fixes issue with selected locals (#1200)

fixes: #1179
This commit is contained in:
Erik Jan de Wit 2021-09-23 16:15:37 +02:00 committed by GitHub
parent 453b5a07e7
commit 8a9f96e53a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -70,7 +70,6 @@ export const LocalizationTab = ({
control,
name: "supportedLocales",
});
const internationalizationEnabled = useWatch({
control,
name: "internationalizationEnabled",
@ -208,8 +207,6 @@ export const LocalizationTab = ({
)}
/>
</FormGroup>
{internationalizationEnabled && (
<>
<FormGroup
label={t("supportedLocales")}
fieldId="kc-l-supported-locales"
@ -217,30 +214,29 @@ export const LocalizationTab = ({
<Controller
name="supportedLocales"
control={control}
render={({ onChange }) => (
render={({ onChange, value }) => {
return internationalizationEnabled ? (
<Select
toggleId="kc-l-supported-locales"
onToggle={() => {
setSupportedLocalesOpen(!supportedLocalesOpen);
onToggle={(open) => {
setSupportedLocalesOpen(open);
}}
onSelect={(_, v) => {
const option = v as string;
if (!watchSupportedLocales) {
if (!value) {
onChange([option]);
} else if (watchSupportedLocales!.includes(option)) {
} else if (value.includes(option)) {
onChange(
watchSupportedLocales.filter(
(item: string) => item !== option
)
value.filter((item: string) => item !== option)
);
} else {
onChange([...watchSupportedLocales, option]);
onChange([...value, option]);
}
}}
onClear={() => {
onChange([]);
}}
selections={watchSupportedLocales}
selections={value}
variant={SelectVariant.typeaheadMulti}
aria-label={t("supportedLocales")}
isOpen={supportedLocalesOpen}
@ -258,22 +254,21 @@ export const LocalizationTab = ({
)
)}
</Select>
)}
) : (
<div />
);
}}
/>
</FormGroup>
<FormGroup
label={t("defaultLocale")}
fieldId="kc-l-default-locale"
>
<FormGroup label={t("defaultLocale")} fieldId="kc-l-default-locale">
<Controller
name="defaultLocale"
control={control}
render={({ onChange, value }) => (
render={({ onChange, value }) => {
return internationalizationEnabled ? (
<Select
toggleId="kc-default-locale"
onToggle={() =>
setDefaultLocaleOpen(!defaultLocaleOpen)
}
onToggle={() => setDefaultLocaleOpen(!defaultLocaleOpen)}
onSelect={(_, value) => {
onChange(value as string);
setValueSelected(true);
@ -307,11 +302,12 @@ export const LocalizationTab = ({
)
)}
</Select>
)}
) : (
<div />
);
}}
/>
</FormGroup>
</>
)}
<ActionGroup>
<Button
variant="primary"