import { FormGroup, NumberInput, Select, SelectOption, SelectVariant, } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; import { HelpItem } from "../../components/help-enabler/HelpItem"; import { UseFormMethods, useWatch, Controller } from "react-hook-form"; import { FormAccess } from "../../components/form-access/FormAccess"; import { isEqual } from "lodash-es"; import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader"; import useToggle from "../../utils/useToggle"; export type SettingsCacheProps = { form: UseFormMethods; showSectionHeading?: boolean; showSectionDescription?: boolean; unWrap?: boolean; }; const CacheFields = ({ form }: { form: UseFormMethods }) => { const { t } = useTranslation("user-federation"); const [isCachePolicyOpen, toggleCachePolicy] = useToggle(); const [isEvictionHourOpen, toggleEvictionHour] = useToggle(); const [isEvictionMinuteOpen, toggleEvictionMinute] = useToggle(); const [isEvictionDayOpen, toggleEvictionDay] = useToggle(); const cachePolicyType = useWatch({ control: form.control, name: "config.cachePolicy", }); 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 ( <> } 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" > { const MIN_VALUE = 0; const setValue = (newValue: number) => onChange(Math.max(newValue, MIN_VALUE)); return ( onChange(Number(value) + 1)} onMinus={() => onChange(Number(value) - 1)} onChange={(event) => { const newValue = Number(event.currentTarget.value); setValue(!isNaN(newValue) ? newValue : 0); }} /> ); }} /> ) : 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 && ( )} {unWrap ? ( ) : ( )} ); };