Added inherited option (#3957)
This commit is contained in:
parent
3d031c79e1
commit
bd3e276721
4 changed files with 38 additions and 14 deletions
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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<RealmRepresentation>();
|
||||
const { realm: realmName } = useRealm();
|
||||
const { adminClient } = useAdminClient();
|
||||
|
||||
useFetch(
|
||||
() => adminClient.realms.findOne({ realm: realmName }),
|
||||
setRealm,
|
||||
[]
|
||||
);
|
||||
|
||||
const { control, register } = useFormContext();
|
||||
return (
|
||||
<FormAccess
|
||||
|
@ -77,7 +90,7 @@ export const AdvancedSettings = ({
|
|||
name={convertAttributeNameToForm(
|
||||
"attributes.access.token.lifespan"
|
||||
)}
|
||||
defaultValue=""
|
||||
defaultValue={realm?.accessTokenLifespan}
|
||||
units={["minute", "day", "hour"]}
|
||||
/>
|
||||
|
||||
|
@ -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"]}
|
||||
/>
|
||||
|
||||
|
|
|
@ -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 = ({
|
|||
>
|
||||
<Controller
|
||||
name={name}
|
||||
defaultValue={defaultValue}
|
||||
defaultValue=""
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Split hasGutter>
|
||||
|
@ -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),
|
||||
]}
|
||||
>
|
||||
<SelectOption value="">{t(inherited)}</SelectOption>
|
||||
<SelectOption value={-1}>{t(never)}</SelectOption>
|
||||
<SelectOption value={60}>{t(expires)}</SelectOption>
|
||||
</Select>
|
||||
</SplitItem>
|
||||
<SplitItem>
|
||||
{isExpireSet(field.value) && (
|
||||
{field.value !== "-1" && field.value !== -1 && (
|
||||
<TimeSelector
|
||||
units={units}
|
||||
value={field.value}
|
||||
value={field.value === "" ? defaultValue : field.value}
|
||||
onChange={field.onChange}
|
||||
onFocus={onFocus}
|
||||
onBlur={onBlur}
|
||||
min={1}
|
||||
isDisabled={field.value === ""}
|
||||
/>
|
||||
)}
|
||||
</SplitItem>
|
||||
|
|
|
@ -129,6 +129,7 @@ export const TimeSelector = ({
|
|||
setOpen(!open);
|
||||
}}
|
||||
isOpen={open}
|
||||
isDisabled={rest.isDisabled}
|
||||
>
|
||||
{times.map((time) => (
|
||||
<SelectOption
|
||||
|
|
Loading…
Reference in a new issue