fix: conditionally hide dot menu in DocumentControls (#4075)

This commit is contained in:
Patrik
2023-11-09 12:01:58 -05:00
committed by GitHub
parent 7059a71243
commit cef4cbb0ee
2 changed files with 14 additions and 3 deletions

View File

@@ -56,7 +56,12 @@ export const DocumentControls: React.FC<{
const { i18n, t } = useTranslation('general')
const showDotMenu = Boolean(collection && id && !disableActions)
const hasCreatePermission = 'create' in permissions && permissions.create?.permission
const hasDeletePermission = 'delete' in permissions && permissions.delete?.permission
const showDotMenu = Boolean(
collection && id && !disableActions && (hasCreatePermission || hasDeletePermission),
)
return (
<Gutter className={baseClass}>
@@ -203,7 +208,7 @@ export const DocumentControls: React.FC<{
verticalAlign="bottom"
>
<PopupList.ButtonGroup>
{'create' in permissions && permissions?.create?.permission && (
{hasCreatePermission && (
<React.Fragment>
<PopupList.Button
id="action-create"
@@ -217,7 +222,7 @@ export const DocumentControls: React.FC<{
)}
</React.Fragment>
)}
{'delete' in permissions && permissions?.delete?.permission && id && (
{hasDeletePermission && (
<DeleteDocument buttonId="action-delete" collection={collection} id={id} />
)}
</PopupList.ButtonGroup>

View File

@@ -179,6 +179,12 @@ describe('access control', () => {
await page.goto(readOnlyUrl.edit(existingDoc.id))
await expect(page.locator('#field-name')).toBeDisabled()
})
test('should not render dot menu popup when `create` and `delete` access control is set to false', async () => {
await page.goto(readOnlyUrl.edit(existingDoc.id))
await wait(1000)
await expect(page.locator('.collection-edit .doc-controls .doc-controls__popup')).toBeHidden()
})
})
describe('readVersions', () => {