2022-08-03 12:12:07 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2021-06-16 11:38:36 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-02-02 10:33:57 +00:00
|
|
|
import { cloneDeep, isEqual, uniqWith } from "lodash-es";
|
2022-06-15 12:57:39 +00:00
|
|
|
import { Controller, useForm, useWatch } from "react-hook-form";
|
2021-06-16 11:38:36 +00:00
|
|
|
import {
|
|
|
|
ActionGroup,
|
2021-07-01 06:48:30 +00:00
|
|
|
AlertVariant,
|
2021-06-16 11:38:36 +00:00
|
|
|
Button,
|
2021-08-17 12:50:31 +00:00
|
|
|
Divider,
|
2021-06-16 11:38:36 +00:00
|
|
|
FormGroup,
|
|
|
|
PageSection,
|
|
|
|
Select,
|
2021-08-17 12:50:31 +00:00
|
|
|
SelectGroup,
|
2021-06-16 11:38:36 +00:00
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
Switch,
|
|
|
|
TextContent,
|
2021-08-17 12:50:31 +00:00
|
|
|
ToolbarItem,
|
2021-06-16 11:38:36 +00:00
|
|
|
} from "@patternfly/react-core";
|
|
|
|
|
2021-08-26 08:39:35 +00:00
|
|
|
import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
|
2021-06-16 11:38:36 +00:00
|
|
|
import { FormAccess } from "../components/form-access/FormAccess";
|
|
|
|
import { useServerInfo } from "../context/server-info/ServerInfoProvider";
|
|
|
|
import { FormPanel } from "../components/scroll-form/FormPanel";
|
2021-12-21 06:34:44 +00:00
|
|
|
import { useAdminClient, useFetch } from "../context/auth/AdminClient";
|
2021-06-16 11:38:36 +00:00
|
|
|
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
|
2021-07-01 06:48:30 +00:00
|
|
|
import { AddMessageBundleModal } from "./AddMessageBundleModal";
|
|
|
|
import { useAlerts } from "../components/alert/Alerts";
|
2021-09-30 08:58:30 +00:00
|
|
|
import { HelpItem } from "../components/help-enabler/HelpItem";
|
2021-07-01 16:44:36 +00:00
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
2021-08-19 13:56:00 +00:00
|
|
|
import { DEFAULT_LOCALE } from "../i18n";
|
2021-12-21 06:34:44 +00:00
|
|
|
import {
|
|
|
|
EditableTextCell,
|
|
|
|
validateCellEdits,
|
|
|
|
cancelCellEdits,
|
|
|
|
applyCellEdits,
|
|
|
|
RowErrors,
|
|
|
|
RowEditType,
|
|
|
|
IRowCell,
|
|
|
|
TableBody,
|
|
|
|
TableHeader,
|
|
|
|
Table,
|
|
|
|
TableVariant,
|
|
|
|
IRow,
|
|
|
|
IEditableTextCell,
|
|
|
|
} from "@patternfly/react-table";
|
|
|
|
import type { EditableTextCellProps } from "@patternfly/react-table/dist/esm/components/Table/base";
|
|
|
|
import { PaginatingTableToolbar } from "../components/table-toolbar/PaginatingTableToolbar";
|
|
|
|
import { SearchIcon } from "@patternfly/react-icons";
|
|
|
|
import { useWhoAmI } from "../context/whoami/WhoAmI";
|
2022-04-20 17:11:46 +00:00
|
|
|
import type { KeyValueType } from "../components/key-value-form/key-value-convert";
|
2022-06-15 12:57:39 +00:00
|
|
|
import { convertToFormValues } from "../util";
|
2021-06-16 11:38:36 +00:00
|
|
|
|
|
|
|
type LocalizationTabProps = {
|
|
|
|
save: (realm: RealmRepresentation) => void;
|
|
|
|
refresh: () => void;
|
|
|
|
realm: RealmRepresentation;
|
|
|
|
};
|
|
|
|
|
2021-12-21 06:34:44 +00:00
|
|
|
export enum RowEditAction {
|
|
|
|
Save = "save",
|
|
|
|
Cancel = "cancel",
|
|
|
|
Edit = "edit",
|
|
|
|
}
|
|
|
|
|
2021-07-01 06:48:30 +00:00
|
|
|
export type BundleForm = {
|
|
|
|
messageBundle: KeyValueType;
|
|
|
|
};
|
|
|
|
|
2022-07-27 16:10:28 +00:00
|
|
|
const localeToDisplayName = (locale: string) =>
|
|
|
|
new Intl.DisplayNames([locale], { type: "language" }).of(locale);
|
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
export const LocalizationTab = ({ save, realm }: LocalizationTabProps) => {
|
2021-06-16 11:38:36 +00:00
|
|
|
const { t } = useTranslation("realm-settings");
|
2022-07-14 13:02:28 +00:00
|
|
|
const { adminClient } = useAdminClient();
|
2021-07-05 11:24:10 +00:00
|
|
|
const [addMessageBundleModalOpen, setAddMessageBundleModalOpen] =
|
|
|
|
useState(false);
|
2021-06-16 11:38:36 +00:00
|
|
|
|
|
|
|
const [supportedLocalesOpen, setSupportedLocalesOpen] = useState(false);
|
|
|
|
const [defaultLocaleOpen, setDefaultLocaleOpen] = useState(false);
|
2021-08-17 12:50:31 +00:00
|
|
|
const [filterDropdownOpen, setFilterDropdownOpen] = useState(false);
|
2021-08-19 13:56:00 +00:00
|
|
|
const [selectMenuLocale, setSelectMenuLocale] = useState(DEFAULT_LOCALE);
|
2021-06-16 11:38:36 +00:00
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
const { setValue, getValues, control, handleSubmit, formState } = useForm({
|
|
|
|
shouldUnregister: false,
|
|
|
|
});
|
2021-08-17 12:50:31 +00:00
|
|
|
const [selectMenuValueSelected, setSelectMenuValueSelected] = useState(false);
|
2021-12-21 06:34:44 +00:00
|
|
|
const [messageBundles, setMessageBundles] = useState<[string, string][]>([]);
|
|
|
|
const [tableRows, setTableRows] = useState<IRow[]>([]);
|
2021-08-17 12:50:31 +00:00
|
|
|
|
2021-06-16 11:38:36 +00:00
|
|
|
const themeTypes = useServerInfo().themes!;
|
2021-07-01 06:48:30 +00:00
|
|
|
const bundleForm = useForm<BundleForm>({ mode: "onChange" });
|
2021-07-28 12:01:42 +00:00
|
|
|
const { addAlert, addError } = useAlerts();
|
2021-07-01 16:44:36 +00:00
|
|
|
const { realm: currentRealm } = useRealm();
|
2021-12-21 06:34:44 +00:00
|
|
|
const { whoAmI } = useWhoAmI();
|
2021-06-16 11:38:36 +00:00
|
|
|
|
2022-06-15 12:57:39 +00:00
|
|
|
const setupForm = () => {
|
|
|
|
convertToFormValues(realm, setValue);
|
|
|
|
if (realm.supportedLocales?.length === 0) {
|
|
|
|
setValue("supportedLocales", [DEFAULT_LOCALE]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(setupForm, []);
|
|
|
|
|
2021-09-02 20:14:43 +00:00
|
|
|
const watchSupportedLocales = useWatch<string[]>({
|
2021-06-16 11:38:36 +00:00
|
|
|
control,
|
|
|
|
name: "supportedLocales",
|
2022-03-16 13:58:25 +00:00
|
|
|
defaultValue: [DEFAULT_LOCALE],
|
2021-06-16 11:38:36 +00:00
|
|
|
});
|
|
|
|
const internationalizationEnabled = useWatch({
|
|
|
|
control,
|
|
|
|
name: "internationalizationEnabled",
|
2021-09-02 20:14:43 +00:00
|
|
|
defaultValue: false,
|
2021-06-16 11:38:36 +00:00
|
|
|
});
|
|
|
|
|
2021-12-21 06:34:44 +00:00
|
|
|
const [tableKey, setTableKey] = useState(0);
|
|
|
|
const [max, setMax] = useState(10);
|
|
|
|
const [first, setFirst] = useState(0);
|
|
|
|
const [filter, setFilter] = useState("");
|
|
|
|
|
|
|
|
const refreshTable = () => {
|
|
|
|
setTableKey(tableKey + 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
useFetch(
|
|
|
|
async () => {
|
2022-01-18 23:48:32 +00:00
|
|
|
let result = await adminClient.realms
|
|
|
|
.getRealmLocalizationTexts({
|
|
|
|
first,
|
|
|
|
max,
|
|
|
|
realm: realm.realm!,
|
|
|
|
selectedLocale:
|
|
|
|
selectMenuLocale ||
|
|
|
|
getValues("defaultLocale") ||
|
|
|
|
whoAmI.getLocale(),
|
|
|
|
})
|
|
|
|
// prevents server error in dev mode due to snowpack
|
|
|
|
.catch(() => []);
|
2021-08-17 12:50:31 +00:00
|
|
|
|
2021-12-21 06:34:44 +00:00
|
|
|
const searchInBundles = (idx: number) => {
|
|
|
|
return Object.entries(result).filter((i) => i[idx].includes(filter));
|
|
|
|
};
|
|
|
|
|
|
|
|
if (filter) {
|
|
|
|
const filtered = uniqWith(
|
|
|
|
searchInBundles(0).concat(searchInBundles(1)),
|
|
|
|
isEqual
|
|
|
|
);
|
|
|
|
|
|
|
|
result = Object.fromEntries(filtered);
|
|
|
|
}
|
|
|
|
|
|
|
|
return { result };
|
|
|
|
},
|
|
|
|
({ result }) => {
|
|
|
|
const bundles = Object.entries(result).slice(first, first + max + 1);
|
|
|
|
setMessageBundles(bundles);
|
|
|
|
|
|
|
|
const updatedRows = bundles.map<IRow>((messageBundle) => ({
|
|
|
|
rowEditBtnAriaLabel: () =>
|
|
|
|
t("rowEditBtnAriaLabel", {
|
|
|
|
messageBundle: messageBundle[1],
|
|
|
|
}),
|
|
|
|
rowSaveBtnAriaLabel: () =>
|
|
|
|
t("rowSaveBtnAriaLabel", {
|
|
|
|
messageBundle: messageBundle[1],
|
|
|
|
}),
|
|
|
|
rowCancelBtnAriaLabel: () =>
|
|
|
|
t("rowCancelBtnAriaLabel", {
|
|
|
|
messageBundle: messageBundle[1],
|
|
|
|
}),
|
|
|
|
cells: [
|
|
|
|
{
|
|
|
|
title: (
|
|
|
|
value: string,
|
|
|
|
rowIndex: number,
|
|
|
|
cellIndex: number,
|
|
|
|
props
|
|
|
|
) => (
|
|
|
|
<EditableTextCell
|
|
|
|
value={value}
|
|
|
|
rowIndex={rowIndex}
|
|
|
|
cellIndex={cellIndex}
|
|
|
|
props={props}
|
|
|
|
isDisabled
|
|
|
|
handleTextInputChange={handleTextInputChange}
|
|
|
|
inputAriaLabel={messageBundle[0]}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
props: {
|
|
|
|
value: messageBundle[0],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: (
|
|
|
|
value: string,
|
|
|
|
rowIndex: number,
|
|
|
|
cellIndex: number,
|
|
|
|
props: EditableTextCellProps
|
|
|
|
) => (
|
|
|
|
<EditableTextCell
|
|
|
|
value={value}
|
|
|
|
rowIndex={rowIndex}
|
|
|
|
cellIndex={cellIndex}
|
|
|
|
props={props}
|
|
|
|
handleTextInputChange={handleTextInputChange}
|
|
|
|
inputAriaLabel={messageBundle[1]}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
props: {
|
|
|
|
value: messageBundle[1],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
setTableRows(updatedRows);
|
|
|
|
|
|
|
|
return bundles;
|
|
|
|
},
|
|
|
|
[tableKey, filter, first, max]
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleTextInputChange = (
|
|
|
|
newValue: string,
|
|
|
|
evt: any,
|
|
|
|
rowIndex: number,
|
|
|
|
cellIndex: number
|
|
|
|
) => {
|
|
|
|
setTableRows((prev) => {
|
|
|
|
const newRows = cloneDeep(prev);
|
2022-07-09 10:22:09 +00:00
|
|
|
const textCell = newRows[rowIndex]?.cells?.[
|
|
|
|
cellIndex
|
|
|
|
] as IEditableTextCell;
|
|
|
|
textCell.props.editableValue = newValue;
|
2021-12-21 06:34:44 +00:00
|
|
|
return newRows;
|
|
|
|
});
|
2021-08-17 12:50:31 +00:00
|
|
|
};
|
|
|
|
|
2021-12-21 06:34:44 +00:00
|
|
|
const updateEditableRows = async (
|
|
|
|
type: RowEditType,
|
|
|
|
rowIndex?: number,
|
|
|
|
validationErrors?: RowErrors
|
|
|
|
) => {
|
|
|
|
if (rowIndex === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const newRows = cloneDeep(tableRows);
|
|
|
|
let newRow: IRow;
|
|
|
|
const invalid =
|
|
|
|
!!validationErrors && Object.keys(validationErrors).length > 0;
|
2021-08-17 12:50:31 +00:00
|
|
|
|
2021-12-21 06:34:44 +00:00
|
|
|
if (invalid) {
|
|
|
|
newRow = validateCellEdits(newRows[rowIndex], type, validationErrors);
|
|
|
|
} else if (type === RowEditAction.Cancel) {
|
|
|
|
newRow = cancelCellEdits(newRows[rowIndex]);
|
|
|
|
} else {
|
|
|
|
newRow = applyCellEdits(newRows[rowIndex], type);
|
2021-06-16 11:38:36 +00:00
|
|
|
}
|
2021-12-21 06:34:44 +00:00
|
|
|
newRows[rowIndex] = newRow;
|
|
|
|
|
|
|
|
// Update the copy of the retrieved data set so we can save it when the user saves changes
|
|
|
|
|
|
|
|
if (!invalid && type === RowEditAction.Save) {
|
|
|
|
const key = (newRow.cells?.[0] as IRowCell).props.value;
|
|
|
|
const value = (newRow.cells?.[1] as IRowCell).props.value;
|
|
|
|
|
|
|
|
// We only have one editable value, otherwise we'd need to save each
|
|
|
|
try {
|
|
|
|
await adminClient.realms.addLocalization(
|
|
|
|
{
|
|
|
|
realm: realm.realm!,
|
|
|
|
selectedLocale:
|
|
|
|
selectMenuLocale || getValues("defaultLocale") || DEFAULT_LOCALE,
|
|
|
|
key,
|
|
|
|
},
|
|
|
|
value
|
|
|
|
);
|
|
|
|
addAlert(t("updateMessageBundleSuccess"), AlertVariant.success);
|
|
|
|
} catch (error) {
|
|
|
|
addAlert(t("updateMessageBundleError"), AlertVariant.danger);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setTableRows(newRows);
|
2021-06-16 11:38:36 +00:00
|
|
|
};
|
|
|
|
|
2021-07-01 06:48:30 +00:00
|
|
|
const handleModalToggle = () => {
|
|
|
|
setAddMessageBundleModalOpen(!addMessageBundleModalOpen);
|
|
|
|
};
|
|
|
|
|
2021-08-17 12:50:31 +00:00
|
|
|
const options = [
|
|
|
|
<SelectGroup label={t("defaultLocale")} key="group1">
|
2022-03-16 13:58:25 +00:00
|
|
|
<SelectOption key={DEFAULT_LOCALE} value={DEFAULT_LOCALE}>
|
2022-07-27 16:10:28 +00:00
|
|
|
{localeToDisplayName(DEFAULT_LOCALE)}
|
2022-03-16 13:58:25 +00:00
|
|
|
</SelectOption>
|
2021-08-17 12:50:31 +00:00
|
|
|
</SelectGroup>,
|
|
|
|
<Divider key="divider" />,
|
|
|
|
<SelectGroup label={t("supportedLocales")} key="group2">
|
2022-08-08 10:17:46 +00:00
|
|
|
{watchSupportedLocales.map((locale) => (
|
|
|
|
<SelectOption key={locale} value={locale}>
|
|
|
|
{localeToDisplayName(locale)}
|
|
|
|
</SelectOption>
|
|
|
|
))}
|
2021-08-17 12:50:31 +00:00
|
|
|
</SelectGroup>,
|
|
|
|
];
|
|
|
|
|
2021-07-01 06:48:30 +00:00
|
|
|
const addKeyValue = async (pair: KeyValueType): Promise<void> => {
|
|
|
|
try {
|
|
|
|
await adminClient.realms.addLocalization(
|
|
|
|
{
|
2021-07-01 16:44:36 +00:00
|
|
|
realm: currentRealm!,
|
2021-08-17 12:50:31 +00:00
|
|
|
selectedLocale:
|
2021-08-19 13:56:00 +00:00
|
|
|
selectMenuLocale || getValues("defaultLocale") || DEFAULT_LOCALE,
|
2021-07-01 06:48:30 +00:00
|
|
|
key: pair.key,
|
|
|
|
},
|
|
|
|
pair.value
|
|
|
|
);
|
|
|
|
|
|
|
|
adminClient.setConfig({
|
2021-07-01 16:44:36 +00:00
|
|
|
realmName: currentRealm!,
|
2021-07-01 06:48:30 +00:00
|
|
|
});
|
2021-08-17 12:50:31 +00:00
|
|
|
refreshTable();
|
2021-12-21 06:34:44 +00:00
|
|
|
addAlert(t("addMessageBundleSuccess"), AlertVariant.success);
|
2021-07-01 06:48:30 +00:00
|
|
|
} catch (error) {
|
2021-12-21 06:34:44 +00:00
|
|
|
addError(t("addMessageBundleError"), error);
|
2021-07-01 06:48:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-16 11:38:36 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-07-01 06:48:30 +00:00
|
|
|
{addMessageBundleModalOpen && (
|
|
|
|
<AddMessageBundleModal
|
|
|
|
handleModalToggle={handleModalToggle}
|
|
|
|
save={(pair: any) => {
|
|
|
|
addKeyValue(pair);
|
|
|
|
handleModalToggle();
|
|
|
|
}}
|
|
|
|
form={bundleForm}
|
|
|
|
/>
|
|
|
|
)}
|
2021-06-16 11:38:36 +00:00
|
|
|
<PageSection variant="light">
|
2021-11-03 19:47:42 +00:00
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
role="manage-realm"
|
|
|
|
className="pf-u-mt-lg"
|
|
|
|
onSubmit={handleSubmit(save)}
|
2021-06-16 11:38:36 +00:00
|
|
|
>
|
2021-11-03 19:47:42 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("internationalization")}
|
|
|
|
fieldId="kc-internationalization"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="realm-settings-help:internationalization"
|
2021-12-14 14:56:36 +00:00
|
|
|
fieldLabelId="realm-settings:internationalization"
|
2021-06-16 11:38:36 +00:00
|
|
|
/>
|
2021-11-03 19:47:42 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<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}
|
2021-09-30 08:58:30 +00:00
|
|
|
/>
|
2021-11-03 19:47:42 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
{internationalizationEnabled && (
|
|
|
|
<>
|
|
|
|
<FormGroup
|
|
|
|
label={t("supportedLocales")}
|
|
|
|
fieldId="kc-l-supported-locales"
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="supportedLocales"
|
|
|
|
control={control}
|
|
|
|
defaultValue={[DEFAULT_LOCALE]}
|
|
|
|
render={({ onChange, value }) => (
|
2021-09-23 14:15:37 +00:00
|
|
|
<Select
|
|
|
|
toggleId="kc-l-supported-locales"
|
|
|
|
onToggle={(open) => {
|
|
|
|
setSupportedLocalesOpen(open);
|
|
|
|
}}
|
|
|
|
onSelect={(_, v) => {
|
|
|
|
const option = v as string;
|
2021-11-03 19:47:42 +00:00
|
|
|
if (value.includes(option)) {
|
2021-09-23 14:15:37 +00:00
|
|
|
onChange(
|
2022-08-08 10:17:46 +00:00
|
|
|
value.filter((item: string) => item !== option)
|
2021-09-23 14:15:37 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
onChange([...value, option]);
|
2021-06-16 11:38:36 +00:00
|
|
|
}
|
2021-09-23 14:15:37 +00:00
|
|
|
}}
|
|
|
|
onClear={() => {
|
2022-08-08 10:17:46 +00:00
|
|
|
onChange([]);
|
2021-09-23 14:15:37 +00:00
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.typeaheadMulti}
|
|
|
|
aria-label={t("supportedLocales")}
|
|
|
|
isOpen={supportedLocalesOpen}
|
2021-11-03 19:47:42 +00:00
|
|
|
placeholderText={t("selectLocales")}
|
2021-09-23 14:15:37 +00:00
|
|
|
>
|
2022-03-16 13:58:25 +00:00
|
|
|
{themeTypes.login![0].locales.map((locale) => (
|
|
|
|
<SelectOption
|
|
|
|
selected={value.includes(locale)}
|
|
|
|
key={locale}
|
|
|
|
value={locale}
|
|
|
|
>
|
2022-07-27 16:10:28 +00:00
|
|
|
{localeToDisplayName(locale)}
|
2022-03-16 13:58:25 +00:00
|
|
|
</SelectOption>
|
|
|
|
))}
|
2021-09-23 14:15:37 +00:00
|
|
|
</Select>
|
2021-11-03 19:47:42 +00:00
|
|
|
)}
|
2021-09-30 08:58:30 +00:00
|
|
|
/>
|
2021-11-03 19:47:42 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("defaultLocale")}
|
|
|
|
fieldId="kc-l-default-locale"
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="defaultLocale"
|
|
|
|
control={control}
|
|
|
|
defaultValue={DEFAULT_LOCALE}
|
|
|
|
render={({ onChange, value }) => (
|
2021-09-23 14:15:37 +00:00
|
|
|
<Select
|
|
|
|
toggleId="kc-default-locale"
|
|
|
|
onToggle={() => setDefaultLocaleOpen(!defaultLocaleOpen)}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setDefaultLocaleOpen(false);
|
|
|
|
}}
|
|
|
|
selections={
|
2021-11-03 19:47:42 +00:00
|
|
|
value
|
2022-07-27 16:10:28 +00:00
|
|
|
? localeToDisplayName(value)
|
2021-09-23 14:15:37 +00:00
|
|
|
: realm.defaultLocale !== ""
|
2022-07-27 16:10:28 +00:00
|
|
|
? localeToDisplayName(
|
|
|
|
realm.defaultLocale || DEFAULT_LOCALE
|
2021-09-23 14:15:37 +00:00
|
|
|
)
|
|
|
|
: t("placeholderText")
|
|
|
|
}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
aria-label={t("defaultLocale")}
|
|
|
|
isOpen={defaultLocaleOpen}
|
|
|
|
placeholderText={t("placeholderText")}
|
|
|
|
data-testid="select-default-locale"
|
|
|
|
>
|
2022-03-16 13:58:25 +00:00
|
|
|
{watchSupportedLocales.map(
|
2021-09-23 14:15:37 +00:00
|
|
|
(locale: string, idx: number) => (
|
|
|
|
<SelectOption
|
|
|
|
key={`default-locale-${idx}`}
|
|
|
|
value={locale}
|
|
|
|
>
|
2022-07-27 16:10:28 +00:00
|
|
|
{localeToDisplayName(locale)}
|
2021-09-23 14:15:37 +00:00
|
|
|
</SelectOption>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</Select>
|
2021-11-03 19:47:42 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
<ActionGroup>
|
|
|
|
<Button
|
|
|
|
variant="primary"
|
|
|
|
isDisabled={!formState.isDirty}
|
|
|
|
type="submit"
|
|
|
|
data-testid="localization-tab-save"
|
|
|
|
>
|
|
|
|
{t("common:save")}
|
|
|
|
</Button>
|
2022-06-15 12:57:39 +00:00
|
|
|
<Button variant="link" onClick={setupForm}>
|
2021-11-03 19:47:42 +00:00
|
|
|
{t("common:revert")}
|
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
|
|
|
</FormAccess>
|
2021-06-16 11:38:36 +00:00
|
|
|
|
2021-06-10 20:00:14 +00:00
|
|
|
<FormPanel className="kc-message-bundles" title="Edit message bundles">
|
2021-06-16 11:38:36 +00:00
|
|
|
<TextContent className="messageBundleDescription">
|
|
|
|
{t("messageBundleDescription")}
|
|
|
|
</TextContent>
|
|
|
|
<div className="tableBorder">
|
2021-12-21 06:34:44 +00:00
|
|
|
<PaginatingTableToolbar
|
|
|
|
count={messageBundles.length}
|
|
|
|
first={first}
|
|
|
|
max={max}
|
|
|
|
onNextClick={setFirst}
|
|
|
|
onPreviousClick={setFirst}
|
|
|
|
onPerPageSelect={(first, max) => {
|
|
|
|
setFirst(first);
|
|
|
|
setMax(max);
|
|
|
|
}}
|
|
|
|
inputGroupName={"common:search"}
|
|
|
|
inputGroupOnEnter={(search) => {
|
|
|
|
setFilter(search);
|
|
|
|
setFirst(0);
|
|
|
|
setMax(10);
|
|
|
|
}}
|
|
|
|
inputGroupPlaceholder={t("searchForMessageBundle")}
|
|
|
|
toolbarItem={
|
|
|
|
<Button
|
|
|
|
data-testid="add-bundle-button"
|
|
|
|
onClick={() => setAddMessageBundleModalOpen(true)}
|
|
|
|
>
|
|
|
|
{t("addMessageBundle")}
|
|
|
|
</Button>
|
|
|
|
}
|
2021-08-17 12:50:31 +00:00
|
|
|
searchTypeComponent={
|
|
|
|
<ToolbarItem>
|
|
|
|
<Select
|
|
|
|
width={180}
|
|
|
|
data-testid="filter-by-locale-select"
|
|
|
|
isOpen={filterDropdownOpen}
|
|
|
|
className="kc-filter-by-locale-select"
|
|
|
|
variant={SelectVariant.single}
|
2022-05-17 07:51:12 +00:00
|
|
|
isDisabled={!internationalizationEnabled}
|
2021-08-17 12:50:31 +00:00
|
|
|
onToggle={(isExpanded) => setFilterDropdownOpen(isExpanded)}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
setSelectMenuLocale(value.toString());
|
|
|
|
setSelectMenuValueSelected(true);
|
|
|
|
refreshTable();
|
|
|
|
setFilterDropdownOpen(false);
|
|
|
|
}}
|
|
|
|
selections={
|
|
|
|
selectMenuValueSelected
|
2022-07-27 16:10:28 +00:00
|
|
|
? localeToDisplayName(selectMenuLocale)
|
2021-08-17 12:50:31 +00:00
|
|
|
: realm.defaultLocale !== ""
|
2022-07-27 16:10:28 +00:00
|
|
|
? localeToDisplayName(DEFAULT_LOCALE)
|
2021-08-17 12:50:31 +00:00
|
|
|
: t("placeholderText")
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{options}
|
|
|
|
</Select>
|
|
|
|
</ToolbarItem>
|
|
|
|
}
|
2021-12-21 06:34:44 +00:00
|
|
|
>
|
|
|
|
{messageBundles.length === 0 && !filter && (
|
2021-06-16 11:38:36 +00:00
|
|
|
<ListEmptyState
|
2021-12-21 06:34:44 +00:00
|
|
|
hasIcon
|
2021-06-16 11:38:36 +00:00
|
|
|
message={t("noMessageBundles")}
|
|
|
|
instructions={t("noMessageBundlesInstructions")}
|
2021-07-01 06:48:30 +00:00
|
|
|
onPrimaryAction={handleModalToggle}
|
2021-06-16 11:38:36 +00:00
|
|
|
/>
|
2021-12-21 06:34:44 +00:00
|
|
|
)}
|
|
|
|
{messageBundles.length === 0 && filter && (
|
|
|
|
<ListEmptyState
|
|
|
|
hasIcon
|
|
|
|
icon={SearchIcon}
|
|
|
|
isSearchVariant
|
|
|
|
message={t("common:noSearchResults")}
|
|
|
|
instructions={t("common:noSearchResultsInstructions")}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{messageBundles.length !== 0 && (
|
|
|
|
<Table
|
|
|
|
aria-label={t("editableRowsTable")}
|
|
|
|
data-testid="editable-rows-table"
|
|
|
|
variant={TableVariant.compact}
|
|
|
|
cells={[t("common:key"), t("common:value")]}
|
|
|
|
rows={tableRows}
|
2022-03-16 13:58:25 +00:00
|
|
|
onRowEdit={(_, type, _b, rowIndex, validation) =>
|
|
|
|
updateEditableRows(type, rowIndex, validation)
|
|
|
|
}
|
2021-12-21 06:34:44 +00:00
|
|
|
>
|
|
|
|
<TableHeader />
|
|
|
|
<TableBody />
|
|
|
|
</Table>
|
|
|
|
)}
|
|
|
|
</PaginatingTableToolbar>
|
2021-06-16 11:38:36 +00:00
|
|
|
</div>
|
|
|
|
</FormPanel>
|
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|