fix(live-preview): populates localized relationships in client-side live preview (#9617)
Fixes #5026. When using client-side Live Preview, switching locale would not populate relationships in that locale, and would use the default locale instead. This was because locale was simply not being handled. Now, we pass the locale through the event, and use it to make localized queries when populating those relationships.
This commit is contained in:
@@ -51,6 +51,7 @@ describe('Collections - Live Preview', () => {
|
||||
slug: 'post-1',
|
||||
title: 'Test Post',
|
||||
tenant: tenant.id,
|
||||
localizedTitle: 'Test Post',
|
||||
},
|
||||
})
|
||||
|
||||
@@ -60,6 +61,7 @@ describe('Collections - Live Preview', () => {
|
||||
slug: 'post-2',
|
||||
title: 'Test Post 2',
|
||||
tenant: tenant.id,
|
||||
localizedTitle: 'Test Post 2',
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1135,6 +1137,54 @@ describe('Collections - Live Preview', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('— relationships - populates localized relationships', async () => {
|
||||
const post = await payload.create({
|
||||
collection: postsSlug,
|
||||
data: {
|
||||
title: 'Test Post',
|
||||
slug: 'test-post',
|
||||
hero: {
|
||||
type: 'highImpact',
|
||||
media: media.id,
|
||||
},
|
||||
localizedTitle: 'Test Post Spanish',
|
||||
},
|
||||
locale: 'es',
|
||||
})
|
||||
|
||||
await payload.update({
|
||||
id: post.id,
|
||||
locale: 'en',
|
||||
collection: postsSlug,
|
||||
data: {
|
||||
localizedTitle: 'Test Post English',
|
||||
},
|
||||
})
|
||||
|
||||
const initialData: Partial<Page> = {
|
||||
title: 'Test Page',
|
||||
relationToLocalized: post.id,
|
||||
}
|
||||
|
||||
// Populate the relationships
|
||||
const merge1 = await mergeData({
|
||||
depth: 1,
|
||||
fieldSchema: schemaJSON,
|
||||
incomingData: {
|
||||
...initialData,
|
||||
relationToLocalized: post.id,
|
||||
},
|
||||
initialData,
|
||||
serverURL,
|
||||
returnNumberOfRequests: true,
|
||||
collectionPopulationRequestHandler,
|
||||
locale: 'es',
|
||||
})
|
||||
|
||||
expect(merge1._numberOfRequests).toEqual(1)
|
||||
expect(merge1.relationToLocalized).toHaveProperty('localizedTitle', 'Test Post Spanish')
|
||||
})
|
||||
|
||||
it('— rich text - merges text changes', async () => {
|
||||
// Add a relationship
|
||||
const merge1 = await traverseRichText({
|
||||
|
||||
Reference in New Issue
Block a user