import {
FormGroup,
Select,
SelectOption,
SelectVariant,
TextInput,
} from "@patternfly/react-core";
import { useTranslation } from "react-i18next";
import React, { useState } from "react";
import { HelpItem } from "../../components/help-enabler/HelpItem";
import { UseFormMethods, useWatch, Controller } from "react-hook-form";
import { FormAccess } from "../../components/form-access/FormAccess";
import _ from "lodash";
import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader";
export type SettingsCacheProps = {
form: UseFormMethods;
showSectionHeading?: boolean;
showSectionDescription?: boolean;
};
export const SettingsCache = ({
form,
showSectionHeading = false,
showSectionDescription = false,
}: SettingsCacheProps) => {
const { t } = useTranslation("user-federation");
const { t: helpText } = useTranslation("user-federation-help");
const [isCachePolicyDropdownOpen, setIsCachePolicyDropdownOpen] =
useState(false);
const [isEvictionHourDropdownOpen, setIsEvictionHourDropdownOpen] =
useState(false);
const cachePolicyType = useWatch({
control: form.control,
name: "config.cachePolicy",
});
const [isEvictionMinuteDropdownOpen, setIsEvictionMinuteDropdownOpen] =
useState(false);
const [isEvictionDayDropdownOpen, setIsEvictionDayDropdownOpen] =
useState(false);
const hourOptions = [
{[`0${0}`]}
,
];
let hourDisplay = "";
for (let index = 1; index < 24; index++) {
if (index < 10) {
hourDisplay = `0${index}`;
} else {
hourDisplay = `${index}`;
}
hourOptions.push(
{hourDisplay}
);
}
const minuteOptions = [
{[`0${0}`]}
,
];
let minuteDisplay = "";
for (let index = 1; index < 60; index++) {
if (index < 10) {
minuteDisplay = `0${index}`;
} else {
minuteDisplay = `${index}`;
}
minuteOptions.push(
{minuteDisplay}
);
}
return (
<>
{showSectionHeading && (
)}
}
fieldId="kc-cache-policy"
>
(
)}
>
{_.isEqual(cachePolicyType, ["EVICT_WEEKLY"]) ? (
}
isRequired
fieldId="kc-eviction-day"
>
(
)}
>
) : null}
{_.isEqual(cachePolicyType, ["EVICT_DAILY"]) ||
_.isEqual(cachePolicyType, ["EVICT_WEEKLY"]) ? (
<>
}
isRequired
fieldId="kc-eviction-hour"
>
(
)}
>
}
isRequired
fieldId="kc-eviction-minute"
>
(
)}
>
>
) : null}
{_.isEqual(cachePolicyType, ["MAX_LIFESPAN"]) ? (
}
fieldId="kc-max-lifespan"
>
) : null}
>
);
};