File tree Expand file tree Collapse file tree 4 files changed +98
-13
lines changed
packages/payload/src/utilities Expand file tree Collapse file tree 4 files changed +98
-13
lines changed Original file line number Diff line number Diff line change @@ -416,27 +416,38 @@ export const traverseFields = ({
416
416
} )
417
417
) {
418
418
if ( Array . isArray ( currentRef ) ) {
419
- return
420
- }
421
-
422
- for ( const key in currentRef as Record < string , unknown > ) {
423
- const localeData = currentRef [ key as keyof typeof currentRef ]
424
- if ( ! Array . isArray ( localeData ) ) {
425
- continue
426
- }
427
-
428
419
traverseArrayOrBlocksField ( {
429
420
callback,
430
421
callbackStack,
431
422
config,
432
- data : localeData ,
423
+ data : currentRef ,
433
424
field,
434
425
fillEmpty,
435
426
leavesFirst,
436
427
parentIsLocalized : true ,
437
428
parentPath,
438
429
parentRef : currentParentRef ,
439
430
} )
431
+ } else {
432
+ for ( const key in currentRef as Record < string , unknown > ) {
433
+ const localeData = currentRef [ key as keyof typeof currentRef ]
434
+ if ( ! Array . isArray ( localeData ) ) {
435
+ continue
436
+ }
437
+
438
+ traverseArrayOrBlocksField ( {
439
+ callback,
440
+ callbackStack,
441
+ config,
442
+ data : localeData ,
443
+ field,
444
+ fillEmpty,
445
+ leavesFirst,
446
+ parentIsLocalized : true ,
447
+ parentPath,
448
+ parentRef : currentParentRef ,
449
+ } )
450
+ }
440
451
}
441
452
} else if ( Array . isArray ( currentRef ) ) {
442
453
traverseArrayOrBlocksField ( {
Original file line number Diff line number Diff line change @@ -4,7 +4,30 @@ export const blocksCollectionSlug = 'blocks-fields'
4
4
5
5
export const BlocksCollection : CollectionConfig = {
6
6
slug : blocksCollectionSlug ,
7
+ versions : { drafts : true } ,
7
8
fields : [
9
+ {
10
+ type : 'tabs' ,
11
+ tabs : [
12
+ {
13
+ label : 'Tab' ,
14
+ fields : [
15
+ {
16
+ name : 'tabContent' ,
17
+ label : 'Content' ,
18
+ type : 'blocks' ,
19
+ localized : true ,
20
+ blocks : [
21
+ {
22
+ slug : 'blockInsideTab' ,
23
+ fields : [ { type : 'text' , name : 'text' } ] ,
24
+ } ,
25
+ ] ,
26
+ } ,
27
+ ] ,
28
+ } ,
29
+ ] ,
30
+ } ,
8
31
{
9
32
name : 'content' ,
10
33
label : 'Content' ,
Original file line number Diff line number Diff line change @@ -2903,7 +2903,7 @@ describe('Localization', () => {
2903
2903
} )
2904
2904
2905
2905
const req = await createLocalReq ( { user } , payload )
2906
-
2906
+ global . d = true
2907
2907
const res = ( await copyDataFromLocaleHandler ( {
2908
2908
fromLocale : 'en' ,
2909
2909
req,
@@ -2915,6 +2915,36 @@ describe('Localization', () => {
2915
2915
expect ( res . content ?. [ 0 ] ?. content ?. [ 0 ] ?. text ) . toBe ( 'some-text' )
2916
2916
} )
2917
2917
2918
+ it ( 'should copy block inside tab to locale' , async ( ) => {
2919
+ // This was previously an e2e test but it was migrated to int
2920
+ // because at the moment only int tests run in Postgres in CI,
2921
+ // and that's where the bug occurs.
2922
+ const doc = await payload . create ( {
2923
+ collection : 'blocks-fields' ,
2924
+ locale : 'en' ,
2925
+ data : {
2926
+ tabContent : [
2927
+ {
2928
+ blockType : 'blockInsideTab' ,
2929
+ text : 'some-text' ,
2930
+ } ,
2931
+ ] ,
2932
+ } ,
2933
+ } )
2934
+
2935
+ const req = await createLocalReq ( { user } , payload )
2936
+ global . d = true
2937
+ const res = ( await copyDataFromLocaleHandler ( {
2938
+ fromLocale : 'en' ,
2939
+ req,
2940
+ toLocale : 'pt' ,
2941
+ docID : doc . id ,
2942
+ collectionSlug : 'blocks-fields' ,
2943
+ } ) ) as BlocksField
2944
+
2945
+ expect ( res . tabContent ?. [ 0 ] ?. text ) . toBe ( 'some-text' )
2946
+ } )
2947
+
2918
2948
it ( 'should copy localized nested to arrays' , async ( ) => {
2919
2949
const doc = await payload . create ( {
2920
2950
collection : 'nested' ,
Original file line number Diff line number Diff line change @@ -192,6 +192,14 @@ export interface RichText {
192
192
*/
193
193
export interface BlocksField {
194
194
id : string ;
195
+ tabContent ?:
196
+ | {
197
+ text ?: string | null ;
198
+ id ?: string | null ;
199
+ blockName ?: string | null ;
200
+ blockType : 'blockInsideTab' ;
201
+ } [ ]
202
+ | null ;
195
203
content ?:
196
204
| {
197
205
content ?:
@@ -217,6 +225,7 @@ export interface BlocksField {
217
225
| null ;
218
226
updatedAt : string ;
219
227
createdAt : string ;
228
+ _status ?: ( 'draft' | 'published' ) | null ;
220
229
}
221
230
/**
222
231
* This interface was referenced by `Config`'s JSON-Schema
@@ -877,6 +886,17 @@ export interface RichTextSelect<T extends boolean = true> {
877
886
* via the `definition` "blocks-fields_select".
878
887
*/
879
888
export interface BlocksFieldsSelect < T extends boolean = true > {
889
+ tabContent ?:
890
+ | T
891
+ | {
892
+ blockInsideTab ?:
893
+ | T
894
+ | {
895
+ text ?: T ;
896
+ id ?: T ;
897
+ blockName ?: T ;
898
+ } ;
899
+ } ;
880
900
content ?:
881
901
| T
882
902
| {
@@ -910,6 +930,7 @@ export interface BlocksFieldsSelect<T extends boolean = true> {
910
930
} ;
911
931
updatedAt ?: T ;
912
932
createdAt ?: T ;
933
+ _status ?: T ;
913
934
}
914
935
/**
915
936
* This interface was referenced by `Config`'s JSON-Schema
@@ -1499,6 +1520,6 @@ export interface Auth {
1499
1520
1500
1521
1501
1522
declare module 'payload' {
1502
- // @ts -ignore
1523
+ // @ts -ignore
1503
1524
export interface GeneratedTypes extends Config { }
1504
- }
1525
+ }
You can’t perform that action at this time.
0 commit comments