parent
405d3310f3
commit
f4068debb8
3 changed files with 88 additions and 106 deletions
|
@ -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,63 +173,54 @@ export const LocalizationTab = ({
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<PageSection variant="light">
|
<PageSection variant="light">
|
||||||
<FormPanel
|
<FormAccess
|
||||||
className="kc-login-screen"
|
isHorizontal
|
||||||
title="Login screen customization"
|
role="manage-realm"
|
||||||
|
className="pf-u-mt-lg"
|
||||||
|
onSubmit={handleSubmit(save)}
|
||||||
>
|
>
|
||||||
<FormAccess
|
<FormGroup
|
||||||
isHorizontal
|
label={t("internationalization")}
|
||||||
role="manage-realm"
|
fieldId="kc-internationalization"
|
||||||
className="pf-u-mt-lg"
|
labelIcon={
|
||||||
onSubmit={handleSubmit(save)}
|
<HelpItem
|
||||||
>
|
helpText="realm-settings-help:internationalization"
|
||||||
<FormGroup
|
forLabel={t("internationalization")}
|
||||||
label={t("internationalization")}
|
forID="kc-internationalization"
|
||||||
fieldId="kc-internationalization"
|
|
||||||
labelIcon={
|
|
||||||
<HelpItem
|
|
||||||
helpText="realm-settings-help:internationalization"
|
|
||||||
forLabel={t("internationalization")}
|
|
||||||
forID="kc-internationalization"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Controller
|
|
||||||
name="internationalizationEnabled"
|
|
||||||
control={control}
|
|
||||||
defaultValue={false}
|
|
||||||
render={({ onChange, value }) => (
|
|
||||||
<Switch
|
|
||||||
id="kc-l-internationalization"
|
|
||||||
label={t("common:enabled")}
|
|
||||||
labelOff={t("common:disabled")}
|
|
||||||
isChecked={internationalizationEnabled}
|
|
||||||
data-testid={
|
|
||||||
value
|
|
||||||
? "internationalization-enabled"
|
|
||||||
: "internationalization-disabled"
|
|
||||||
}
|
|
||||||
onChange={onChange}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
}
|
||||||
<FormGroup
|
>
|
||||||
label={t("supportedLocales")}
|
<Controller
|
||||||
fieldId="kc-l-supported-locales"
|
name="internationalizationEnabled"
|
||||||
labelIcon={
|
control={control}
|
||||||
<HelpItem
|
defaultValue={false}
|
||||||
helpText="realm-settings-help:supportedLocales"
|
render={({ onChange, value }) => (
|
||||||
forLabel={t("supportedLocales")}
|
<Switch
|
||||||
forID="kc-l-supported-locales"
|
id="kc-l-internationalization"
|
||||||
|
label={t("common:enabled")}
|
||||||
|
labelOff={t("common:disabled")}
|
||||||
|
isChecked={internationalizationEnabled}
|
||||||
|
data-testid={
|
||||||
|
value
|
||||||
|
? "internationalization-enabled"
|
||||||
|
: "internationalization-disabled"
|
||||||
|
}
|
||||||
|
onChange={onChange}
|
||||||
/>
|
/>
|
||||||
}
|
)}
|
||||||
>
|
/>
|
||||||
<Controller
|
</FormGroup>
|
||||||
name="supportedLocales"
|
{internationalizationEnabled && (
|
||||||
control={control}
|
<>
|
||||||
render={({ onChange, value }) => {
|
<FormGroup
|
||||||
return internationalizationEnabled ? (
|
label={t("supportedLocales")}
|
||||||
|
fieldId="kc-l-supported-locales"
|
||||||
|
>
|
||||||
|
<Controller
|
||||||
|
name="supportedLocales"
|
||||||
|
control={control}
|
||||||
|
defaultValue={[DEFAULT_LOCALE]}
|
||||||
|
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
|
|
||||||
label={t("defaultLocale")}
|
|
||||||
fieldId="kc-l-default-locale"
|
|
||||||
labelIcon={
|
|
||||||
<HelpItem
|
|
||||||
helpText="realm-settings-help:defaultLocale"
|
|
||||||
forLabel={t("defaultLocale")}
|
|
||||||
forID="kc-l-default-locale"
|
|
||||||
/>
|
/>
|
||||||
}
|
</FormGroup>
|
||||||
>
|
<FormGroup
|
||||||
<Controller
|
label={t("defaultLocale")}
|
||||||
name="defaultLocale"
|
fieldId="kc-l-default-locale"
|
||||||
control={control}
|
>
|
||||||
render={({ onChange, value }) => {
|
<Controller
|
||||||
return internationalizationEnabled ? (
|
name="defaultLocale"
|
||||||
|
control={control}
|
||||||
|
defaultValue={DEFAULT_LOCALE}
|
||||||
|
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,27 +307,25 @@ export const LocalizationTab = ({
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
</Select>
|
</Select>
|
||||||
) : (
|
)}
|
||||||
<div />
|
/>
|
||||||
);
|
</FormGroup>
|
||||||
}}
|
</>
|
||||||
/>
|
)}
|
||||||
</FormGroup>
|
<ActionGroup>
|
||||||
<ActionGroup>
|
<Button
|
||||||
<Button
|
variant="primary"
|
||||||
variant="primary"
|
isDisabled={!formState.isDirty}
|
||||||
isDisabled={!formState.isDirty}
|
type="submit"
|
||||||
type="submit"
|
data-testid="localization-tab-save"
|
||||||
data-testid="localization-tab-save"
|
>
|
||||||
>
|
{t("common:save")}
|
||||||
{t("common:save")}
|
</Button>
|
||||||
</Button>
|
<Button variant="link" onClick={reset}>
|
||||||
<Button variant="link" onClick={reset}>
|
{t("common:revert")}
|
||||||
{t("common:revert")}
|
</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">
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in a new issue