From 46a11e9aa15d5c5a7561b98008f8115c0dd410c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Zori=C4=87?= Date: Thu, 19 Dec 2024 14:56:28 +0100 Subject: [PATCH] fix(api-form-builder): skip create fb on new locale if fb not installed on current locale --- .../src/operations/form/index.ts | 3 ++- packages/api-form-builder/__tests__/forms.test.ts | 10 +++++----- packages/api-form-builder/src/plugins/crud/index.ts | 6 ++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/api-form-builder-so-ddb/src/operations/form/index.ts b/packages/api-form-builder-so-ddb/src/operations/form/index.ts index c25f60780dc..8177b0c942a 100644 --- a/packages/api-form-builder-so-ddb/src/operations/form/index.ts +++ b/packages/api-form-builder-so-ddb/src/operations/form/index.ts @@ -513,7 +513,8 @@ export const createFormStorageOperations = ( } let latestPublishedKeys: Keys | undefined; const entityBatch = createEntityWriteBatch({ - entity + entity, + delete: [createLatestKeys(form)] }); for (const item of items) { diff --git a/packages/api-form-builder/__tests__/forms.test.ts b/packages/api-form-builder/__tests__/forms.test.ts index 0b29a520ec1..a2b9fc330b0 100644 --- a/packages/api-form-builder/__tests__/forms.test.ts +++ b/packages/api-form-builder/__tests__/forms.test.ts @@ -40,7 +40,7 @@ describe('Form Builder "Form" Test', () => { } }); - test("should create a form and return it in the list of latest forms", async () => { + it("should create a form and return it in the list of latest forms", async () => { const [create] = await createForm({ data: { name: "contact-us" } }); const { id } = create.data.formBuilder.createForm.data; @@ -70,7 +70,7 @@ describe('Form Builder "Form" Test', () => { expect(data[0].id).toEqual(id); }); - test("should update form and return new data from storage", async () => { + it("should update form and return new data from storage", async () => { const [create] = await createForm({ data: { name: "contact-us" } }); const { id } = create.data.formBuilder.createForm.data; @@ -219,7 +219,7 @@ describe('Form Builder "Form" Test', () => { expect(revisions[0].version).toEqual(2); }); - test("should delete a form and all of its revisions", async () => { + it("should delete a form and all of its revisions", async () => { const [create] = await createForm({ data: { name: "contact-us" } }); const { id } = create.data.formBuilder.createForm.data; @@ -246,7 +246,7 @@ describe('Form Builder "Form" Test', () => { expect(list.data.formBuilder.listForms.data.length).toBe(0); }); - test("should publish, add views and unpublish", async () => { + it("should publish, add views and unpublish", async () => { const [create] = await createForm({ data: { name: "contact-us" } }); const { id } = create.data.formBuilder.createForm.data; @@ -306,7 +306,7 @@ describe('Form Builder "Form" Test', () => { expect(latestPublished3.data.formBuilder.getPublishedForm.data.id).toEqual(id); }); - test("should create, list and export submissions to file", async () => { + it("should create, list and export submissions to file", async () => { const [create] = await createForm({ data: { name: "contact-us" } }); const { id } = create.data.formBuilder.createForm.data; diff --git a/packages/api-form-builder/src/plugins/crud/index.ts b/packages/api-form-builder/src/plugins/crud/index.ts index 5a20f2300b6..0c94f6f367a 100644 --- a/packages/api-form-builder/src/plugins/crud/index.ts +++ b/packages/api-form-builder/src/plugins/crud/index.ts @@ -111,6 +111,12 @@ export default (params: CreateFormBuilderCrudParams) => { // Once a new locale is created, we need to create a new settings entry for it. new ContextPlugin(async context => { context.i18n.locales.onLocaleAfterCreate.subscribe(async params => { + // We don't want to auto-create the settings entry if Form Builder is not installed. + // This is because the entry will be created by the app's installer. + const fbIsInstalled = Boolean(await context.formBuilder.getSystemVersion()); + if (!fbIsInstalled) { + return; + } const { locale } = params; await context.i18n.withLocale(locale, async () => { return context.formBuilder.createSettings({});