From bd3e2767212a957641c289c180f6601783c8b7a5 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Thu, 8 Dec 2022 06:25:49 -0500 Subject: [PATCH] Added inherited option (#3957) --- .../admin-ui/public/resources/en/clients.json | 1 + .../src/clients/advanced/AdvancedSettings.tsx | 23 ++++++++++++---- .../src/clients/advanced/TokenLifespan.tsx | 27 ++++++++++++------- .../components/time-selector/TimeSelector.tsx | 1 + 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/apps/admin-ui/public/resources/en/clients.json b/apps/admin-ui/public/resources/en/clients.json index e37710964c..a9a70bd5c7 100644 --- a/apps/admin-ui/public/resources/en/clients.json +++ b/apps/admin-ui/public/resources/en/clients.json @@ -515,6 +515,7 @@ "importError": "Could not import certificate {{error}}", "importParseError": "Could not parse the file {{error}}", "tokenLifespan": { + "inherited": "Inherits from realm settings", "expires": "Expires in", "never": "Never expires" }, diff --git a/apps/admin-ui/src/clients/advanced/AdvancedSettings.tsx b/apps/admin-ui/src/clients/advanced/AdvancedSettings.tsx index 04692b9314..7808592077 100644 --- a/apps/admin-ui/src/clients/advanced/AdvancedSettings.tsx +++ b/apps/admin-ui/src/clients/advanced/AdvancedSettings.tsx @@ -7,6 +7,7 @@ import { SelectVariant, Switch, } from "@patternfly/react-core"; +import RealmRepresentation from "libs/keycloak-admin-client/lib/defs/realmRepresentation"; import { useState } from "react"; import { Controller, useFormContext } from "react-hook-form-v7"; import { useTranslation } from "react-i18next"; @@ -16,6 +17,8 @@ import { HelpItem } from "../../components/help-enabler/HelpItem"; import { KeyValueInput } from "../../components/key-value-form/hook-form-v7/KeyValueInput"; import { MultiLineInput } from "../../components/multi-line-input/hook-form-v7/MultiLineInput"; import { TimeSelector } from "../../components/time-selector/TimeSelector"; +import { useAdminClient, useFetch } from "../../context/auth/AdminClient"; +import { useRealm } from "../../context/realm-context/RealmContext"; import { convertAttributeNameToForm } from "../../util"; import { FormFields } from "../ClientDetails"; import { TokenLifespan } from "./TokenLifespan"; @@ -36,6 +39,16 @@ export const AdvancedSettings = ({ const { t } = useTranslation("clients"); const [open, setOpen] = useState(false); + const [realm, setRealm] = useState(); + const { realm: realmName } = useRealm(); + const { adminClient } = useAdminClient(); + + useFetch( + () => adminClient.realms.findOne({ realm: realmName }), + setRealm, + [] + ); + const { control, register } = useFormContext(); return ( @@ -86,7 +99,7 @@ export const AdvancedSettings = ({ name={convertAttributeNameToForm( "attributes.client.session.idle.timeout" )} - defaultValue="" + defaultValue={realm?.clientSessionIdleTimeout} units={["minute", "day", "hour"]} /> @@ -95,7 +108,7 @@ export const AdvancedSettings = ({ name={convertAttributeNameToForm( "attributes.client.session.max.lifespan" )} - defaultValue="" + defaultValue={realm?.clientSessionMaxLifespan} units={["minute", "day", "hour"]} /> @@ -104,7 +117,7 @@ export const AdvancedSettings = ({ name={convertAttributeNameToForm( "attributes.client.offline.session.idle.timeout" )} - defaultValue="" + defaultValue={realm?.offlineSessionIdleTimeout} units={["minute", "day", "hour"]} /> @@ -113,7 +126,7 @@ export const AdvancedSettings = ({ name={convertAttributeNameToForm( "attributes.client.offline.session.max.lifespan" )} - defaultValue="" + defaultValue={realm?.offlineSessionMaxLifespan} units={["minute", "day", "hour"]} /> diff --git a/apps/admin-ui/src/clients/advanced/TokenLifespan.tsx b/apps/admin-ui/src/clients/advanced/TokenLifespan.tsx index b0879782e2..e4866abab5 100644 --- a/apps/admin-ui/src/clients/advanced/TokenLifespan.tsx +++ b/apps/admin-ui/src/clients/advanced/TokenLifespan.tsx @@ -1,6 +1,3 @@ -import { useState } from "react"; -import { Controller, useFormContext } from "react-hook-form-v7"; -import { useTranslation } from "react-i18next"; import { FormGroup, Select, @@ -9,20 +6,24 @@ import { Split, SplitItem, } from "@patternfly/react-core"; +import { useState } from "react"; +import { Controller, useFormContext } from "react-hook-form-v7"; +import { useTranslation } from "react-i18next"; +import { HelpItem } from "../../components/help-enabler/HelpItem"; import { TimeSelector, Unit, } from "../../components/time-selector/TimeSelector"; -import { HelpItem } from "../../components/help-enabler/HelpItem"; type TokenLifespanProps = { id: string; name: string; - defaultValue: string; + defaultValue?: number; units?: Unit[]; }; +const inherited = "tokenLifespan.inherited"; const never = "tokenLifespan.never"; const expires = "tokenLifespan.expires"; @@ -58,7 +59,7 @@ export const TokenLifespan = ({ > ( @@ -71,21 +72,29 @@ export const TokenLifespan = ({ field.onChange(value); setOpen(false); }} - selections={[isExpireSet(field.value) ? t(expires) : t(never)]} + selections={[ + isExpireSet(field.value) + ? t(expires) + : field.value === "" + ? t(inherited) + : t(never), + ]} > + {t(inherited)} {t(never)} {t(expires)} - {isExpireSet(field.value) && ( + {field.value !== "-1" && field.value !== -1 && ( )} diff --git a/apps/admin-ui/src/components/time-selector/TimeSelector.tsx b/apps/admin-ui/src/components/time-selector/TimeSelector.tsx index 2b10eb77a7..45ed17fa13 100644 --- a/apps/admin-ui/src/components/time-selector/TimeSelector.tsx +++ b/apps/admin-ui/src/components/time-selector/TimeSelector.tsx @@ -129,6 +129,7 @@ export const TimeSelector = ({ setOpen(!open); }} isOpen={open} + isDisabled={rest.isDisabled} > {times.map((time) => (