From 8a9f96e53ab5f8c86d68841080aba6a806a9dbfe Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Thu, 23 Sep 2021 16:15:37 +0200 Subject: [PATCH] fixes issue with selected locals (#1200) fixes: #1179 --- src/realm-settings/LocalizationTab.tsx | 204 ++++++++++++------------- 1 file changed, 100 insertions(+), 104 deletions(-) diff --git a/src/realm-settings/LocalizationTab.tsx b/src/realm-settings/LocalizationTab.tsx index 393310d1e5..37af37cee0 100644 --- a/src/realm-settings/LocalizationTab.tsx +++ b/src/realm-settings/LocalizationTab.tsx @@ -70,7 +70,6 @@ export const LocalizationTab = ({ control, name: "supportedLocales", }); - const internationalizationEnabled = useWatch({ control, name: "internationalizationEnabled", @@ -208,110 +207,107 @@ export const LocalizationTab = ({ )} /> - {internationalizationEnabled && ( - <> - - ( - - )} - /> - - - ( - { + setSupportedLocalesOpen(open); + }} + onSelect={(_, v) => { + const option = v as string; + if (!value) { + onChange([option]); + } else if (value.includes(option)) { + onChange( + value.filter((item: string) => item !== option) + ); + } else { + onChange([...value, option]); } - onSelect={(_, value) => { - onChange(value as string); - setValueSelected(true); - setDefaultLocaleOpen(false); - }} - selections={ - valueSelected - ? t(`allSupportedLocales.${value}`) - : realm.defaultLocale !== "" - ? t( - `allSupportedLocales.${ - realm.defaultLocale || DEFAULT_LOCALE - }` - ) - : t("placeholderText") - } - variant={SelectVariant.single} - aria-label={t("defaultLocale")} - isOpen={defaultLocaleOpen} - placeholderText={t("placeholderText")} - data-testid="select-default-locale" - > - {watchSupportedLocales?.map( - (locale: string, idx: number) => ( - - {t(`allSupportedLocales.${locale}`)} - - ) - )} - - )} - /> - - - )} + }} + onClear={() => { + onChange([]); + }} + selections={value} + variant={SelectVariant.typeaheadMulti} + aria-label={t("supportedLocales")} + isOpen={supportedLocalesOpen} + placeholderText={"Select locales"} + > + {themeTypes.login![0].locales.map( + (locale: string, idx: number) => ( + + {t(`allSupportedLocales.${locale}`)} + + ) + )} + + ) : ( +
+ ); + }} + /> + + + { + return internationalizationEnabled ? ( + + ) : ( +
+ ); + }} + /> +