import { FormGroup, Select, SelectOption, SelectVariant, TextInput, } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; import React 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"; 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" > ) : 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 ? ( ) : ( )} ); };