From 330dd33803ad244e8bee66e1f5e0dd8c6bf2b41a Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 16 Mar 2022 14:58:25 +0100 Subject: [PATCH] Always keep DEFAULT_LOCAL selected (#2241) --- src/realm-settings/LocalizationTab.tsx | 46 +++++++++++--------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/realm-settings/LocalizationTab.tsx b/src/realm-settings/LocalizationTab.tsx index a3263bef5f..d90ac7ce9c 100644 --- a/src/realm-settings/LocalizationTab.tsx +++ b/src/realm-settings/LocalizationTab.tsx @@ -97,6 +97,7 @@ export const LocalizationTab = ({ const watchSupportedLocales = useWatch({ control, name: "supportedLocales", + defaultValue: [DEFAULT_LOCALE], }); const internationalizationEnabled = useWatch({ control, @@ -227,9 +228,7 @@ export const LocalizationTab = ({ }; const updateEditableRows = async ( - evt: any, type: RowEditType, - isEditable?: boolean | undefined, rowIndex?: number, validationErrors?: RowErrors ) => { @@ -281,18 +280,14 @@ export const LocalizationTab = ({ const options = [ - {watchSupportedLocales - ?.filter((item) => item === realm.defaultLocale) - .map((locale) => ( - - {t(`allSupportedLocales.${locale}`)} - - ))} + + {t(`allSupportedLocales.${DEFAULT_LOCALE}`)} + , , {watchSupportedLocales - ?.filter((item) => item !== realm.defaultLocale) + .filter((item) => item !== realm.defaultLocale) .map((locale) => ( {t(`allSupportedLocales.${locale}`)} @@ -402,7 +397,7 @@ export const LocalizationTab = ({ } }} onClear={() => { - onChange([]); + onChange([DEFAULT_LOCALE]); }} selections={value} variant={SelectVariant.typeaheadMulti} @@ -410,20 +405,15 @@ export const LocalizationTab = ({ isOpen={supportedLocalesOpen} placeholderText={t("selectLocales")} > - { - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - themeTypes.login![0].locales?.map( - (locale: string, idx: number) => ( - - {t(`allSupportedLocales.${locale}`)} - - ) - ) - } + {themeTypes.login![0].locales.map((locale) => ( + + {t(`allSupportedLocales.${locale}`)} + + ))} )} /> @@ -461,7 +451,7 @@ export const LocalizationTab = ({ placeholderText={t("placeholderText")} data-testid="select-default-locale" > - {watchSupportedLocales?.map( + {watchSupportedLocales.map( (locale: string, idx: number) => ( + updateEditableRows(type, rowIndex, validation) + } >