fix(ui): ensure publishSpecificLocale works during create operation (#13129)
### What? This PR ensures that when a document is created using the `Publish in __` button, it is saved to the correct locale. ### Why? During document creation, the buttons `Publish` or `Publish in [locale]` have the same effect. As a result, we overlooked the case where a user may specifically click `Publish in [locale]` for the first save. In this scenario, the create operation does not respect the `publishSpecificLocale` value, so the document was always saved in the default locale regardless of the intended one. ### How? Passes the `publishSpecificLocale` value to the create operation, ensuring the document and version is saved to the correct locale. **Fixes:** #13117
This commit is contained in:
@@ -116,7 +116,7 @@ export const VersionPillLabel: React.FC<{
|
|||||||
)}
|
)}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)}
|
)}
|
||||||
{localeLabel && <Pill>{localeLabel}</Pill>}
|
{localeLabel && <Pill size="small">{localeLabel}</Pill>}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export const createHandler: PayloadHandler = async (req) => {
|
|||||||
const autosave = searchParams.get('autosave') === 'true'
|
const autosave = searchParams.get('autosave') === 'true'
|
||||||
const draft = searchParams.get('draft') === 'true'
|
const draft = searchParams.get('draft') === 'true'
|
||||||
const depth = searchParams.get('depth')
|
const depth = searchParams.get('depth')
|
||||||
|
const publishSpecificLocale = req.query.publishSpecificLocale as string | undefined
|
||||||
|
|
||||||
const doc = await createOperation({
|
const doc = await createOperation({
|
||||||
autosave,
|
autosave,
|
||||||
@@ -24,6 +25,7 @@ export const createHandler: PayloadHandler = async (req) => {
|
|||||||
depth: isNumber(depth) ? depth : undefined,
|
depth: isNumber(depth) ? depth : undefined,
|
||||||
draft,
|
draft,
|
||||||
populate: sanitizePopulateParam(req.query.populate),
|
populate: sanitizePopulateParam(req.query.populate),
|
||||||
|
publishSpecificLocale,
|
||||||
req,
|
req,
|
||||||
select: sanitizeSelectParam(req.query.select),
|
select: sanitizeSelectParam(req.query.select),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export type Arguments<TSlug extends CollectionSlug> = {
|
|||||||
overrideAccess?: boolean
|
overrideAccess?: boolean
|
||||||
overwriteExistingFiles?: boolean
|
overwriteExistingFiles?: boolean
|
||||||
populate?: PopulateType
|
populate?: PopulateType
|
||||||
|
publishSpecificLocale?: string
|
||||||
req: PayloadRequest
|
req: PayloadRequest
|
||||||
select?: SelectType
|
select?: SelectType
|
||||||
showHiddenFields?: boolean
|
showHiddenFields?: boolean
|
||||||
@@ -88,6 +89,10 @@ export const createOperation = async <
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args.publishSpecificLocale) {
|
||||||
|
args.req.locale = args.publishSpecificLocale
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
autosave = false,
|
autosave = false,
|
||||||
collection: { config: collectionConfig },
|
collection: { config: collectionConfig },
|
||||||
@@ -99,6 +104,7 @@ export const createOperation = async <
|
|||||||
overrideAccess,
|
overrideAccess,
|
||||||
overwriteExistingFiles = false,
|
overwriteExistingFiles = false,
|
||||||
populate,
|
populate,
|
||||||
|
publishSpecificLocale,
|
||||||
req: {
|
req: {
|
||||||
fallbackLocale,
|
fallbackLocale,
|
||||||
locale,
|
locale,
|
||||||
@@ -286,6 +292,7 @@ export const createOperation = async <
|
|||||||
collection: collectionConfig,
|
collection: collectionConfig,
|
||||||
docWithLocales: result,
|
docWithLocales: result,
|
||||||
payload,
|
payload,
|
||||||
|
publishSpecificLocale,
|
||||||
req,
|
req,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -279,7 +279,12 @@ export async function saveDocHotkeyAndAssert(page: Page): Promise<void> {
|
|||||||
|
|
||||||
export async function saveDocAndAssert(
|
export async function saveDocAndAssert(
|
||||||
page: Page,
|
page: Page,
|
||||||
selector: '#action-publish' | '#action-save' | '#action-save-draft' | string = '#action-save',
|
selector:
|
||||||
|
| '#action-publish'
|
||||||
|
| '#action-save'
|
||||||
|
| '#action-save-draft'
|
||||||
|
| '#publish-locale'
|
||||||
|
| string = '#action-save',
|
||||||
expectation: 'error' | 'success' = 'success',
|
expectation: 'error' | 'success' = 'success',
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await wait(500) // TODO: Fix this
|
await wait(500) // TODO: Fix this
|
||||||
|
|||||||
@@ -618,6 +618,21 @@ describe('Localization', () => {
|
|||||||
await expect(searchInput).toBeVisible()
|
await expect(searchInput).toBeVisible()
|
||||||
await expect(searchInput).toHaveAttribute('placeholder', 'Search by Full title')
|
await expect(searchInput).toHaveAttribute('placeholder', 'Search by Full title')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('publish specific locale', () => {
|
||||||
|
test('should create post in correct locale with publishSpecificLocale', async () => {
|
||||||
|
await page.goto(urlPostsWithDrafts.create)
|
||||||
|
await changeLocale(page, 'es')
|
||||||
|
await fillValues({ title: 'Created In Spanish' })
|
||||||
|
const chevronButton = page.locator('.form-submit .popup__trigger-wrap > .popup-button')
|
||||||
|
await chevronButton.click()
|
||||||
|
await saveDocAndAssert(page, '#publish-locale')
|
||||||
|
|
||||||
|
await expect(page.locator('#field-title')).toHaveValue('Created In Spanish')
|
||||||
|
await changeLocale(page, defaultLocale)
|
||||||
|
await expect(page.locator('#field-title')).toBeEmpty()
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
async function fillValues(data: Partial<LocalizedPost>) {
|
async function fillValues(data: Partial<LocalizedPost>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user