fix: localised relationship fields (#7178)

Fixes the issue where locale is not passed into the relationship field
resulting in documents without titles in some situations


![image](https://github.com/user-attachments/assets/67f0a70c-29a0-4f54-a395-f4aa9b132d6f)
This commit is contained in:
Paul
2024-07-16 15:22:37 -04:00
committed by GitHub
parent 0371aea711
commit 2f0aa83a93
2 changed files with 31 additions and 9 deletions

View File

@@ -47,15 +47,6 @@ export const createPayloadRequest = async ({
let locale
let fallbackLocale
if (config.localization) {
const locales = sanitizeLocales({
fallbackLocale: searchParams.get('fallback-locale'),
locale: searchParams.get('locale'),
localization: payload.config.localization,
})
locale = locales.locale
fallbackLocale = locales.fallbackLocale
}
const overrideHttpMethod = request.headers.get('X-HTTP-Method-Override')
const queryToParse = overrideHttpMethod === 'GET' ? await request.text() : urlProperties.search
@@ -68,6 +59,20 @@ export const createPayloadRequest = async ({
})
: {}
if (config.localization) {
const locales = sanitizeLocales({
fallbackLocale: searchParams.get('fallback-locale'),
locale: searchParams.get('locale'),
localization: payload.config.localization,
})
locale = locales.locale
fallbackLocale = locales.fallbackLocale
// Override if query params are present, in order to respect HTTP method override
if (query.locale) locale = query.locale
if (query?.['fallback-locale']) fallbackLocale = query['fallback-locale']
}
const customRequest: CustomPayloadRequestProperties = {
context: {},
fallbackLocale,

View File

@@ -234,6 +234,23 @@ describe('Localization', () => {
await expect(page.locator('.row-1 .cell-title')).toContainText(spanishTitle)
})
})
describe('localized relationships', () => {
test('ensure relationship field fetches are localised as well', async () => {
await page.goto(url.list)
await changeLocale(page, spanishLocale)
const localisedPost = page.locator('.cell-title a').first()
const localisedPostUrl = await localisedPost.getAttribute('href')
await page.goto(serverURL + localisedPostUrl)
await page.waitForURL(serverURL + localisedPostUrl)
const selectField = page.locator('#field-children .rs__control')
await selectField.click()
await expect(page.locator('#field-children .rs__menu')).toContainText('spanish-relation2')
})
})
})
async function fillValues(data: Partial<LocalizedPost>) {