Always keep DEFAULT_LOCAL selected (#2241)

This commit is contained in:
Erik Jan de Wit 2022-03-16 14:58:25 +01:00 committed by GitHub
parent b023c802f5
commit 330dd33803
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -97,6 +97,7 @@ export const LocalizationTab = ({
const watchSupportedLocales = useWatch<string[]>({ const watchSupportedLocales = useWatch<string[]>({
control, control,
name: "supportedLocales", name: "supportedLocales",
defaultValue: [DEFAULT_LOCALE],
}); });
const internationalizationEnabled = useWatch({ const internationalizationEnabled = useWatch({
control, control,
@ -227,9 +228,7 @@ export const LocalizationTab = ({
}; };
const updateEditableRows = async ( const updateEditableRows = async (
evt: any,
type: RowEditType, type: RowEditType,
isEditable?: boolean | undefined,
rowIndex?: number, rowIndex?: number,
validationErrors?: RowErrors validationErrors?: RowErrors
) => { ) => {
@ -281,18 +280,14 @@ export const LocalizationTab = ({
const options = [ const options = [
<SelectGroup label={t("defaultLocale")} key="group1"> <SelectGroup label={t("defaultLocale")} key="group1">
{watchSupportedLocales <SelectOption key={DEFAULT_LOCALE} value={DEFAULT_LOCALE}>
?.filter((item) => item === realm.defaultLocale) {t(`allSupportedLocales.${DEFAULT_LOCALE}`)}
.map((locale) => (
<SelectOption key={locale} value={locale}>
{t(`allSupportedLocales.${locale}`)}
</SelectOption> </SelectOption>
))}
</SelectGroup>, </SelectGroup>,
<Divider key="divider" />, <Divider key="divider" />,
<SelectGroup label={t("supportedLocales")} key="group2"> <SelectGroup label={t("supportedLocales")} key="group2">
{watchSupportedLocales {watchSupportedLocales
?.filter((item) => item !== realm.defaultLocale) .filter((item) => item !== realm.defaultLocale)
.map((locale) => ( .map((locale) => (
<SelectOption key={locale} value={locale}> <SelectOption key={locale} value={locale}>
{t(`allSupportedLocales.${locale}`)} {t(`allSupportedLocales.${locale}`)}
@ -402,7 +397,7 @@ export const LocalizationTab = ({
} }
}} }}
onClear={() => { onClear={() => {
onChange([]); onChange([DEFAULT_LOCALE]);
}} }}
selections={value} selections={value}
variant={SelectVariant.typeaheadMulti} variant={SelectVariant.typeaheadMulti}
@ -410,20 +405,15 @@ export const LocalizationTab = ({
isOpen={supportedLocalesOpen} isOpen={supportedLocalesOpen}
placeholderText={t("selectLocales")} placeholderText={t("selectLocales")}
> >
{ {themeTypes.login![0].locales.map((locale) => (
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
themeTypes.login![0].locales?.map(
(locale: string, idx: number) => (
<SelectOption <SelectOption
selected={value.includes(locale)} selected={value.includes(locale)}
key={`locale-${idx}`} key={locale}
value={locale} value={locale}
> >
{t(`allSupportedLocales.${locale}`)} {t(`allSupportedLocales.${locale}`)}
</SelectOption> </SelectOption>
) ))}
)
}
</Select> </Select>
)} )}
/> />
@ -461,7 +451,7 @@ export const LocalizationTab = ({
placeholderText={t("placeholderText")} placeholderText={t("placeholderText")}
data-testid="select-default-locale" data-testid="select-default-locale"
> >
{watchSupportedLocales?.map( {watchSupportedLocales.map(
(locale: string, idx: number) => ( (locale: string, idx: number) => (
<SelectOption <SelectOption
key={`default-locale-${idx}`} key={`default-locale-${idx}`}
@ -576,7 +566,9 @@ export const LocalizationTab = ({
variant={TableVariant.compact} variant={TableVariant.compact}
cells={[t("common:key"), t("common:value")]} cells={[t("common:key"), t("common:value")]}
rows={tableRows} rows={tableRows}
onRowEdit={updateEditableRows} onRowEdit={(_, type, _b, rowIndex, validation) =>
updateEditableRows(type, rowIndex, validation)
}
> >
<TableHeader /> <TableHeader />
<TableBody /> <TableBody />