From 880669bc3cf5e9ae707df6311f10c5b2a0b853d0 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Sat, 19 Oct 2024 01:14:40 +0300 Subject: [PATCH 1/2] fix(ui): unique ids for nested rows on row duplicate to prevent errors with postgres --- packages/ui/src/forms/Form/fieldReducer.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/ui/src/forms/Form/fieldReducer.ts b/packages/ui/src/forms/Form/fieldReducer.ts index 158fa7dc08b..b7164f76277 100644 --- a/packages/ui/src/forms/Form/fieldReducer.ts +++ b/packages/ui/src/forms/Form/fieldReducer.ts @@ -263,6 +263,15 @@ export function fieldReducer(state: FormState, action: FieldAction): FormState { duplicateRowState.id.initialValue = new ObjectId().toHexString() } + for (const key of Object.keys(duplicateRowState).filter((key) => key.endsWith('.id'))) { + const idState = duplicateRowState[key] + + if (idState && typeof idState.value === 'string' && ObjectId.isValid(idState.value)) { + duplicateRowState[key].value = new ObjectId().toHexString() + duplicateRowState[key].initialValue = new ObjectId().toHexString() + } + } + // If there are subfields if (Object.keys(duplicateRowState).length > 0) { // Add new object containing subfield names to unflattenedRows array From e1352d31247c3eda51983f921c4e2f95c57e5290 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Sat, 19 Oct 2024 14:12:42 +0300 Subject: [PATCH 2/2] chore: add e2e --- test/fields/collections/Blocks/e2e.spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/fields/collections/Blocks/e2e.spec.ts b/test/fields/collections/Blocks/e2e.spec.ts index db9e356c09b..afb8b9b4a94 100644 --- a/test/fields/collections/Blocks/e2e.spec.ts +++ b/test/fields/collections/Blocks/e2e.spec.ts @@ -130,6 +130,24 @@ describe('Block fields', () => { expect(await blocks.count()).toEqual(4) }) + test('should save when duplicating subblocks', async () => { + await page.goto(url.create) + const subblocksRow = page.locator('#field-blocks #blocks-row-2') + const rowActions = subblocksRow.locator('.collapsible__actions').first() + await expect(rowActions).toBeVisible() + + await rowActions.locator('.array-actions__button').click() + const duplicateButton = rowActions.locator('.array-actions__action.array-actions__duplicate') + await expect(duplicateButton).toBeVisible() + await duplicateButton.click() + + const blocks = page.locator('#field-blocks > .blocks-field__rows > div') + expect(await blocks.count()).toEqual(4) + + await page.click('#action-save') + await expect(page.locator('.payload-toast-container')).toContainText('successfully') + }) + test('should use i18n block labels', async () => { await page.goto(url.create) await expect(page.locator('#field-i18nBlocks .blocks-field__header')).toContainText('Block en')