import { FormGroup, Select, SelectOption, SelectVariant, TextInput, } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; import React, { useEffect, useState } from "react"; import { HelpItem } from "../../components/help-enabler/HelpItem"; import { useForm, Controller } from "react-hook-form"; import { convertToFormValues } from "../../util"; import ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation"; import { FormAccess } from "../../components/form-access/FormAccess"; import { useAdminClient } from "../../context/auth/AdminClient"; import { useParams } from "react-router-dom"; export const LdapSettingsCache = () => { const { t } = useTranslation("user-federation"); const helpText = useTranslation("user-federation-help").t; const adminClient = useAdminClient(); const { control, setValue, register } = useForm(); const { id } = useParams<{ id: string }>(); const convertToDays = (num: string) => { switch (num) { case "1": return t("common:Sunday"); case "2": return t("common:Monday"); case "3": return t("common:Tuesday"); case "4": return t("common:Wednesday"); case "5": return t("common:Thursday"); case "6": return t("common:Friday"); case "7": return t("common:Saturday"); default: return t("common:selectOne"); } }; const setupForm = (component: ComponentRepresentation) => { Object.entries(component).map((entry) => { if (entry[0] === "config") { convertToFormValues(entry[1], "config", setValue); if (entry[1].evictionDay) { setValue( "config.evictionDay", convertToDays(entry[1].evictionDay[0]) ); } } else { setValue(entry[0], entry[1]); } }); }; useEffect(() => { (async () => { const fetchedComponent = await adminClient.components.findOne({ id }); if (fetchedComponent) { setupForm(fetchedComponent); } })(); }, []); const [isCachePolicyDropdownOpen, setIsCachePolicyDropdownOpen] = useState( false ); const [isEvictionHourDropdownOpen, setIsEvictionHourDropdownOpen] = useState( false ); const [ isEvictionMinuteDropdownOpen, setIsEvictionMinuteDropdownOpen, ] = useState(false); const [isEvictionDayDropdownOpen, setIsEvictionDayDropdownOpen] = useState( false ); const hourOptions = [ , ]; for (let index = 1; index <= 24; index++) { hourOptions.push(); } const minuteOptions = [ , ]; for (let index = 1; index <= 60; index++) { minuteOptions.push(); } return ( <> {/* Cache settings */} } fieldId="kc-cache-policy" > ( )} > {/* TODO: Field shows only if cache policy is EVICT_WEEKLY */} } fieldId="kc-eviction-day" > ( )} > {/* TODO: Field shows only if cache policy is EVICT_WEEKLY or EVICT_DAILY */} {/* TODO: Investigate whether this should be a number field instead of a dropdown/text field */} } fieldId="kc-eviction-hour" > ( )} > {/* TODO: Field shows only if cache policy is EVICT_WEEKLY or EVICT_DAILY */} {/* TODO: Investigate whether this should be a number field instead of a dropdown/text field */} } fieldId="kc-eviction-minute" > ( )} > {/* TODO: Field shows only if cache policy is MAX_LIFESPAN */} } fieldId="kc-max-lifespan" > ); };