From 064dbd81db919eabd9af43b6b1ca1fe54fe8c354 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Fri, 27 Dec 2024 18:17:18 +0200 Subject: [PATCH 1/6] test: add integration testing for copying to locale --- test/localization/int.spec.ts | 91 ++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/test/localization/int.spec.ts b/test/localization/int.spec.ts index e260cae9827..e97d3b59769 100644 --- a/test/localization/int.spec.ts +++ b/test/localization/int.spec.ts @@ -1,10 +1,21 @@ +import type { Payload, User, Where } from 'payload' + import path from 'path' -import { type Payload, type Where } from 'payload' +import { createLocalReq } from 'payload' import { fileURLToPath } from 'url' import type { NextRESTClient } from '../helpers/NextRESTClient.js' -import type { LocalizedPost, LocalizedSort, WithLocalizedRelationship } from './payload-types.js' +import type { + LocalizedPost, + LocalizedSort, + Nested, + WithLocalizedRelationship, +} from './payload-types.js' + +import { devUser } from '../credentials.js' +// eslint-disable-next-line payload/no-relative-monorepo-imports +import { copyDataFromLocaleHandler } from '../../packages/ui/src/utilities/copyDataFromLocale.js' import { idToString } from '../helpers/idToString.js' import { initPayloadInt } from '../helpers/initPayloadInt.js' import { arrayCollectionSlug } from './collections/Array/index.js' @@ -2451,6 +2462,82 @@ describe('Localization', () => { ).rejects.toBeTruthy() }) }) + + describe('Copying To Locale', () => { + let user: User + + beforeAll(async () => { + user = ( + await payload.find({ + collection: 'users', + where: { + email: { + equals: devUser.email, + }, + }, + }) + ).docs[0] as unknown as User + + user['collection'] = 'users' + }) + + it('should copy to locale', async () => { + const doc = await payload.create({ + collection: 'localized-posts', + data: { + title: 'Hello', + group: { + children: 'Children', + }, + unique: 'unique-field', + localizedCheckbox: true, + }, + }) + + const req = await createLocalReq({ user }, payload) + + const res = (await copyDataFromLocaleHandler({ + fromLocale: 'en', + req, + toLocale: 'es', + docID: doc.id, + collectionSlug: 'localized-posts', + })) as LocalizedPost + + expect(res.title).toBe('Hello') + expect(res.group.children).toBe('Children') + expect(res.unique).toBe('unique-field') + expect(res.localizedCheckbox).toBe(true) + }) + + it('should copy localized nested to arrays', async () => { + const doc = await payload.create({ + collection: 'nested', + locale: 'en', + data: { + topLevelArray: [ + { + localizedText: 'some-localized-text', + notLocalizedText: 'some-not-localized-text', + }, + ], + }, + }) + + const req = await createLocalReq({ user }, payload) + + const res = (await copyDataFromLocaleHandler({ + fromLocale: 'en', + req, + toLocale: 'es', + docID: doc.id, + collectionSlug: 'nested', + })) as Nested + + expect(res.topLevelArray[0].localizedText).toBe('some-localized-text') + expect(res.topLevelArray[0].notLocalizedText).toBe('some-not-localized-text') + }) + }) }) describe('Localization with fallback false', () => { From 0f99bc427bdffb012ac8ad60f633a9a552a65e14 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Wed, 1 Jan 2025 04:14:15 +0200 Subject: [PATCH 2/6] failing test --- test/admin/payload-types.ts | 109 ++++++++++-------- .../NestedToArrayAndBlock/index.ts | 11 ++ test/localization/int.spec.ts | 26 +++++ test/localization/payload-types.ts | 12 ++ 4 files changed, 109 insertions(+), 49 deletions(-) diff --git a/test/admin/payload-types.ts b/test/admin/payload-types.ts index 2ccadf1a388..4b9b5e1a24b 100644 --- a/test/admin/payload-types.ts +++ b/test/admin/payload-types.ts @@ -54,7 +54,7 @@ export interface Config { 'payload-migrations': PayloadMigrationsSelect | PayloadMigrationsSelect; }; db: { - defaultIDType: string; + defaultIDType: number; }; globals: { 'hidden-global': HiddenGlobal; @@ -110,7 +110,7 @@ export interface UserAuthOperations { * via the `definition` "uploads". */ export interface Upload { - id: string; + id: number; title?: string | null; updatedAt: string; createdAt: string; @@ -135,11 +135,13 @@ export interface Upload { }; } /** + * This is a custom collection description. + * * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "posts". */ export interface Post { - id: string; + id: number; title?: string | null; description?: string | null; number?: number | null; @@ -173,12 +175,15 @@ export interface Post { }[] | null; defaultValueField?: string | null; - relationship?: (string | null) | Post; + relationship?: (number | null) | Post; customCell?: string | null; hiddenField?: string | null; adminHiddenField?: string | null; disableListColumnText?: string | null; disableListFilterText?: string | null; + /** + * This is a very long description that takes many characters to complete and hopefully will wrap instead of push the sidebar open, lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, voluptatum voluptates. Quisquam, voluptatum voluptates. + */ sidebarField?: string | null; updatedAt: string; createdAt: string; @@ -189,7 +194,7 @@ export interface Post { * via the `definition` "users". */ export interface User { - id: string; + id: number; textField?: string | null; sidebarField?: string | null; updatedAt: string; @@ -208,7 +213,7 @@ export interface User { * via the `definition` "hidden-collection". */ export interface HiddenCollection { - id: string; + id: number; title?: string | null; updatedAt: string; createdAt: string; @@ -218,7 +223,7 @@ export interface HiddenCollection { * via the `definition` "not-in-view-collection". */ export interface NotInViewCollection { - id: string; + id: number; title?: string | null; updatedAt: string; createdAt: string; @@ -228,7 +233,7 @@ export interface NotInViewCollection { * via the `definition` "collection-no-api-view". */ export interface CollectionNoApiView { - id: string; + id: number; updatedAt: string; createdAt: string; } @@ -237,7 +242,7 @@ export interface CollectionNoApiView { * via the `definition` "custom-views-one". */ export interface CustomViewsOne { - id: string; + id: number; title?: string | null; updatedAt: string; createdAt: string; @@ -247,7 +252,7 @@ export interface CustomViewsOne { * via the `definition` "custom-views-two". */ export interface CustomViewsTwo { - id: string; + id: number; title?: string | null; updatedAt: string; createdAt: string; @@ -257,14 +262,20 @@ export interface CustomViewsTwo { * via the `definition` "custom-fields". */ export interface CustomField { - id: string; + id: number; customTextServerField?: string | null; customTextClientField?: string | null; + /** + * Static field description. + */ descriptionAsString?: string | null; + /** + * Function description + */ descriptionAsFunction?: string | null; descriptionAsComponent?: string | null; customSelectField?: string | null; - relationshipFieldWithBeforeAfterInputs?: (string | null) | Post; + relationshipFieldWithBeforeAfterInputs?: (number | null) | Post; arrayFieldWithBeforeAfterInputs?: | { someTextField?: string | null; @@ -293,7 +304,7 @@ export interface CustomField { * via the `definition` "group-one-collection-ones". */ export interface GroupOneCollectionOne { - id: string; + id: number; title?: string | null; updatedAt: string; createdAt: string; @@ -303,7 +314,7 @@ export interface GroupOneCollectionOne { * via the `definition` "group-one-collection-twos". */ export interface GroupOneCollectionTwo { - id: string; + id: number; title?: string | null; updatedAt: string; createdAt: string; @@ -313,7 +324,7 @@ export interface GroupOneCollectionTwo { * via the `definition` "group-two-collection-ones". */ export interface GroupTwoCollectionOne { - id: string; + id: number; title?: string | null; updatedAt: string; createdAt: string; @@ -323,7 +334,7 @@ export interface GroupTwoCollectionOne { * via the `definition` "group-two-collection-twos". */ export interface GroupTwoCollectionTwo { - id: string; + id: number; title?: string | null; updatedAt: string; createdAt: string; @@ -333,7 +344,7 @@ export interface GroupTwoCollectionTwo { * via the `definition` "geo". */ export interface Geo { - id: string; + id: number; /** * @minItems 2 * @maxItems 2 @@ -347,7 +358,7 @@ export interface Geo { * via the `definition` "disable-duplicate". */ export interface DisableDuplicate { - id: string; + id: number; title?: string | null; updatedAt: string; createdAt: string; @@ -357,7 +368,7 @@ export interface DisableDuplicate { * via the `definition` "base-list-filters". */ export interface BaseListFilter { - id: string; + id: number; title?: string | null; updatedAt: string; createdAt: string; @@ -367,76 +378,76 @@ export interface BaseListFilter { * via the `definition` "payload-locked-documents". */ export interface PayloadLockedDocument { - id: string; + id: number; document?: | ({ relationTo: 'uploads'; - value: string | Upload; + value: number | Upload; } | null) | ({ relationTo: 'posts'; - value: string | Post; + value: number | Post; } | null) | ({ relationTo: 'users'; - value: string | User; + value: number | User; } | null) | ({ relationTo: 'hidden-collection'; - value: string | HiddenCollection; + value: number | HiddenCollection; } | null) | ({ relationTo: 'not-in-view-collection'; - value: string | NotInViewCollection; + value: number | NotInViewCollection; } | null) | ({ relationTo: 'collection-no-api-view'; - value: string | CollectionNoApiView; + value: number | CollectionNoApiView; } | null) | ({ relationTo: 'custom-views-one'; - value: string | CustomViewsOne; + value: number | CustomViewsOne; } | null) | ({ relationTo: 'custom-views-two'; - value: string | CustomViewsTwo; + value: number | CustomViewsTwo; } | null) | ({ relationTo: 'custom-fields'; - value: string | CustomField; + value: number | CustomField; } | null) | ({ relationTo: 'group-one-collection-ones'; - value: string | GroupOneCollectionOne; + value: number | GroupOneCollectionOne; } | null) | ({ relationTo: 'group-one-collection-twos'; - value: string | GroupOneCollectionTwo; + value: number | GroupOneCollectionTwo; } | null) | ({ relationTo: 'group-two-collection-ones'; - value: string | GroupTwoCollectionOne; + value: number | GroupTwoCollectionOne; } | null) | ({ relationTo: 'group-two-collection-twos'; - value: string | GroupTwoCollectionTwo; + value: number | GroupTwoCollectionTwo; } | null) | ({ relationTo: 'geo'; - value: string | Geo; + value: number | Geo; } | null) | ({ relationTo: 'disable-duplicate'; - value: string | DisableDuplicate; + value: number | DisableDuplicate; } | null) | ({ relationTo: 'base-list-filters'; - value: string | BaseListFilter; + value: number | BaseListFilter; } | null); globalSlug?: string | null; user: { relationTo: 'users'; - value: string | User; + value: number | User; }; updatedAt: string; createdAt: string; @@ -446,10 +457,10 @@ export interface PayloadLockedDocument { * via the `definition` "payload-preferences". */ export interface PayloadPreference { - id: string; + id: number; user: { relationTo: 'users'; - value: string | User; + value: number | User; }; key?: string | null; value?: @@ -469,7 +480,7 @@ export interface PayloadPreference { * via the `definition` "payload-migrations". */ export interface PayloadMigration { - id: string; + id: number; name?: string | null; batch?: number | null; updatedAt: string; @@ -758,7 +769,7 @@ export interface PayloadMigrationsSelect { * via the `definition` "hidden-global". */ export interface HiddenGlobal { - id: string; + id: number; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -768,7 +779,7 @@ export interface HiddenGlobal { * via the `definition` "not-in-view-global". */ export interface NotInViewGlobal { - id: string; + id: number; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -778,7 +789,7 @@ export interface NotInViewGlobal { * via the `definition` "global-no-api-view". */ export interface GlobalNoApiView { - id: string; + id: number; updatedAt?: string | null; createdAt?: string | null; } @@ -787,7 +798,7 @@ export interface GlobalNoApiView { * via the `definition` "global". */ export interface Global { - id: string; + id: number; title?: string | null; sidebarField?: string | null; _status?: ('draft' | 'published') | null; @@ -799,7 +810,7 @@ export interface Global { * via the `definition` "custom-global-views-one". */ export interface CustomGlobalViewsOne { - id: string; + id: number; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -809,7 +820,7 @@ export interface CustomGlobalViewsOne { * via the `definition` "custom-global-views-two". */ export interface CustomGlobalViewsTwo { - id: string; + id: number; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -819,7 +830,7 @@ export interface CustomGlobalViewsTwo { * via the `definition` "group-globals-one". */ export interface GroupGlobalsOne { - id: string; + id: number; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -829,7 +840,7 @@ export interface GroupGlobalsOne { * via the `definition` "group-globals-two". */ export interface GroupGlobalsTwo { - id: string; + id: number; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -839,7 +850,7 @@ export interface GroupGlobalsTwo { * via the `definition` "settings". */ export interface Setting { - id: string; + id: number; canAccessProtected?: boolean | null; updatedAt?: string | null; createdAt?: string | null; diff --git a/test/localization/collections/NestedToArrayAndBlock/index.ts b/test/localization/collections/NestedToArrayAndBlock/index.ts index 06171c6befd..080dddfc8cf 100644 --- a/test/localization/collections/NestedToArrayAndBlock/index.ts +++ b/test/localization/collections/NestedToArrayAndBlock/index.ts @@ -47,5 +47,16 @@ export const NestedToArrayAndBlock: CollectionConfig = { }, ], }, + { + name: 'topLevelArrayLocalized', + type: 'array', + localized: true, + fields: [ + { + name: 'text', + type: 'text', + }, + ], + }, ], } diff --git a/test/localization/int.spec.ts b/test/localization/int.spec.ts index e97d3b59769..1912c7be998 100644 --- a/test/localization/int.spec.ts +++ b/test/localization/int.spec.ts @@ -2537,6 +2537,32 @@ describe('Localization', () => { expect(res.topLevelArray[0].localizedText).toBe('some-localized-text') expect(res.topLevelArray[0].notLocalizedText).toBe('some-not-localized-text') }) + + it('should copy localized arrays', async () => { + const doc = await payload.create({ + collection: 'nested', + locale: 'en', + data: { + topLevelArrayLocalized: [ + { + text: 'some-text', + }, + ], + }, + }) + + const req = await createLocalReq({ user }, payload) + + const res = (await copyDataFromLocaleHandler({ + fromLocale: 'en', + req, + toLocale: 'es', + docID: doc.id, + collectionSlug: 'nested', + })) as Nested + + expect(res.topLevelArrayLocalized[0].text).toBe('some-text') + }) }) }) diff --git a/test/localization/payload-types.ts b/test/localization/payload-types.ts index c2e41412cd3..091f2240421 100644 --- a/test/localization/payload-types.ts +++ b/test/localization/payload-types.ts @@ -471,6 +471,12 @@ export interface Nested { id?: string | null; }[] | null; + topLevelArrayLocalized?: + | { + text?: string | null; + id?: string | null; + }[] + | null; updatedAt: string; createdAt: string; } @@ -1051,6 +1057,12 @@ export interface NestedSelect { notLocalizedText?: T; id?: T; }; + topLevelArrayLocalized?: + | T + | { + text?: T; + id?: T; + }; updatedAt?: T; createdAt?: T; } From 5e62691bd18bf76b0a4a2eb5b0d25dfde637ded1 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Wed, 1 Jan 2025 04:18:10 +0200 Subject: [PATCH 3/6] fixed --- packages/ui/src/utilities/copyDataFromLocale.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/utilities/copyDataFromLocale.ts b/packages/ui/src/utilities/copyDataFromLocale.ts index 9ca06288992..4ac8a65ed16 100644 --- a/packages/ui/src/utilities/copyDataFromLocale.ts +++ b/packages/ui/src/utilities/copyDataFromLocale.ts @@ -1,3 +1,4 @@ +import ObjectIdImport from 'bson-objectid' import { type CollectionSlug, type Data, @@ -7,6 +8,9 @@ import { } from 'payload' import { fieldAffectsData, tabHasName } from 'payload/shared' +const ObjectId = (ObjectIdImport.default || + ObjectIdImport) as unknown as typeof ObjectIdImport.default + export type CopyDataFromLocaleArgs = { collectionSlug?: CollectionSlug docID?: number | string @@ -34,9 +38,13 @@ function iterateFields(fields: Field[], fromLocaleData: Data, toLocaleData: Data } // if the field has a value but is not localized, loop over the data from target - if (!field.localized && field.name in toLocaleData) { + if (field.name in toLocaleData) { toLocaleData[field.name].map((item: Data, index: number) => { if (fromLocaleData[field.name]?.[index]) { + if (field.localized) { + toLocaleData[field.name][index].id = new ObjectId().toHexString() + } + iterateFields(field.fields, fromLocaleData[field.name][index], item) } }) @@ -56,17 +64,22 @@ function iterateFields(fields: Field[], fromLocaleData: Data, toLocaleData: Data } // if the field has a value but is not localized, loop over the data from target - if (!field.localized && field.name in toLocaleData) { + if (field.name in toLocaleData) { toLocaleData[field.name].map((blockData: Data, index: number) => { const blockFields = field.blocks.find( ({ slug }) => slug === blockData.blockType, )?.fields + if (field.localized) { + toLocaleData[field.name][index].id = new ObjectId().toHexString() + } + if (blockFields?.length) { iterateFields(blockFields, fromLocaleData[field.name][index], blockData) } }) } + break case 'checkbox': From 454307d1cbaefbe12db1318540d53043f3a0db13 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Wed, 1 Jan 2025 04:19:41 +0200 Subject: [PATCH 4/6] reset test/admin --- test/admin/payload-types.ts | 109 ++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 60 deletions(-) diff --git a/test/admin/payload-types.ts b/test/admin/payload-types.ts index 4b9b5e1a24b..2ccadf1a388 100644 --- a/test/admin/payload-types.ts +++ b/test/admin/payload-types.ts @@ -54,7 +54,7 @@ export interface Config { 'payload-migrations': PayloadMigrationsSelect | PayloadMigrationsSelect; }; db: { - defaultIDType: number; + defaultIDType: string; }; globals: { 'hidden-global': HiddenGlobal; @@ -110,7 +110,7 @@ export interface UserAuthOperations { * via the `definition` "uploads". */ export interface Upload { - id: number; + id: string; title?: string | null; updatedAt: string; createdAt: string; @@ -135,13 +135,11 @@ export interface Upload { }; } /** - * This is a custom collection description. - * * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "posts". */ export interface Post { - id: number; + id: string; title?: string | null; description?: string | null; number?: number | null; @@ -175,15 +173,12 @@ export interface Post { }[] | null; defaultValueField?: string | null; - relationship?: (number | null) | Post; + relationship?: (string | null) | Post; customCell?: string | null; hiddenField?: string | null; adminHiddenField?: string | null; disableListColumnText?: string | null; disableListFilterText?: string | null; - /** - * This is a very long description that takes many characters to complete and hopefully will wrap instead of push the sidebar open, lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, voluptatum voluptates. Quisquam, voluptatum voluptates. - */ sidebarField?: string | null; updatedAt: string; createdAt: string; @@ -194,7 +189,7 @@ export interface Post { * via the `definition` "users". */ export interface User { - id: number; + id: string; textField?: string | null; sidebarField?: string | null; updatedAt: string; @@ -213,7 +208,7 @@ export interface User { * via the `definition` "hidden-collection". */ export interface HiddenCollection { - id: number; + id: string; title?: string | null; updatedAt: string; createdAt: string; @@ -223,7 +218,7 @@ export interface HiddenCollection { * via the `definition` "not-in-view-collection". */ export interface NotInViewCollection { - id: number; + id: string; title?: string | null; updatedAt: string; createdAt: string; @@ -233,7 +228,7 @@ export interface NotInViewCollection { * via the `definition` "collection-no-api-view". */ export interface CollectionNoApiView { - id: number; + id: string; updatedAt: string; createdAt: string; } @@ -242,7 +237,7 @@ export interface CollectionNoApiView { * via the `definition` "custom-views-one". */ export interface CustomViewsOne { - id: number; + id: string; title?: string | null; updatedAt: string; createdAt: string; @@ -252,7 +247,7 @@ export interface CustomViewsOne { * via the `definition` "custom-views-two". */ export interface CustomViewsTwo { - id: number; + id: string; title?: string | null; updatedAt: string; createdAt: string; @@ -262,20 +257,14 @@ export interface CustomViewsTwo { * via the `definition` "custom-fields". */ export interface CustomField { - id: number; + id: string; customTextServerField?: string | null; customTextClientField?: string | null; - /** - * Static field description. - */ descriptionAsString?: string | null; - /** - * Function description - */ descriptionAsFunction?: string | null; descriptionAsComponent?: string | null; customSelectField?: string | null; - relationshipFieldWithBeforeAfterInputs?: (number | null) | Post; + relationshipFieldWithBeforeAfterInputs?: (string | null) | Post; arrayFieldWithBeforeAfterInputs?: | { someTextField?: string | null; @@ -304,7 +293,7 @@ export interface CustomField { * via the `definition` "group-one-collection-ones". */ export interface GroupOneCollectionOne { - id: number; + id: string; title?: string | null; updatedAt: string; createdAt: string; @@ -314,7 +303,7 @@ export interface GroupOneCollectionOne { * via the `definition` "group-one-collection-twos". */ export interface GroupOneCollectionTwo { - id: number; + id: string; title?: string | null; updatedAt: string; createdAt: string; @@ -324,7 +313,7 @@ export interface GroupOneCollectionTwo { * via the `definition` "group-two-collection-ones". */ export interface GroupTwoCollectionOne { - id: number; + id: string; title?: string | null; updatedAt: string; createdAt: string; @@ -334,7 +323,7 @@ export interface GroupTwoCollectionOne { * via the `definition` "group-two-collection-twos". */ export interface GroupTwoCollectionTwo { - id: number; + id: string; title?: string | null; updatedAt: string; createdAt: string; @@ -344,7 +333,7 @@ export interface GroupTwoCollectionTwo { * via the `definition` "geo". */ export interface Geo { - id: number; + id: string; /** * @minItems 2 * @maxItems 2 @@ -358,7 +347,7 @@ export interface Geo { * via the `definition` "disable-duplicate". */ export interface DisableDuplicate { - id: number; + id: string; title?: string | null; updatedAt: string; createdAt: string; @@ -368,7 +357,7 @@ export interface DisableDuplicate { * via the `definition` "base-list-filters". */ export interface BaseListFilter { - id: number; + id: string; title?: string | null; updatedAt: string; createdAt: string; @@ -378,76 +367,76 @@ export interface BaseListFilter { * via the `definition` "payload-locked-documents". */ export interface PayloadLockedDocument { - id: number; + id: string; document?: | ({ relationTo: 'uploads'; - value: number | Upload; + value: string | Upload; } | null) | ({ relationTo: 'posts'; - value: number | Post; + value: string | Post; } | null) | ({ relationTo: 'users'; - value: number | User; + value: string | User; } | null) | ({ relationTo: 'hidden-collection'; - value: number | HiddenCollection; + value: string | HiddenCollection; } | null) | ({ relationTo: 'not-in-view-collection'; - value: number | NotInViewCollection; + value: string | NotInViewCollection; } | null) | ({ relationTo: 'collection-no-api-view'; - value: number | CollectionNoApiView; + value: string | CollectionNoApiView; } | null) | ({ relationTo: 'custom-views-one'; - value: number | CustomViewsOne; + value: string | CustomViewsOne; } | null) | ({ relationTo: 'custom-views-two'; - value: number | CustomViewsTwo; + value: string | CustomViewsTwo; } | null) | ({ relationTo: 'custom-fields'; - value: number | CustomField; + value: string | CustomField; } | null) | ({ relationTo: 'group-one-collection-ones'; - value: number | GroupOneCollectionOne; + value: string | GroupOneCollectionOne; } | null) | ({ relationTo: 'group-one-collection-twos'; - value: number | GroupOneCollectionTwo; + value: string | GroupOneCollectionTwo; } | null) | ({ relationTo: 'group-two-collection-ones'; - value: number | GroupTwoCollectionOne; + value: string | GroupTwoCollectionOne; } | null) | ({ relationTo: 'group-two-collection-twos'; - value: number | GroupTwoCollectionTwo; + value: string | GroupTwoCollectionTwo; } | null) | ({ relationTo: 'geo'; - value: number | Geo; + value: string | Geo; } | null) | ({ relationTo: 'disable-duplicate'; - value: number | DisableDuplicate; + value: string | DisableDuplicate; } | null) | ({ relationTo: 'base-list-filters'; - value: number | BaseListFilter; + value: string | BaseListFilter; } | null); globalSlug?: string | null; user: { relationTo: 'users'; - value: number | User; + value: string | User; }; updatedAt: string; createdAt: string; @@ -457,10 +446,10 @@ export interface PayloadLockedDocument { * via the `definition` "payload-preferences". */ export interface PayloadPreference { - id: number; + id: string; user: { relationTo: 'users'; - value: number | User; + value: string | User; }; key?: string | null; value?: @@ -480,7 +469,7 @@ export interface PayloadPreference { * via the `definition` "payload-migrations". */ export interface PayloadMigration { - id: number; + id: string; name?: string | null; batch?: number | null; updatedAt: string; @@ -769,7 +758,7 @@ export interface PayloadMigrationsSelect { * via the `definition` "hidden-global". */ export interface HiddenGlobal { - id: number; + id: string; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -779,7 +768,7 @@ export interface HiddenGlobal { * via the `definition` "not-in-view-global". */ export interface NotInViewGlobal { - id: number; + id: string; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -789,7 +778,7 @@ export interface NotInViewGlobal { * via the `definition` "global-no-api-view". */ export interface GlobalNoApiView { - id: number; + id: string; updatedAt?: string | null; createdAt?: string | null; } @@ -798,7 +787,7 @@ export interface GlobalNoApiView { * via the `definition` "global". */ export interface Global { - id: number; + id: string; title?: string | null; sidebarField?: string | null; _status?: ('draft' | 'published') | null; @@ -810,7 +799,7 @@ export interface Global { * via the `definition` "custom-global-views-one". */ export interface CustomGlobalViewsOne { - id: number; + id: string; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -820,7 +809,7 @@ export interface CustomGlobalViewsOne { * via the `definition` "custom-global-views-two". */ export interface CustomGlobalViewsTwo { - id: number; + id: string; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -830,7 +819,7 @@ export interface CustomGlobalViewsTwo { * via the `definition` "group-globals-one". */ export interface GroupGlobalsOne { - id: number; + id: string; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -840,7 +829,7 @@ export interface GroupGlobalsOne { * via the `definition` "group-globals-two". */ export interface GroupGlobalsTwo { - id: number; + id: string; title?: string | null; updatedAt?: string | null; createdAt?: string | null; @@ -850,7 +839,7 @@ export interface GroupGlobalsTwo { * via the `definition` "settings". */ export interface Setting { - id: number; + id: string; canAccessProtected?: boolean | null; updatedAt?: string | null; createdAt?: string | null; From 39346d7b3e4d7b80e4794933fa91955e8a686a97 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Wed, 1 Jan 2025 04:21:45 +0200 Subject: [PATCH 5/6] update comments --- packages/ui/src/utilities/copyDataFromLocale.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/utilities/copyDataFromLocale.ts b/packages/ui/src/utilities/copyDataFromLocale.ts index 4ac8a65ed16..6eaa1980d37 100644 --- a/packages/ui/src/utilities/copyDataFromLocale.ts +++ b/packages/ui/src/utilities/copyDataFromLocale.ts @@ -37,10 +37,11 @@ function iterateFields(fields: Field[], fromLocaleData: Data, toLocaleData: Data break } - // if the field has a value but is not localized, loop over the data from target + // if the field has a value - loop over the data from target if (field.name in toLocaleData) { toLocaleData[field.name].map((item: Data, index: number) => { if (fromLocaleData[field.name]?.[index]) { + // Generate new IDs if the field is localized to prevent errors with relational DBs. if (field.localized) { toLocaleData[field.name][index].id = new ObjectId().toHexString() } @@ -63,13 +64,14 @@ function iterateFields(fields: Field[], fromLocaleData: Data, toLocaleData: Data break } - // if the field has a value but is not localized, loop over the data from target + // if the field has a value - loop over the data from target if (field.name in toLocaleData) { toLocaleData[field.name].map((blockData: Data, index: number) => { const blockFields = field.blocks.find( ({ slug }) => slug === blockData.blockType, )?.fields + // Generate new IDs if the field is localized to prevent errors with relational DBs. if (field.localized) { toLocaleData[field.name][index].id = new ObjectId().toHexString() } From c5ef29d9bacb232541acacf7adeb0170884e1c27 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:21:44 +0200 Subject: [PATCH 6/6] fix e2e locator to specific array --- test/localization/e2e.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/localization/e2e.spec.ts b/test/localization/e2e.spec.ts index 869ad08972c..00cc6df75fd 100644 --- a/test/localization/e2e.spec.ts +++ b/test/localization/e2e.spec.ts @@ -315,7 +315,7 @@ describe('Localization', () => { const nestedArrayURL = new AdminUrlUtil(serverURL, nestedToArrayAndBlockCollectionSlug) await page.goto(nestedArrayURL.create) await changeLocale(page, 'ar') - const addArrayRow = page.locator('.array-field__add-row') + const addArrayRow = page.locator('#field-topLevelArray .array-field__add-row') await addArrayRow.click() const arrayField = page.locator('#field-topLevelArray__0__localizedText')