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";
|
2021-01-26 01:41:14 +00:00
|
|
|
import React, { useState } 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";
|
2021-01-26 01:41:14 +00:00
|
|
|
import _ from "lodash";
|
2021-01-04 21:33:18 +00:00
|
|
|
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
|
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;
|
|
|
|
};
|
|
|
|
|
2021-02-11 20:51:51 +00:00
|
|
|
export const SettingsCache = ({
|
2021-01-26 01:41:14 +00:00
|
|
|
form,
|
2021-01-04 21:33:18 +00:00
|
|
|
showSectionHeading = false,
|
|
|
|
showSectionDescription = false,
|
2021-02-11 20:51:51 +00:00
|
|
|
}: SettingsCacheProps) => {
|
2020-10-30 20:15:37 +00:00
|
|
|
const { t } = useTranslation("user-federation");
|
|
|
|
const helpText = useTranslation("user-federation-help").t;
|
|
|
|
|
2020-11-25 14:50:40 +00:00
|
|
|
const [isCachePolicyDropdownOpen, setIsCachePolicyDropdownOpen] = useState(
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
const [isEvictionHourDropdownOpen, setIsEvictionHourDropdownOpen] = useState(
|
|
|
|
false
|
|
|
|
);
|
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",
|
|
|
|
});
|
|
|
|
|
2020-11-25 14:50:40 +00:00
|
|
|
const [
|
|
|
|
isEvictionMinuteDropdownOpen,
|
|
|
|
setIsEvictionMinuteDropdownOpen,
|
|
|
|
] = useState(false);
|
2020-11-25 16:17:50 +00:00
|
|
|
|
2020-11-25 14:50:40 +00:00
|
|
|
const [isEvictionDayDropdownOpen, setIsEvictionDayDropdownOpen] = useState(
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
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 (
|
|
|
|
<>
|
2021-01-04 21:33:18 +00:00
|
|
|
{showSectionHeading && (
|
|
|
|
<WizardSectionHeader
|
|
|
|
title={t("cacheSettings")}
|
2021-02-11 20:51:51 +00:00
|
|
|
description={helpText("cacheSettingsDescription")}
|
2021-01-04 21:33:18 +00:00
|
|
|
showDescription={showSectionDescription}
|
|
|
|
/>
|
|
|
|
)}
|
2020-11-25 16:17:50 +00:00
|
|
|
<FormAccess role="manage-realm" isHorizontal>
|
2020-10-30 20:15:37 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("cachePolicy")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("cachePolicyHelp")}
|
|
|
|
forLabel={t("cachePolicy")}
|
|
|
|
forID="kc-cache-policy"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-cache-policy"
|
|
|
|
>
|
2020-11-25 14:50:40 +00:00
|
|
|
<Controller
|
2020-12-16 07:02:41 +00:00
|
|
|
name="config.cachePolicy"
|
2021-01-26 01:41:14 +00:00
|
|
|
defaultValue={["DEFAULT"]}
|
|
|
|
control={form.control}
|
2020-11-25 14:50:40 +00:00
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="kc-cache-policy"
|
|
|
|
required
|
|
|
|
onToggle={() =>
|
|
|
|
setIsCachePolicyDropdownOpen(!isCachePolicyDropdownOpen)
|
|
|
|
}
|
|
|
|
isOpen={isCachePolicyDropdownOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setIsCachePolicyDropdownOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
2021-02-19 21:22:05 +00:00
|
|
|
data-testid="kerberos-cache-policy"
|
2020-11-25 14:50:40 +00:00
|
|
|
>
|
2021-01-26 01:41:14 +00:00
|
|
|
<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"]} />
|
2020-11-25 14:50:40 +00:00
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
></Controller>
|
2020-10-30 20:15:37 +00:00
|
|
|
</FormGroup>
|
2021-01-26 01:41:14 +00:00
|
|
|
{_.isEqual(cachePolicyType, ["EVICT_WEEKLY"]) ? (
|
|
|
|
<FormGroup
|
|
|
|
label={t("evictionDay")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("evictionDayHelp")}
|
|
|
|
forLabel={t("evictionDay")}
|
|
|
|
forID="kc-eviction-day"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
isRequired
|
|
|
|
fieldId="kc-eviction-day"
|
|
|
|
>
|
|
|
|
<Controller
|
2021-02-11 20:51:51 +00:00
|
|
|
name="config.evictionDay[0]"
|
|
|
|
defaultValue={"1"}
|
2021-01-26 01:41:14 +00:00
|
|
|
control={form.control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
2021-02-19 21:22:05 +00:00
|
|
|
data-testid="cache-day"
|
2021-01-26 01:41:14 +00:00
|
|
|
toggleId="kc-eviction-day"
|
|
|
|
required
|
|
|
|
onToggle={() =>
|
|
|
|
setIsEvictionDayDropdownOpen(!isEvictionDayDropdownOpen)
|
|
|
|
}
|
|
|
|
isOpen={isEvictionDayDropdownOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setIsEvictionDayDropdownOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
>
|
2021-02-11 20:51:51 +00:00
|
|
|
<SelectOption key={0} value="1" isPlaceholder>
|
2021-01-26 01:41:14 +00:00
|
|
|
{t("common:Sunday")}
|
|
|
|
</SelectOption>
|
2021-02-11 20:51:51 +00:00
|
|
|
<SelectOption key={1} value="2">
|
2021-01-26 01:41:14 +00:00
|
|
|
{t("common:Monday")}
|
|
|
|
</SelectOption>
|
2021-02-11 20:51:51 +00:00
|
|
|
<SelectOption key={2} value="3">
|
2021-01-26 01:41:14 +00:00
|
|
|
{t("common:Tuesday")}
|
|
|
|
</SelectOption>
|
2021-02-11 20:51:51 +00:00
|
|
|
<SelectOption key={3} value="4">
|
2021-01-26 01:41:14 +00:00
|
|
|
{t("common:Wednesday")}
|
|
|
|
</SelectOption>
|
2021-02-11 20:51:51 +00:00
|
|
|
<SelectOption key={4} value="5">
|
2021-01-26 01:41:14 +00:00
|
|
|
{t("common:Thursday")}
|
|
|
|
</SelectOption>
|
2021-02-11 20:51:51 +00:00
|
|
|
<SelectOption key={5} value="6">
|
2021-01-26 01:41:14 +00:00
|
|
|
{t("common:Friday")}
|
|
|
|
</SelectOption>
|
2021-02-11 20:51:51 +00:00
|
|
|
<SelectOption key={6} value="7">
|
2021-01-26 01:41:14 +00:00
|
|
|
{t("common:Saturday")}
|
|
|
|
</SelectOption>
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
></Controller>
|
|
|
|
</FormGroup>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
)}
|
|
|
|
{_.isEqual(cachePolicyType, ["EVICT_DAILY"]) ||
|
|
|
|
_.isEqual(cachePolicyType, ["EVICT_WEEKLY"]) ? (
|
|
|
|
<>
|
|
|
|
<FormGroup
|
|
|
|
label={t("evictionHour")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("evictionHourHelp")}
|
|
|
|
forLabel={t("evictionHour")}
|
|
|
|
forID="kc-eviction-hour"
|
2020-11-25 14:50:40 +00:00
|
|
|
/>
|
2021-01-26 01:41:14 +00:00
|
|
|
}
|
|
|
|
isRequired
|
|
|
|
fieldId="kc-eviction-hour"
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="config.evictionHour"
|
2021-02-11 20:51:51 +00:00
|
|
|
defaultValue={["0"]}
|
2021-01-26 01:41:14 +00:00
|
|
|
control={form.control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="kc-eviction-hour"
|
|
|
|
onToggle={() =>
|
|
|
|
setIsEvictionHourDropdownOpen(!isEvictionHourDropdownOpen)
|
|
|
|
}
|
|
|
|
isOpen={isEvictionHourDropdownOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setIsEvictionHourDropdownOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
>
|
|
|
|
{hourOptions}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
></Controller>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("evictionMinute")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("evictionMinuteHelp")}
|
|
|
|
forLabel={t("evictionMinute")}
|
|
|
|
forID="kc-eviction-minute"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
isRequired
|
|
|
|
fieldId="kc-eviction-minute"
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="config.evictionMinute"
|
2021-02-11 20:51:51 +00:00
|
|
|
defaultValue={["0"]}
|
2021-01-26 01:41:14 +00:00
|
|
|
control={form.control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="kc-eviction-minute"
|
|
|
|
onToggle={() =>
|
|
|
|
setIsEvictionMinuteDropdownOpen(
|
|
|
|
!isEvictionMinuteDropdownOpen
|
|
|
|
)
|
|
|
|
}
|
|
|
|
isOpen={isEvictionMinuteDropdownOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value as string);
|
|
|
|
setIsEvictionMinuteDropdownOpen(false);
|
|
|
|
}}
|
|
|
|
selections={value}
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
>
|
|
|
|
{minuteOptions}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
></Controller>
|
|
|
|
</FormGroup>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
)}
|
|
|
|
{_.isEqual(cachePolicyType, ["MAX_LIFESPAN"]) ? (
|
|
|
|
<FormGroup
|
|
|
|
label={t("maxLifespan")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText={helpText("maxLifespanHelp")}
|
|
|
|
forLabel={t("maxLifespan")}
|
|
|
|
forID="kc-max-lifespan"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-max-lifespan"
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-max-lifespan"
|
|
|
|
name="config.maxLifespan[0]"
|
|
|
|
ref={form.register}
|
2021-02-19 21:22:05 +00:00
|
|
|
data-testid="kerberos-cache-lifespan"
|
2020-11-25 14:50:40 +00:00
|
|
|
/>
|
2021-01-26 01:41:14 +00:00
|
|
|
</FormGroup>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
)}
|
2020-11-25 16:17:50 +00:00
|
|
|
</FormAccess>
|
2020-10-30 20:15:37 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|