can't remove english from supported locals (#1461)

fixes: #1059
This commit is contained in:
Erik Jan de Wit 2021-11-03 20:47:42 +01:00 committed by GitHub
parent 405d3310f3
commit f4068debb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 106 deletions

View file

@ -59,7 +59,6 @@ export const LocalizationTab = ({
const [selectMenuLocale, setSelectMenuLocale] = useState(DEFAULT_LOCALE); const [selectMenuLocale, setSelectMenuLocale] = useState(DEFAULT_LOCALE);
const { getValues, control, handleSubmit, formState } = useFormContext(); const { getValues, control, handleSubmit, formState } = useFormContext();
const [valueSelected, setValueSelected] = useState(false);
const [selectMenuValueSelected, setSelectMenuValueSelected] = useState(false); const [selectMenuValueSelected, setSelectMenuValueSelected] = useState(false);
const themeTypes = useServerInfo().themes!; const themeTypes = useServerInfo().themes!;
@ -174,10 +173,6 @@ export const LocalizationTab = ({
/> />
)} )}
<PageSection variant="light"> <PageSection variant="light">
<FormPanel
className="kc-login-screen"
title="Login screen customization"
>
<FormAccess <FormAccess
isHorizontal isHorizontal
role="manage-realm" role="manage-realm"
@ -215,22 +210,17 @@ export const LocalizationTab = ({
)} )}
/> />
</FormGroup> </FormGroup>
{internationalizationEnabled && (
<>
<FormGroup <FormGroup
label={t("supportedLocales")} label={t("supportedLocales")}
fieldId="kc-l-supported-locales" fieldId="kc-l-supported-locales"
labelIcon={
<HelpItem
helpText="realm-settings-help:supportedLocales"
forLabel={t("supportedLocales")}
forID="kc-l-supported-locales"
/>
}
> >
<Controller <Controller
name="supportedLocales" name="supportedLocales"
control={control} control={control}
render={({ onChange, value }) => { defaultValue={[DEFAULT_LOCALE]}
return internationalizationEnabled ? ( render={({ onChange, value }) => (
<Select <Select
toggleId="kc-l-supported-locales" toggleId="kc-l-supported-locales"
onToggle={(open) => { onToggle={(open) => {
@ -238,11 +228,12 @@ export const LocalizationTab = ({
}} }}
onSelect={(_, v) => { onSelect={(_, v) => {
const option = v as string; const option = v as string;
if (!value) { if (value.includes(option)) {
onChange([option]);
} else if (value.includes(option)) {
onChange( onChange(
value.filter((item: string) => item !== option) value.filter(
(item: string) =>
item !== option || option === DEFAULT_LOCALE
)
); );
} else { } else {
onChange([...value, option]); onChange([...value, option]);
@ -255,12 +246,12 @@ export const LocalizationTab = ({
variant={SelectVariant.typeaheadMulti} variant={SelectVariant.typeaheadMulti}
aria-label={t("supportedLocales")} aria-label={t("supportedLocales")}
isOpen={supportedLocalesOpen} isOpen={supportedLocalesOpen}
placeholderText={"Select locales"} placeholderText={t("selectLocales")}
> >
{themeTypes.login![0].locales.map( {themeTypes.login![0].locales.map(
(locale: string, idx: number) => ( (locale: string, idx: number) => (
<SelectOption <SelectOption
selected={true} selected={value.includes(locale)}
key={`locale-${idx}`} key={`locale-${idx}`}
value={locale} value={locale}
> >
@ -269,38 +260,27 @@ export const LocalizationTab = ({
) )
)} )}
</Select> </Select>
) : ( )}
<div />
);
}}
/> />
</FormGroup> </FormGroup>
<FormGroup <FormGroup
label={t("defaultLocale")} label={t("defaultLocale")}
fieldId="kc-l-default-locale" fieldId="kc-l-default-locale"
labelIcon={
<HelpItem
helpText="realm-settings-help:defaultLocale"
forLabel={t("defaultLocale")}
forID="kc-l-default-locale"
/>
}
> >
<Controller <Controller
name="defaultLocale" name="defaultLocale"
control={control} control={control}
render={({ onChange, value }) => { defaultValue={DEFAULT_LOCALE}
return internationalizationEnabled ? ( render={({ onChange, value }) => (
<Select <Select
toggleId="kc-default-locale" toggleId="kc-default-locale"
onToggle={() => setDefaultLocaleOpen(!defaultLocaleOpen)} onToggle={() => setDefaultLocaleOpen(!defaultLocaleOpen)}
onSelect={(_, value) => { onSelect={(_, value) => {
onChange(value as string); onChange(value as string);
setValueSelected(true);
setDefaultLocaleOpen(false); setDefaultLocaleOpen(false);
}} }}
selections={ selections={
valueSelected value
? t(`allSupportedLocales.${value}`) ? t(`allSupportedLocales.${value}`)
: realm.defaultLocale !== "" : realm.defaultLocale !== ""
? t( ? t(
@ -327,12 +307,11 @@ export const LocalizationTab = ({
) )
)} )}
</Select> </Select>
) : ( )}
<div />
);
}}
/> />
</FormGroup> </FormGroup>
</>
)}
<ActionGroup> <ActionGroup>
<Button <Button
variant="primary" variant="primary"
@ -347,7 +326,6 @@ export const LocalizationTab = ({
</Button> </Button>
</ActionGroup> </ActionGroup>
</FormAccess> </FormAccess>
</FormPanel>
<FormPanel className="kc-message-bundles" title="Edit message bundles"> <FormPanel className="kc-message-bundles" title="Edit message bundles">
<TextContent className="messageBundleDescription"> <TextContent className="messageBundleDescription">

View file

@ -47,6 +47,7 @@ import { PartialExportDialog } from "./PartialExport";
import { toRealmSettings } from "./routes/RealmSettings"; import { toRealmSettings } from "./routes/RealmSettings";
import { LocalizationTab } from "./LocalizationTab"; import { LocalizationTab } from "./LocalizationTab";
import { HelpItem } from "../components/help-enabler/HelpItem"; import { HelpItem } from "../components/help-enabler/HelpItem";
import { DEFAULT_LOCALE } from "../i18n";
type RealmSettingsHeaderProps = { type RealmSettingsHeaderProps = {
onChange: (value: boolean) => void; onChange: (value: boolean) => void;
@ -168,7 +169,7 @@ export const RealmSettingsTabs = ({
const kpComponentTypes = const kpComponentTypes =
useServerInfo().componentTypes?.[KEY_PROVIDER_TYPE] ?? []; useServerInfo().componentTypes?.[KEY_PROVIDER_TYPE] ?? [];
const form = useForm({ mode: "onChange" }); const form = useForm({ mode: "onChange", shouldUnregister: false });
const { control, getValues, setValue, reset: resetForm } = form; const { control, getValues, setValue, reset: resetForm } = form;
const [activeTab, setActiveTab] = useState(0); const [activeTab, setActiveTab] = useState(0);
@ -182,6 +183,8 @@ export const RealmSettingsTabs = ({
Object.entries(r).map(([key, value]) => { Object.entries(r).map(([key, value]) => {
if (key === "attributes") { if (key === "attributes") {
convertToFormValues(value, "attributes", setValue); convertToFormValues(value, "attributes", setValue);
} else if (key === "supportedLocales" && value?.length === 0) {
setValue(key, [DEFAULT_LOCALE]);
} else { } else {
setValue(key, value); setValue(key, value);
} }

View file

@ -336,6 +336,7 @@ export default {
pairCreatedError: "Error creating localization text.", pairCreatedError: "Error creating localization text.",
supportedLocales: "Supported locales", supportedLocales: "Supported locales",
defaultLocale: "Default locale", defaultLocale: "Default locale",
selectLocales: "Select locales",
addMessageBundle: "Add message bundle", addMessageBundle: "Add message bundle",
eventType: "Event saved type", eventType: "Event saved type",
searchEventType: "Search saved event type", searchEventType: "Search saved event type",