From 83af3bc4559ca194370c4fbcdaf8e1504c16fbfa Mon Sep 17 00:00:00 2001 From: agagancarczyk <4890675+agagancarczyk@users.noreply.github.com> Date: Tue, 18 Jun 2024 08:06:10 +0100 Subject: [PATCH] Fixed refreshing translations on user detail's tab (#30199) * added translations refresh Signed-off-by: Agnieszka Gancarczyk * added translation refresh on adding new translation from realm overrides Signed-off-by: Agnieszka Gancarczyk * added translation refresh on deleting translations from realm overrides Signed-off-by: Agnieszka Gancarczyk * fixed test Signed-off-by: Agnieszka Gancarczyk * fixed test Signed-off-by: Agnieszka Gancarczyk * fixed test Signed-off-by: Agnieszka Gancarczyk * fixed test Signed-off-by: Agnieszka Gancarczyk --------- Signed-off-by: Agnieszka Gancarczyk Co-authored-by: Agnieszka Gancarczyk --- .../cypress/e2e/partial_import_test.spec.ts | 7 +++--- .../partial-import-test-data/client-only.json | 21 +++++++++--------- .../realm-settings/NewAttributeSettings.tsx | 2 ++ .../localization/RealmOverrides.tsx | 22 ++++++++++++++----- .../user-profile/AttributesGroupForm.tsx | 2 ++ 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/js/apps/admin-ui/cypress/e2e/partial_import_test.spec.ts b/js/apps/admin-ui/cypress/e2e/partial_import_test.spec.ts index 2ad43ee0c8..ad3871a4e6 100644 --- a/js/apps/admin-ui/cypress/e2e/partial_import_test.spec.ts +++ b/js/apps/admin-ui/cypress/e2e/partial_import_test.spec.ts @@ -110,7 +110,7 @@ describe("Partial import test", () => { modal.importButton().click(); cy.contains("One record added"); - cy.contains("customer-portal"); + cy.contains("customer-portal3"); modal.closeButton().click(); }); @@ -119,8 +119,9 @@ describe("Partial import test", () => { //clear button should be disabled if there is nothing in the dialog modal.clearButton().should("be.disabled"); - modal.textArea().type("test", { force: true }); - modal.textArea().get(".view-lines").should("have.text", "test"); + modal.textArea().get(".view-lines").should("have.text", ""); + modal.textArea().type("{}", { force: true }); + modal.textArea().get(".view-lines").should("have.text", "{}"); modal.clearButton().should("not.be.disabled"); modal.clearButton().click(); modal.clickClearConfirmButton(); diff --git a/js/apps/admin-ui/cypress/fixtures/partial-import-test-data/client-only.json b/js/apps/admin-ui/cypress/fixtures/partial-import-test-data/client-only.json index fa7b64ad8b..b051e3a1fa 100644 --- a/js/apps/admin-ui/cypress/fixtures/partial-import-test-data/client-only.json +++ b/js/apps/admin-ui/cypress/fixtures/partial-import-test-data/client-only.json @@ -1,13 +1,12 @@ { - "clients": [ - { - "clientId": "customer-portal", - "enabled": true, - "adminUrl": "/customer-portal", - "baseUrl": "/customer-portal", - "redirectUris": [ - "/customer-portal/*" - ], - "secret": "password" - }] + "clients": [ + { + "clientId": "customer-portal3", + "enabled": true, + "adminUrl": "/customer-portal", + "baseUrl": "/customer-portal", + "redirectUris": ["/customer-portal/*"], + "secret": "password" + } + ] } diff --git a/js/apps/admin-ui/src/realm-settings/NewAttributeSettings.tsx b/js/apps/admin-ui/src/realm-settings/NewAttributeSettings.tsx index f906af097c..97ac03ae02 100644 --- a/js/apps/admin-ui/src/realm-settings/NewAttributeSettings.tsx +++ b/js/apps/admin-ui/src/realm-settings/NewAttributeSettings.tsx @@ -31,6 +31,7 @@ import { AttributeAnnotations } from "./user-profile/attribute/AttributeAnnotati import { AttributeGeneralSettings } from "./user-profile/attribute/AttributeGeneralSettings"; import { AttributePermission } from "./user-profile/attribute/AttributePermission"; import { AttributeValidations } from "./user-profile/attribute/AttributeValidations"; +import { i18n } from "../i18n/i18n"; type TranslationForm = { locale: string; @@ -394,6 +395,7 @@ export default function NewAttributeSettings() { }); await saveTranslations(); + i18n.reloadResources(); navigate(toUserProfile({ realm: realmName, tab: "attributes" })); addAlert(t("createAttributeSuccess"), AlertVariant.success); diff --git a/js/apps/admin-ui/src/realm-settings/localization/RealmOverrides.tsx b/js/apps/admin-ui/src/realm-settings/localization/RealmOverrides.tsx index b9cde01c58..845e96bad1 100644 --- a/js/apps/admin-ui/src/realm-settings/localization/RealmOverrides.tsx +++ b/js/apps/admin-ui/src/realm-settings/localization/RealmOverrides.tsx @@ -49,7 +49,7 @@ import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState import { PaginatingTableToolbar } from "../../components/table-toolbar/PaginatingTableToolbar"; import { useRealm } from "../../context/realm-context/RealmContext"; import { useWhoAmI } from "../../context/whoami/WhoAmI"; -import { DEFAULT_LOCALE } from "../../i18n/i18n"; +import { DEFAULT_LOCALE, i18n } from "../../i18n/i18n"; import { localeToDisplayName } from "../../util"; import { AddTranslationModal } from "../AddTranslationModal"; @@ -218,6 +218,8 @@ export const RealmOverrides = ({ refreshTable(); translationForm.setValue("key", ""); translationForm.setValue("value", ""); + i18n.reloadResources(); + addAlert(t("addTranslationSuccess"), AlertVariant.success); } catch (error) { addError(t("addTranslationError"), error); @@ -238,15 +240,22 @@ export const RealmOverrides = ({ onConfirm: async () => { try { for (const key of selectedRowKeys) { - await adminClient.realms.deleteRealmLocalizationTexts({ - realm: currentRealm!, - selectedLocale: selectMenuLocale, - key: key, - }); + delete ( + i18n.store.data[whoAmI.getLocale()]["translation"] as Record< + string, + string + > + )[key], + await adminClient.realms.deleteRealmLocalizationTexts({ + realm: currentRealm!, + selectedLocale: selectMenuLocale, + key: key, + }); } setAreAllRowsSelected(false); setSelectedRowKeys([]); refreshTable(); + addAlert(t("deleteAllTranslationsSuccess"), AlertVariant.success); } catch (error) { addError("deleteAllTranslationsError", error); @@ -309,6 +318,7 @@ export const RealmOverrides = ({ }, value, ); + i18n.reloadResources(); addAlert(t("updateTranslationSuccess"), AlertVariant.success); setTableRows(newRows); diff --git a/js/apps/admin-ui/src/realm-settings/user-profile/AttributesGroupForm.tsx b/js/apps/admin-ui/src/realm-settings/user-profile/AttributesGroupForm.tsx index 14aaf3e87f..3581e6a41a 100644 --- a/js/apps/admin-ui/src/realm-settings/user-profile/AttributesGroupForm.tsx +++ b/js/apps/admin-ui/src/realm-settings/user-profile/AttributesGroupForm.tsx @@ -40,6 +40,7 @@ import { AddTranslationsDialog, TranslationsType, } from "./attribute/AddTranslationsDialog"; +import { i18n } from "../../i18n/i18n"; function parseAnnotations(input: Record): KeyValueType[] { return Object.entries(input).reduce((p, [key, value]) => { @@ -346,6 +347,7 @@ export default function AttributesGroupForm() { if (success) { await saveTranslations(); + i18n.reloadResources(); navigate(toUserProfile({ realm: realmName, tab: "attributes-group" })); } };