fix: copy to locale with localized fields inside tabs (#13456)
Fixes https://github.com/payloadcms/payload/issues/13374
This commit is contained in:
@@ -4,7 +4,30 @@ export const blocksCollectionSlug = 'blocks-fields'
|
||||
|
||||
export const BlocksCollection: CollectionConfig = {
|
||||
slug: blocksCollectionSlug,
|
||||
versions: { drafts: true },
|
||||
fields: [
|
||||
{
|
||||
type: 'tabs',
|
||||
tabs: [
|
||||
{
|
||||
label: 'Tab',
|
||||
fields: [
|
||||
{
|
||||
name: 'tabContent',
|
||||
label: 'Content',
|
||||
type: 'blocks',
|
||||
localized: true,
|
||||
blocks: [
|
||||
{
|
||||
slug: 'blockInsideTab',
|
||||
fields: [{ type: 'text', name: 'text' }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'content',
|
||||
label: 'Content',
|
||||
|
||||
@@ -2903,7 +2903,7 @@ describe('Localization', () => {
|
||||
})
|
||||
|
||||
const req = await createLocalReq({ user }, payload)
|
||||
|
||||
global.d = true
|
||||
const res = (await copyDataFromLocaleHandler({
|
||||
fromLocale: 'en',
|
||||
req,
|
||||
@@ -2915,6 +2915,36 @@ describe('Localization', () => {
|
||||
expect(res.content?.[0]?.content?.[0]?.text).toBe('some-text')
|
||||
})
|
||||
|
||||
it('should copy block inside tab to locale', async () => {
|
||||
// This was previously an e2e test but it was migrated to int
|
||||
// because at the moment only int tests run in Postgres in CI,
|
||||
// and that's where the bug occurs.
|
||||
const doc = await payload.create({
|
||||
collection: 'blocks-fields',
|
||||
locale: 'en',
|
||||
data: {
|
||||
tabContent: [
|
||||
{
|
||||
blockType: 'blockInsideTab',
|
||||
text: 'some-text',
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
const req = await createLocalReq({ user }, payload)
|
||||
global.d = true
|
||||
const res = (await copyDataFromLocaleHandler({
|
||||
fromLocale: 'en',
|
||||
req,
|
||||
toLocale: 'pt',
|
||||
docID: doc.id,
|
||||
collectionSlug: 'blocks-fields',
|
||||
})) as BlocksField
|
||||
|
||||
expect(res.tabContent?.[0]?.text).toBe('some-text')
|
||||
})
|
||||
|
||||
it('should copy localized nested to arrays', async () => {
|
||||
const doc = await payload.create({
|
||||
collection: 'nested',
|
||||
|
||||
@@ -192,6 +192,14 @@ export interface RichText {
|
||||
*/
|
||||
export interface BlocksField {
|
||||
id: string;
|
||||
tabContent?:
|
||||
| {
|
||||
text?: string | null;
|
||||
id?: string | null;
|
||||
blockName?: string | null;
|
||||
blockType: 'blockInsideTab';
|
||||
}[]
|
||||
| null;
|
||||
content?:
|
||||
| {
|
||||
content?:
|
||||
@@ -217,6 +225,7 @@ export interface BlocksField {
|
||||
| null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
_status?: ('draft' | 'published') | null;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
@@ -877,6 +886,17 @@ export interface RichTextSelect<T extends boolean = true> {
|
||||
* via the `definition` "blocks-fields_select".
|
||||
*/
|
||||
export interface BlocksFieldsSelect<T extends boolean = true> {
|
||||
tabContent?:
|
||||
| T
|
||||
| {
|
||||
blockInsideTab?:
|
||||
| T
|
||||
| {
|
||||
text?: T;
|
||||
id?: T;
|
||||
blockName?: T;
|
||||
};
|
||||
};
|
||||
content?:
|
||||
| T
|
||||
| {
|
||||
@@ -910,6 +930,7 @@ export interface BlocksFieldsSelect<T extends boolean = true> {
|
||||
};
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
_status?: T;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
@@ -1499,6 +1520,6 @@ export interface Auth {
|
||||
|
||||
|
||||
declare module 'payload' {
|
||||
// @ts-ignore
|
||||
// @ts-ignore
|
||||
export interface GeneratedTypes extends Config {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user