Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form Builder - Delete Settings Entry On Locale Deletion #4460

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/api-form-builder/__tests__/graphql/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,19 @@ export const CREATE_LOCALE = /* GraphQL */ `
}
}
`;

export const DELETE_LOCALE = /* GraphQL */ `
mutation DeleteI18NLocale($code: String!) {
i18n {
deleteI18NLocale(code: $code) {
data {
code
}
error {
message
code
}
}
}
}
`;
57 changes: 48 additions & 9 deletions packages/api-form-builder/__tests__/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import useGqlHandler from "./useGqlHandler";
import { GET_SETTINGS } from "~tests/graphql/formBuilderSettings";

describe("Settings Test", () => {
const { getSettings, updateSettings, install, createI18NLocale, isInstalled } = useGqlHandler();

test(`Should not be able to get & update settings before "install"`, async () => {
const {
getSettings,
updateSettings,
install,
createI18NLocale,
deleteI18NLocale,
isInstalled
} = useGqlHandler();

it(`Should not be able to get & update settings before "install"`, async () => {
// Should not have any settings without install
const [getSettingsResponse] = await getSettings();

Expand Down Expand Up @@ -40,7 +47,7 @@ describe("Settings Test", () => {
});
});

test("Should be able to install `Form Builder`", async () => {
it("Should be able to install `Form Builder`", async () => {
// "isInstalled" should return false prior "install"
const [isInstalledResponse] = await isInstalled();

Expand Down Expand Up @@ -78,7 +85,7 @@ describe("Settings Test", () => {
});
});

test(`Should be able to get & update settings after "install"`, async () => {
it(`Should be able to get & update settings after "install"`, async () => {
// Let's install the `Form builder`
const [installResponse] = await install({ domain: "http://localhost:3001" });

Expand Down Expand Up @@ -156,7 +163,7 @@ describe("Settings Test", () => {
});
});

test(`Should be able to get & update settings after in a new locale`, async () => {
it(`Should be able to get & update settings after in a new locale`, async () => {
// Let's install the `Form builder`
await install({ domain: "http://localhost:3001" });

Expand All @@ -168,9 +175,7 @@ describe("Settings Test", () => {
// set the locale header. Wasn't easily possible via the `getSettings` helper.
const [newLocaleFbSettings] = await invoke({
body: { query: GET_SETTINGS },
headers: {
"x-i18n-locale": "default:de-DE;content:de-DE;"
}
headers: { "x-i18n-locale": "default:de-DE;content:de-DE;" }
});

// Settings should exist in the newly created locale.
Expand All @@ -192,4 +197,38 @@ describe("Settings Test", () => {
}
});
});

it(`Should be able to create a locale, delete it, and again create it`, async () => {
// Let's install the `Form builder`
await install({ domain: "http://localhost:3001" });

await createI18NLocale({ data: { code: "en-US" } });
await createI18NLocale({ data: { code: "de-DE" } });

const [deleteDeLocaleResponse] = await deleteI18NLocale({ code: "de-DE" });
expect(deleteDeLocaleResponse).toEqual({
data: {
i18n: {
deleteI18NLocale: {
data: { code: "de-DE" },
error: null
}
}
}
});

const [createDeLocaleResponse] = await createI18NLocale({ data: { code: "de-DE" } });
expect(createDeLocaleResponse).toEqual({
data: {
i18n: {
createI18NLocale: {
data: {
code: "de-DE"
},
error: null
}
}
}
});
});
});
5 changes: 4 additions & 1 deletion packages/api-form-builder/__tests__/useGqlHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createI18NGraphQL } from "@webiny/api-i18n/graphql";

// Graphql
import { INSTALL as INSTALL_FILE_MANAGER } from "./graphql/fileManagerSettings";
import { CREATE_LOCALE } from "./graphql/i18n";
import { DELETE_LOCALE, CREATE_LOCALE } from "./graphql/i18n";

import {
GET_SETTINGS,
Expand Down Expand Up @@ -228,6 +228,9 @@ export default (params: UseGqlHandlerParams = {}) => {
// Locales.
async createI18NLocale(variables: Record<string, any>) {
return invoke({ body: { query: CREATE_LOCALE, variables } });
},
async deleteI18NLocale(variables: Record<string, any>) {
return invoke({ body: { query: DELETE_LOCALE, variables } });
}
};
};
7 changes: 7 additions & 0 deletions packages/api-form-builder/src/plugins/crud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ export default (params: CreateFormBuilderCrudParams) => {
return context.formBuilder.createSettings({});
});
});

context.i18n.locales.onLocaleAfterDelete.subscribe(async params => {
const { locale } = params;
await context.i18n.withLocale(locale, async () => {
return context.formBuilder.deleteSettings();
});
});
})
];
};
Loading