Skip to content

Commit

Permalink
fix: uses docPermissions to show/hide x button on media collection do…
Browse files Browse the repository at this point in the history
…c fileDetails - #2428
  • Loading branch information
JarrodMFlesch committed Apr 10, 2023
1 parent 13cc669 commit 7f2c3d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 0 additions & 1 deletion docs/admin/hooks.mdx
Expand Up @@ -166,7 +166,6 @@ The `useDocumentInfo` hook provides lots of information about the document curre
|---------------------------|--------------------------------------------------------------------------------------------------------------------| |
| **`collection`** | If the doc is a collection, its collection config will be returned |
| **`global`** | If the doc is a global, its global config will be returned |
| **`type`** | The type of document being edited (collection or global) |
| **`id`** | If the doc is a collection, its ID will be returned |
| **`preferencesKey`** | The `preferences` key to use when interacting with document-level user preferences |
| **`versions`** | Versions of the current doc |
Expand Down
8 changes: 6 additions & 2 deletions src/admin/components/views/collections/Edit/Upload/index.tsx
Expand Up @@ -2,6 +2,7 @@ import React, {
useState, useRef, useEffect, useCallback,
} from 'react';
import { useTranslation } from 'react-i18next';
import { useDocumentInfo } from '../../../../utilities/DocumentInfo';
import useField from '../../../../forms/useField';
import Button from '../../../../elements/Button';
import FileDetails from '../../../../elements/FileDetails';
Expand Down Expand Up @@ -40,6 +41,7 @@ const Upload: React.FC<Props> = (props) => {
const [replacingFile, setReplacingFile] = useState(false);
const { t } = useTranslation('upload');
const [doc, setDoc] = useState(reduceFieldsToValues(internalState || {}, true));
const { docPermissions } = useDocumentInfo();

const {
value,
Expand Down Expand Up @@ -129,6 +131,8 @@ const Upload: React.FC<Props> = (props) => {
'field-type',
].filter(Boolean).join(' ');

const canRemoveUpload = docPermissions?.update?.permission && 'delete' in docPermissions && docPermissions?.delete?.permission;

return (
<div className={classes}>
<Error
Expand All @@ -139,10 +143,10 @@ const Upload: React.FC<Props> = (props) => {
<FileDetails
doc={doc}
collection={collection}
handleRemove={() => {
handleRemove={canRemoveUpload ? () => {
setReplacingFile(true);
setValue(null);
}}
} : undefined}
/>
)}
{(!doc.filename || replacingFile) && (
Expand Down

0 comments on commit 7f2c3d1

Please sign in to comment.