fix(ui): should not show publish specific locale button when no localized fields exist (#13459)

### What?
Hides the `Publish in [specific locale]` button on collections and
globals when no localized fields are present.

### Why?
Currently, the `Publish in [specific locale]` shows on every
collection/global as long as `localization` is enabled in the Payload
config, however this is not necessary when the collection/global has no
localized fields.

### How?
Checks that localized fields exist prior to rendering the `Publish in
[specific locale]` button.

Fixes #13447

---------

Co-authored-by: German Jablonski <43938777+GermanJablo@users.noreply.github.com>
This commit is contained in:
Jessica Rynkar
2025-09-02 10:23:53 +01:00
committed by GitHub
parent fdab2712c0
commit ac691b675b
4 changed files with 71 additions and 3 deletions

View File

@@ -29,6 +29,7 @@ import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
import { POLL_TOPASS_TIMEOUT, TEST_TIMEOUT_LONG } from '../playwright.config.js'
import { arrayCollectionSlug } from './collections/Array/index.js'
import { nestedToArrayAndBlockCollectionSlug } from './collections/NestedToArrayAndBlock/index.js'
import { noLocalizedFieldsCollectionSlug } from './collections/NoLocalizedFields/index.js'
import { richTextSlug } from './collections/RichText/index.js'
import {
arrayWithFallbackCollectionSlug,
@@ -61,6 +62,7 @@ let urlCannotCreateDefaultLocale: AdminUrlUtil
let urlPostsWithDrafts: AdminUrlUtil
let urlArray: AdminUrlUtil
let arrayWithFallbackURL: AdminUrlUtil
let noLocalizedFieldsURL: AdminUrlUtil
const title = 'english title'
const spanishTitle = 'spanish title'
@@ -87,6 +89,7 @@ describe('Localization', () => {
urlPostsWithDrafts = new AdminUrlUtil(serverURL, localizedDraftsSlug)
urlArray = new AdminUrlUtil(serverURL, arrayCollectionSlug)
arrayWithFallbackURL = new AdminUrlUtil(serverURL, arrayWithFallbackCollectionSlug)
noLocalizedFieldsURL = new AdminUrlUtil(serverURL, noLocalizedFieldsCollectionSlug)
context = await browser.newContext()
page = await context.newPage()
@@ -671,6 +674,13 @@ describe('Localization', () => {
await expect(page.locator('#field-title')).toBeEmpty()
})
})
test('should not show publish specific locale button when no localized fields exist', async () => {
await page.goto(urlPostsWithDrafts.create)
await expect(page.locator('#publish-locale')).toHaveCount(1)
await page.goto(noLocalizedFieldsURL.create)
await expect(page.locator('#publish-locale')).toHaveCount(0)
})
})
async function createLocalizedArrayItem(page: Page, url: AdminUrlUtil) {