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}}",
|
"importError": "Could not import certificate {{error}}",
|
||||||
"importParseError": "Could not parse the file {{error}}",
|
"importParseError": "Could not parse the file {{error}}",
|
||||||
"tokenLifespan": {
|
"tokenLifespan": {
|
||||||
|
"inherited": "Inherits from realm settings",
|
||||||
"expires": "Expires in",
|
"expires": "Expires in",
|
||||||
"never": "Never expires"
|
"never": "Never expires"
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
SelectVariant,
|
SelectVariant,
|
||||||
Switch,
|
Switch,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
|
import RealmRepresentation from "libs/keycloak-admin-client/lib/defs/realmRepresentation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Controller, useFormContext } from "react-hook-form-v7";
|
import { Controller, useFormContext } from "react-hook-form-v7";
|
||||||
import { useTranslation } from "react-i18next";
|
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 { KeyValueInput } from "../../components/key-value-form/hook-form-v7/KeyValueInput";
|
||||||
import { MultiLineInput } from "../../components/multi-line-input/hook-form-v7/MultiLineInput";
|
import { MultiLineInput } from "../../components/multi-line-input/hook-form-v7/MultiLineInput";
|
||||||
import { TimeSelector } from "../../components/time-selector/TimeSelector";
|
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 { convertAttributeNameToForm } from "../../util";
|
||||||
import { FormFields } from "../ClientDetails";
|
import { FormFields } from "../ClientDetails";
|
||||||
import { TokenLifespan } from "./TokenLifespan";
|
import { TokenLifespan } from "./TokenLifespan";
|
||||||
|
@ -36,6 +39,16 @@ export const AdvancedSettings = ({
|
||||||
const { t } = useTranslation("clients");
|
const { t } = useTranslation("clients");
|
||||||
const [open, setOpen] = useState(false);
|
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();
|
const { control, register } = useFormContext();
|
||||||
return (
|
return (
|
||||||
<FormAccess
|
<FormAccess
|
||||||
|
@ -77,7 +90,7 @@ export const AdvancedSettings = ({
|
||||||
name={convertAttributeNameToForm(
|
name={convertAttributeNameToForm(
|
||||||
"attributes.access.token.lifespan"
|
"attributes.access.token.lifespan"
|
||||||
)}
|
)}
|
||||||
defaultValue=""
|
defaultValue={realm?.accessTokenLifespan}
|
||||||
units={["minute", "day", "hour"]}
|
units={["minute", "day", "hour"]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -86,7 +99,7 @@ export const AdvancedSettings = ({
|
||||||
name={convertAttributeNameToForm(
|
name={convertAttributeNameToForm(
|
||||||
"attributes.client.session.idle.timeout"
|
"attributes.client.session.idle.timeout"
|
||||||
)}
|
)}
|
||||||
defaultValue=""
|
defaultValue={realm?.clientSessionIdleTimeout}
|
||||||
units={["minute", "day", "hour"]}
|
units={["minute", "day", "hour"]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -95,7 +108,7 @@ export const AdvancedSettings = ({
|
||||||
name={convertAttributeNameToForm(
|
name={convertAttributeNameToForm(
|
||||||
"attributes.client.session.max.lifespan"
|
"attributes.client.session.max.lifespan"
|
||||||
)}
|
)}
|
||||||
defaultValue=""
|
defaultValue={realm?.clientSessionMaxLifespan}
|
||||||
units={["minute", "day", "hour"]}
|
units={["minute", "day", "hour"]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -104,7 +117,7 @@ export const AdvancedSettings = ({
|
||||||
name={convertAttributeNameToForm(
|
name={convertAttributeNameToForm(
|
||||||
"attributes.client.offline.session.idle.timeout"
|
"attributes.client.offline.session.idle.timeout"
|
||||||
)}
|
)}
|
||||||
defaultValue=""
|
defaultValue={realm?.offlineSessionIdleTimeout}
|
||||||
units={["minute", "day", "hour"]}
|
units={["minute", "day", "hour"]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -113,7 +126,7 @@ export const AdvancedSettings = ({
|
||||||
name={convertAttributeNameToForm(
|
name={convertAttributeNameToForm(
|
||||||
"attributes.client.offline.session.max.lifespan"
|
"attributes.client.offline.session.max.lifespan"
|
||||||
)}
|
)}
|
||||||
defaultValue=""
|
defaultValue={realm?.offlineSessionMaxLifespan}
|
||||||
units={["minute", "day", "hour"]}
|
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 {
|
import {
|
||||||
FormGroup,
|
FormGroup,
|
||||||
Select,
|
Select,
|
||||||
|
@ -9,20 +6,24 @@ import {
|
||||||
Split,
|
Split,
|
||||||
SplitItem,
|
SplitItem,
|
||||||
} from "@patternfly/react-core";
|
} 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 {
|
import {
|
||||||
TimeSelector,
|
TimeSelector,
|
||||||
Unit,
|
Unit,
|
||||||
} from "../../components/time-selector/TimeSelector";
|
} from "../../components/time-selector/TimeSelector";
|
||||||
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
|
||||||
|
|
||||||
type TokenLifespanProps = {
|
type TokenLifespanProps = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
defaultValue: string;
|
defaultValue?: number;
|
||||||
units?: Unit[];
|
units?: Unit[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const inherited = "tokenLifespan.inherited";
|
||||||
const never = "tokenLifespan.never";
|
const never = "tokenLifespan.never";
|
||||||
const expires = "tokenLifespan.expires";
|
const expires = "tokenLifespan.expires";
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ export const TokenLifespan = ({
|
||||||
>
|
>
|
||||||
<Controller
|
<Controller
|
||||||
name={name}
|
name={name}
|
||||||
defaultValue={defaultValue}
|
defaultValue=""
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<Split hasGutter>
|
<Split hasGutter>
|
||||||
|
@ -71,21 +72,29 @@ export const TokenLifespan = ({
|
||||||
field.onChange(value);
|
field.onChange(value);
|
||||||
setOpen(false);
|
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={-1}>{t(never)}</SelectOption>
|
||||||
<SelectOption value={60}>{t(expires)}</SelectOption>
|
<SelectOption value={60}>{t(expires)}</SelectOption>
|
||||||
</Select>
|
</Select>
|
||||||
</SplitItem>
|
</SplitItem>
|
||||||
<SplitItem>
|
<SplitItem>
|
||||||
{isExpireSet(field.value) && (
|
{field.value !== "-1" && field.value !== -1 && (
|
||||||
<TimeSelector
|
<TimeSelector
|
||||||
units={units}
|
units={units}
|
||||||
value={field.value}
|
value={field.value === "" ? defaultValue : field.value}
|
||||||
onChange={field.onChange}
|
onChange={field.onChange}
|
||||||
onFocus={onFocus}
|
onFocus={onFocus}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
min={1}
|
min={1}
|
||||||
|
isDisabled={field.value === ""}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</SplitItem>
|
</SplitItem>
|
||||||
|
|
|
@ -129,6 +129,7 @@ export const TimeSelector = ({
|
||||||
setOpen(!open);
|
setOpen(!open);
|
||||||
}}
|
}}
|
||||||
isOpen={open}
|
isOpen={open}
|
||||||
|
isDisabled={rest.isDisabled}
|
||||||
>
|
>
|
||||||
{times.map((time) => (
|
{times.map((time) => (
|
||||||
<SelectOption
|
<SelectOption
|
||||||
|
|
Loading…
Reference in a new issue