From f93d478f44298efa5e7e7ffd5ceb73f9ec49dcff Mon Sep 17 00:00:00 2001 From: Jenny <32821331+jenny-s51@users.noreply.github.com> Date: Tue, 17 Aug 2021 08:50:31 -0400 Subject: [PATCH] Realm settings(localization): add locale dropdown to table (#936) * add localization dropdown uncomment isDisabled clean up names comment out localization tab again disable actions menu if form not submitted uncomment tab use currentRealm for tableLoader fix axe issues labeled as serious PR feedback from Erik use isSearching instead of keepToolbar * fix node build * use object entries Co-authored-by: Jon Koops --- src/PageNav.tsx | 11 +- .../table-toolbar/KeycloakDataTable.tsx | 4 +- src/realm-settings/LocalizationTab.tsx | 102 +++++++++++++++--- src/realm-settings/RealmSettingsSection.tsx | 1 - 4 files changed, 97 insertions(+), 21 deletions(-) diff --git a/src/PageNav.tsx b/src/PageNav.tsx index 81ee7854b2..338c7da947 100644 --- a/src/PageNav.tsx +++ b/src/PageNav.tsx @@ -7,6 +7,7 @@ import { NavGroup, NavList, PageSidebar, + Divider, } from "@patternfly/react-core"; import { RealmSelector } from "./components/realm-selector/RealmSelector"; @@ -90,13 +91,9 @@ export const PageNav: React.FunctionComponent = () => { - {!isOnAddRealm && ( - - - - )} + {showManage && !isOnAddRealm && ( - + @@ -108,7 +105,7 @@ export const PageNav: React.FunctionComponent = () => { )} {showConfigure && !isOnAddRealm && ( - + diff --git a/src/components/table-toolbar/KeycloakDataTable.tsx b/src/components/table-toolbar/KeycloakDataTable.tsx index 2966ea0801..2de250bdbc 100644 --- a/src/components/table-toolbar/KeycloakDataTable.tsx +++ b/src/components/table-toolbar/KeycloakDataTable.tsx @@ -375,6 +375,7 @@ export function KeycloakDataTable({ {((data && data.length > 0) || search !== "" || isSearching || + emptyState || loading) && ( ({ {!loading && (!data || data.length === 0) && (search !== "" || !isSearching) && - searchPlaceholderKey && ( + searchPlaceholderKey && + !emptyState && ( { const { t } = useTranslation("realm-settings"); const adminClient = useAdminClient(); const [addMessageBundleModalOpen, setAddMessageBundleModalOpen] = useState(false); - const [key, setKey] = useState(0); const [supportedLocalesOpen, setSupportedLocalesOpen] = useState(false); const [defaultLocaleOpen, setDefaultLocaleOpen] = useState(false); + const [filterDropdownOpen, setFilterDropdownOpen] = useState(false); + const [selectMenuLocale, setSelectMenuLocale] = useState("en"); - const { getValues, control, handleSubmit } = useFormContext(); + const { getValues, control, handleSubmit, formState } = useFormContext(); const [valueSelected, setValueSelected] = useState(false); + const [selectMenuValueSelected, setSelectMenuValueSelected] = useState(false); + const themeTypes = useServerInfo().themes!; const bundleForm = useForm({ mode: "onChange" }); const { addAlert, addError } = useAlerts(); @@ -76,11 +81,25 @@ export const LocalizationTab = ({ try { const result = await adminClient.realms.getRealmLocalizationTexts({ realm: realm.realm!, - selectedLocale: getValues("defaultLocale") || "en", + selectedLocale: selectMenuLocale || getValues("defaultLocale") || "en", }); - return Object.keys(result).map((key) => [key, result[key]]); + + return Object.entries(result); } catch (error) { - return [[]]; + return []; + } + }; + + const tableLoader = async () => { + try { + const result = await adminClient.realms.getRealmLocalizationTexts({ + realm: currentRealm, + selectedLocale: selectMenuLocale, + }); + + return Object.entries(result); + } catch (error) { + return []; } }; @@ -88,6 +107,34 @@ export const LocalizationTab = ({ setAddMessageBundleModalOpen(!addMessageBundleModalOpen); }; + const options = [ + + {watchSupportedLocales + .filter((item) => item === realm?.defaultLocale) + .map((locale) => ( + + {t(`allSupportedLocales.${locale}`)} + + ))} + , + , + + {watchSupportedLocales + .filter((item) => item !== realm?.defaultLocale) + .map((locale) => ( + + {t(`allSupportedLocales.${locale}`)} + + ))} + , + ]; + + const [tableKey, setTableKey] = useState(0); + + const refreshTable = () => { + setTableKey(new Date().getTime()); + }; + const addKeyValue = async (pair: KeyValueType): Promise => { try { adminClient.setConfig({ @@ -96,7 +143,8 @@ export const LocalizationTab = ({ await adminClient.realms.addLocalization( { realm: currentRealm!, - selectedLocale: getValues("defaultLocale") || "en", + selectedLocale: + selectMenuLocale || getValues("defaultLocale") || "en", key: pair.key, }, pair.value @@ -105,7 +153,7 @@ export const LocalizationTab = ({ adminClient.setConfig({ realmName: currentRealm!, }); - refresh(); + refreshTable(); addAlert(t("pairCreatedSuccess"), AlertVariant.success); } catch (error) { addError("realm-settings:pairCreatedError", error); @@ -230,7 +278,6 @@ export const LocalizationTab = ({ onSelect={(_, value) => { onChange(value as string); setValueSelected(true); - setKey(new Date().getTime()); setDefaultLocaleOpen(false); }} selections={ @@ -269,6 +316,7 @@ export const LocalizationTab = ({