From d2bf69fac7f994d260c258651b07da374b54a830 Mon Sep 17 00:00:00 2001 From: Jenny <32821331+jenny-s51@users.noreply.github.com> Date: Wed, 16 Jun 2021 07:38:36 -0400 Subject: [PATCH] Localization tab (#685) * localization wip wip localization return key value data as array localization table css lint lint clean up log stmts clean up log stmts * PR feedback from Erik * fix logic for supported locales * update empty state text * set default value * fix cypress test * Update src/realm-settings/RealmSettingsSection.tsx Co-authored-by: Erik Jan de Wit * fix rsa-generated delete bug; PR feedback frog Erik * revert locale abbreviation * remove log stmts * PR feedback from Erik, fix undefined * fix loader w Erik Co-authored-by: Erik Jan de Wit --- public/index.css | 4 + src/realm-settings/LocalizationTab.tsx | 277 ++++++++++++++++++++ src/realm-settings/RSAGeneratedModal.tsx | 7 +- src/realm-settings/RealmSettingsSection.css | 12 + src/realm-settings/RealmSettingsSection.tsx | 44 ++-- src/realm-settings/ThemesTab.tsx | 14 +- src/realm-settings/messages.json | 9 +- 7 files changed, 333 insertions(+), 34 deletions(-) create mode 100644 src/realm-settings/LocalizationTab.tsx diff --git a/public/index.css b/public/index.css index eb44a2e12e..6a04ea7a48 100644 --- a/public/index.css +++ b/public/index.css @@ -54,3 +54,7 @@ td.pf-c-table__check > input { margin-top: var(--pf-c-table__check--input--MarginTop); vertical-align: baseline; } + +.pf-c-pagination.pf-m-bottom.pf-m-compact { + padding: 0px; +} diff --git a/src/realm-settings/LocalizationTab.tsx b/src/realm-settings/LocalizationTab.tsx new file mode 100644 index 0000000000..15dd89a548 --- /dev/null +++ b/src/realm-settings/LocalizationTab.tsx @@ -0,0 +1,277 @@ +import React, { useState } from "react"; +import { useTranslation } from "react-i18next"; +import { Controller, useFormContext, useWatch } from "react-hook-form"; +import { + ActionGroup, + Button, + FormGroup, + PageSection, + Select, + SelectOption, + SelectVariant, + Switch, + TextContent, +} from "@patternfly/react-core"; + +import type RealmRepresentation from "keycloak-admin/lib/defs/realmRepresentation"; +import { FormAccess } from "../components/form-access/FormAccess"; +import { useServerInfo } from "../context/server-info/ServerInfoProvider"; +import { FormPanel } from "../components/scroll-form/FormPanel"; +import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; +import { useAdminClient } from "../context/auth/AdminClient"; +import { getBaseUrl } from "../util"; +import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; + +type LocalizationTabProps = { + save: (realm: RealmRepresentation) => void; + reset: () => void; + refresh: () => void; + realm: RealmRepresentation; +}; + +export const LocalizationTab = ({ + save, + reset, + realm, +}: LocalizationTabProps) => { + const { t } = useTranslation("realm-settings"); + const adminClient = useAdminClient(); + const [key, setKey] = useState(0); + + const [supportedLocalesOpen, setSupportedLocalesOpen] = useState(false); + const [defaultLocaleOpen, setDefaultLocaleOpen] = useState(false); + + const { getValues, control, handleSubmit } = useFormContext(); + // const [selectedLocale, setSelectedLocale] = useState("en"); + const [valueSelected, setValueSelected] = useState(false); + const themeTypes = useServerInfo().themes!; + + const watchSupportedLocales = useWatch({ + control, + name: "supportedLocales", + defaultValue: themeTypes?.account![0].locales, + }); + + const internationalizationEnabled = useWatch({ + control, + name: "internationalizationEnabled", + defaultValue: realm?.internationalizationEnabled, + }); + + const loader = async () => { + if (realm) { + const response = await fetch( + `${getBaseUrl(adminClient)}admin/realms/${realm.realm}/localization/${ + getValues("defaultLocale") || "en" + }`, + { + method: "GET", + headers: { + Authorization: `bearer ${await adminClient.getAccessToken()}`, + }, + } + ); + + const result = await response.json(); + const resultTest = Object.keys(result).map((key) => [key, result[key]]); + return resultTest; + } + return [[]]; + }; + + return ( + <> + + + + + ( + + )} + /> + + {internationalizationEnabled && ( + <> + + ( + + )} + /> + + + ( + + )} + /> + + + )} + + + + + + + + + + {t("messageBundleDescription")} + +
+ {}} + /> + } + canSelectAll + columns={[ + { + name: "Key", + cellRenderer: (row) => row[0], + }, + { + name: "Value", + cellRenderer: (row) => row[1], + }, + ]} + /> +
+
+
+ + ); +}; diff --git a/src/realm-settings/RSAGeneratedModal.tsx b/src/realm-settings/RSAGeneratedModal.tsx index b1a65f3933..1f1f115c11 100644 --- a/src/realm-settings/RSAGeneratedModal.tsx +++ b/src/realm-settings/RSAGeneratedModal.tsx @@ -214,8 +214,9 @@ export const RSAGeneratedModal = ({ } > ( { setSupportedLocalesOpen(!supportedLocalesOpen); }} @@ -318,7 +320,7 @@ export const RealmSettingsThemesTab = ({ defaultValue="" render={({ onChange, value }) => (