From a53876d741b33fac4ad57e95041e88326ed770fb Mon Sep 17 00:00:00 2001 From: Jessica Chowdhury <67977755+JessChowdhury@users.noreply.github.com> Date: Fri, 7 Mar 2025 14:13:48 +0000 Subject: [PATCH] fix(ui): logic for showing copyToLocale button and adds test (#11584) ### What? This [PR](https://github.com/payloadcms/payload/pull/11546) introduced a bug where the `CopyToLocale` button can show up when localization is false. ### Why? `const disableCopyToLocale = localization && collectionConfig?.admin?.disableCopyToLocale` this line was faulty ### How? Fixed the logic and added test to confirm button doesn't show when localization is false. --- packages/ui/src/elements/DocumentControls/index.tsx | 4 ++-- test/admin-root/e2e.spec.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/elements/DocumentControls/index.tsx b/packages/ui/src/elements/DocumentControls/index.tsx index 0986f80ea2..2bc81ec871 100644 --- a/packages/ui/src/elements/DocumentControls/index.tsx +++ b/packages/ui/src/elements/DocumentControls/index.tsx @@ -137,7 +137,7 @@ export const DocumentControls: React.FC<{ (collectionConfig?.versions?.drafts && collectionConfig?.versions?.drafts?.autosave) || (globalConfig?.versions?.drafts && globalConfig?.versions?.drafts?.autosave) - const disableCopyToLocale = localization && collectionConfig?.admin?.disableCopyToLocale + const showCopyToLocale = localization && !collectionConfig?.admin?.disableCopyToLocale return ( @@ -265,7 +265,7 @@ export const DocumentControls: React.FC<{ verticalAlign="bottom" > - {!disableCopyToLocale && } + {showCopyToLocale && } {hasCreatePermission && ( {!disableCreate && ( diff --git a/test/admin-root/e2e.spec.ts b/test/admin-root/e2e.spec.ts index db8aecc595..93bf862682 100644 --- a/test/admin-root/e2e.spec.ts +++ b/test/admin-root/e2e.spec.ts @@ -80,6 +80,15 @@ test.describe('Admin Panel (Root)', () => { await expect(firstRow).toBeVisible() }) + test('collection - should hide Copy To Locale button when localization is false', async () => { + await page.goto(url.create) + const textField = page.locator('#field-text') + await textField.fill('test') + await saveDocAndAssert(page) + await page.locator('.doc-controls__popup >> .popup-button').click() + await expect(page.locator('#copy-locale-data__button')).toBeHidden() + }) + test('global — navigates to edit view', async () => { await page.goto(url.global('menu')) const pageURL = page.url()