2020-11-25 14:50:40 +00:00
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
TextInput,
|
|
|
|
} from "@patternfly/react-core";
|
2020-10-30 20:15:37 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-01-05 17:06:53 +00:00
|
|
|
import React from "react";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
2021-01-26 01:41:14 +00:00
|
|
|
import { UseFormMethods, useWatch, Controller } from "react-hook-form";
|
2020-12-16 07:02:41 +00:00
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
2022-02-02 10:33:57 +00:00
|
|
|
import { isEqual } from "lodash-es";
|
2021-01-04 21:33:18 +00:00
|
|
|
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
|
2022-01-05 17:06:53 +00:00
|
|
|
import useToggle from "../../utils/useToggle";
|
2020-10-30 20:15:37 +00:00
|
|
|
|
2021-02-11 20:51:51 +00:00
|
|
|
export type SettingsCacheProps = {
|
2021-01-26 01:41:14 +00:00
|
|
|
form: UseFormMethods;
|
2021-01-04 21:33:18 +00:00
|
|
|
showSectionHeading?: boolean;
|
|
|
|
showSectionDescription?: boolean;
|
2022-01-05 17:06:53 +00:00
|
|
|
unWrap?: boolean;
|
2021-01-04 21:33:18 +00:00
|
|
|
};
|
|
|
|
|
2022-01-05 17:06:53 +00:00
|
|
|
const CacheFields = ({ form }: { form: UseFormMethods }) => {
|
2020-10-30 20:15:37 +00:00
|
|
|
const { t } = useTranslation("user-federation");
|
|
|
|
|
2022-01-05 17:06:53 +00:00
|
|
|
const [isCachePolicyOpen, toggleCachePolicy] = useToggle();
|
|
|
|
const [isEvictionHourOpen, toggleEvictionHour] = useToggle();
|
|
|
|
const [isEvictionMinuteOpen, toggleEvictionMinute] = useToggle();
|
2020-11-25 14:50:40 +00:00
|
|
|
|
2022-01-05 17:06:53 +00:00
|
|
|
const [isEvictionDayOpen, toggleEvictionDay] = useToggle();
|
2020-12-16 07:02:41 +00:00
|
|
|
|
2021-01-26 01:41:14 +00:00
|
|
|
const cachePolicyType = useWatch({
|
|
|
|
control: form.control,
|
|
|
|
name: "config.cachePolicy",
|
|
|
|
});
|
|
|
|
|
2021-02-11 20:51:51 +00:00
|
|
|
const hourOptions = [
|
|
|
|
<SelectOption key={0} value={[`${0}`]} isPlaceholder>
|
|
|
|
{[`0${0}`]}
|
|
|
|
</SelectOption>,
|
|
|
|
];
|
|
|
|
let hourDisplay = "";
|
|
|
|
for (let index = 1; index < 24; index++) {
|
|
|
|
if (index < 10) {
|
|
|
|
hourDisplay = `0${index}`;
|
|
|
|
} else {
|
|
|
|
hourDisplay = `${index}`;
|
|
|
|
}
|
|
|
|
hourOptions.push(
|
|
|
|
<SelectOption key={index} value={[`${index}`]}>
|
|
|
|
{hourDisplay}
|
|
|
|
</SelectOption>
|
|
|
|
);
|
2020-11-25 14:50:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const minuteOptions = [
|
2021-02-11 20:51:51 +00:00
|
|
|
<SelectOption key={0} value={[`${0}`]} isPlaceholder>
|
|
|
|
{[`0${0}`]}
|
|
|
|
</SelectOption>,
|
2020-11-25 14:50:40 +00:00
|
|
|
];
|
2021-02-11 20:51:51 +00:00
|
|
|
let minuteDisplay = "";
|
|
|
|
for (let index = 1; index < 60; index++) {
|
|
|
|
if (index < 10) {
|
|
|
|
minuteDisplay = `0${index}`;
|
|
|
|
} else {
|
|
|
|
minuteDisplay = `${index}`;
|
|
|
|
}
|
|
|
|
minuteOptions.push(
|
|
|
|
<SelectOption key={index} value={[`${index}`]}>
|
|
|
|
{minuteDisplay}
|
|
|
|
</SelectOption>
|
|
|
|
);
|
2020-11-25 14:50:40 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 20:15:37 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-01-05 17:06:53 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("cachePolicy")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="user-federation-help:cachePolicyHelp"
|
|
|
|
fieldLabelId="user-federation:cachePolicy"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-cache-policy"
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="config.cachePolicy"
|
|
|
|
defaultValue={["DEFAULT"]}
|
|
|
|
control={form.control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="kc-cache-policy"
|
|
|
|
required
|
|
|
|
onToggle={toggleCachePolicy}
|
|
|
|
isOpen={isCachePolicyOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
toggleCachePolicy();
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
data-testid="kerberos-cache-policy"
|
|
|
|
>
|
|
|
|
<SelectOption key={0} value={["DEFAULT"]} isPlaceholder />
|
|
|
|
<SelectOption key={1} value={["EVICT_DAILY"]} />
|
|
|
|
<SelectOption key={2} value={["EVICT_WEEKLY"]} />
|
|
|
|
<SelectOption key={3} value={["MAX_LIFESPAN"]} />
|
|
|
|
<SelectOption key={4} value={["NO_CACHE"]} />
|
|
|
|
</Select>
|
|
|
|
)}
|
2021-01-04 21:33:18 +00:00
|
|
|
/>
|
2022-01-05 17:06:53 +00:00
|
|
|
</FormGroup>
|
2022-02-02 10:33:57 +00:00
|
|
|
{isEqual(cachePolicyType, ["EVICT_WEEKLY"]) ? (
|
2020-10-30 20:15:37 +00:00
|
|
|
<FormGroup
|
2022-01-05 17:06:53 +00:00
|
|
|
label={t("evictionDay")}
|
2020-10-30 20:15:37 +00:00
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2022-01-05 17:06:53 +00:00
|
|
|
helpText="user-federation-help:evictionDayHelp"
|
|
|
|
fieldLabelId="user-federation:evictionDay"
|
2020-10-30 20:15:37 +00:00
|
|
|
/>
|
|
|
|
}
|
2022-01-05 17:06:53 +00:00
|
|
|
isRequired
|
|
|
|
fieldId="kc-eviction-day"
|
2020-10-30 20:15:37 +00:00
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2022-01-05 17:06:53 +00:00
|
|
|
name="config.evictionDay[0]"
|
|
|
|
defaultValue={"1"}
|
2021-01-26 01:41:14 +00:00
|
|
|
control={form.control}
|
2020-11-25 14:50:40 +00:00
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
2022-01-05 17:06:53 +00:00
|
|
|
data-testid="cache-day"
|
|
|
|
toggleId="kc-eviction-day"
|
2020-11-25 14:50:40 +00:00
|
|
|
required
|
2022-01-05 17:06:53 +00:00
|
|
|
onToggle={toggleEvictionDay}
|
|
|
|
isOpen={isEvictionDayOpen}
|
2020-11-25 14:50:40 +00:00
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
2022-01-05 17:06:53 +00:00
|
|
|
toggleEvictionDay();
|
2020-11-25 14:50:40 +00:00
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
>
|
2022-01-05 17:06:53 +00:00
|
|
|
<SelectOption key={0} value="1" isPlaceholder>
|
|
|
|
{t("common:Sunday")}
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption key={1} value="2">
|
|
|
|
{t("common:Monday")}
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption key={2} value="3">
|
|
|
|
{t("common:Tuesday")}
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption key={3} value="4">
|
|
|
|
{t("common:Wednesday")}
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption key={4} value="5">
|
|
|
|
{t("common:Thursday")}
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption key={5} value="6">
|
|
|
|
{t("common:Friday")}
|
|
|
|
</SelectOption>
|
|
|
|
<SelectOption key={6} value="7">
|
|
|
|
{t("common:Saturday")}
|
|
|
|
</SelectOption>
|
2020-11-25 14:50:40 +00:00
|
|
|
</Select>
|
|
|
|
)}
|
2022-01-05 17:06:53 +00:00
|
|
|
/>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
2022-01-05 17:06:53 +00:00
|
|
|
) : null}
|
2022-02-02 10:33:57 +00:00
|
|
|
{isEqual(cachePolicyType, ["EVICT_DAILY"]) ||
|
|
|
|
isEqual(cachePolicyType, ["EVICT_WEEKLY"]) ? (
|
2022-01-05 17:06:53 +00:00
|
|
|
<>
|
2021-01-26 01:41:14 +00:00
|
|
|
<FormGroup
|
2022-01-05 17:06:53 +00:00
|
|
|
label={t("evictionHour")}
|
2021-01-26 01:41:14 +00:00
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2022-01-05 17:06:53 +00:00
|
|
|
helpText="user-federation-help:evictionHourHelp"
|
|
|
|
fieldLabelId="user-federation:evictionHour"
|
2021-01-26 01:41:14 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
isRequired
|
2022-01-05 17:06:53 +00:00
|
|
|
fieldId="kc-eviction-hour"
|
2021-01-26 01:41:14 +00:00
|
|
|
>
|
|
|
|
<Controller
|
2022-01-05 17:06:53 +00:00
|
|
|
name="config.evictionHour"
|
|
|
|
defaultValue={["0"]}
|
2021-01-26 01:41:14 +00:00
|
|
|
control={form.control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
2022-01-05 17:06:53 +00:00
|
|
|
toggleId="kc-eviction-hour"
|
|
|
|
onToggle={toggleEvictionHour}
|
|
|
|
isOpen={isEvictionHourOpen}
|
2021-01-26 01:41:14 +00:00
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
2022-01-05 17:06:53 +00:00
|
|
|
toggleEvictionHour();
|
2021-01-26 01:41:14 +00:00
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
>
|
2022-01-05 17:06:53 +00:00
|
|
|
{hourOptions}
|
2021-01-26 01:41:14 +00:00
|
|
|
</Select>
|
|
|
|
)}
|
2022-01-05 17:06:53 +00:00
|
|
|
/>
|
2021-01-26 01:41:14 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
2022-01-05 17:06:53 +00:00
|
|
|
label={t("evictionMinute")}
|
2021-01-26 01:41:14 +00:00
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2022-01-05 17:06:53 +00:00
|
|
|
helpText="user-federation-help:evictionMinuteHelp"
|
|
|
|
fieldLabelId="user-federation:evictionMinute"
|
2021-01-26 01:41:14 +00:00
|
|
|
/>
|
|
|
|
}
|
2022-01-05 17:06:53 +00:00
|
|
|
isRequired
|
|
|
|
fieldId="kc-eviction-minute"
|
2021-01-26 01:41:14 +00:00
|
|
|
>
|
2022-01-05 17:06:53 +00:00
|
|
|
<Controller
|
|
|
|
name="config.evictionMinute"
|
|
|
|
defaultValue={["0"]}
|
|
|
|
control={form.control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="kc-eviction-minute"
|
|
|
|
onToggle={toggleEvictionMinute}
|
|
|
|
isOpen={isEvictionMinuteOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
toggleEvictionMinute();
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
>
|
|
|
|
{minuteOptions}
|
|
|
|
</Select>
|
|
|
|
)}
|
2020-11-25 14:50:40 +00:00
|
|
|
/>
|
2021-01-26 01:41:14 +00:00
|
|
|
</FormGroup>
|
2022-01-05 17:06:53 +00:00
|
|
|
</>
|
|
|
|
) : null}
|
2022-02-02 10:33:57 +00:00
|
|
|
{isEqual(cachePolicyType, ["MAX_LIFESPAN"]) ? (
|
2022-01-05 17:06:53 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("maxLifespan")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="user-federation-help:maxLifespanHelp"
|
|
|
|
fieldLabelId="user-federation:maxLifespan"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-max-lifespan"
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-max-lifespan"
|
|
|
|
name="config.maxLifespan[0]"
|
|
|
|
ref={form.register}
|
|
|
|
data-testid="kerberos-cache-lifespan"
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const SettingsCache = ({
|
|
|
|
form,
|
|
|
|
showSectionHeading = false,
|
|
|
|
showSectionDescription = false,
|
|
|
|
unWrap = false,
|
|
|
|
}: SettingsCacheProps) => {
|
|
|
|
const { t } = useTranslation("user-federation");
|
|
|
|
const { t: helpText } = useTranslation("user-federation-help");
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{showSectionHeading && (
|
|
|
|
<WizardSectionHeader
|
|
|
|
title={t("cacheSettings")}
|
|
|
|
description={helpText("cacheSettingsDescription")}
|
|
|
|
showDescription={showSectionDescription}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{unWrap ? (
|
|
|
|
<CacheFields form={form} />
|
|
|
|
) : (
|
|
|
|
<FormAccess role="manage-realm" isHorizontal>
|
|
|
|
<CacheFields form={form} />
|
|
|
|
</FormAccess>
|
|
|
|
)}
|
2020-10-30 20:15:37 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|