UNPKG

@keycloakify/keycloak-admin-ui

Version:
78 lines 6.91 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { HelpItem, KeycloakSelect, SelectControl, SelectVariant, } from "../../ui-shared"; import { FormGroup, NumberInput, SelectOption } from "@patternfly/react-core"; import { isEqual } from "lodash-es"; import { Controller, useWatch } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { FormAccess } from "../../components/form/FormAccess"; import { WizardSectionHeader } from "../../components/wizard-section-header/WizardSectionHeader"; import useToggle from "../../utils/useToggle"; const CacheFields = ({ form }) => { const { t } = useTranslation(); const [isCachePolicyOpen, toggleCachePolicy] = useToggle(); const [isEvictionHourOpen, toggleEvictionHour] = useToggle(); const [isEvictionMinuteOpen, toggleEvictionMinute] = useToggle(); const cachePolicyType = useWatch({ control: form.control, name: "config.cachePolicy", }); const hourOptions = [ _jsx(SelectOption, { value: [`0`], children: [`00`] }, 0), ]; let hourDisplay = ""; for (let index = 1; index < 24; index++) { if (index < 10) { hourDisplay = `0${index}`; } else { hourDisplay = `${index}`; } hourOptions.push(_jsx(SelectOption, { value: [`${index}`], children: hourDisplay }, index)); } const minuteOptions = [ _jsx(SelectOption, { value: [`0`], children: [`00`] }, 0), ]; let minuteDisplay = ""; for (let index = 1; index < 60; index++) { if (index < 10) { minuteDisplay = `0${index}`; } else { minuteDisplay = `${index}`; } minuteOptions.push(_jsx(SelectOption, { value: [`${index}`], children: minuteDisplay }, index)); } return (_jsxs(_Fragment, { children: [_jsx(FormGroup, { label: t("cachePolicy"), labelIcon: _jsx(HelpItem, { helpText: t("cachePolicyHelp"), fieldLabelId: "cachePolicy" }), fieldId: "kc-cache-policy", children: _jsx(Controller, { name: "config.cachePolicy", defaultValue: ["DEFAULT"], control: form.control, render: ({ field }) => (_jsxs(KeycloakSelect, { toggleId: "kc-cache-policy", onToggle: toggleCachePolicy, isOpen: isCachePolicyOpen, onSelect: (value) => { field.onChange(value); toggleCachePolicy(); }, selections: field.value, variant: SelectVariant.single, "data-testid": "kerberos-cache-policy", "aria-label": t("selectCachePolicy"), children: [_jsx(SelectOption, { value: ["DEFAULT"], children: "DEFAULT" }, 0), _jsx(SelectOption, { value: ["EVICT_DAILY"], children: "EVICT_DAILY" }, 1), _jsx(SelectOption, { value: ["EVICT_WEEKLY"], children: "EVICT_WEEKLY" }, 2), _jsx(SelectOption, { value: ["MAX_LIFESPAN"], children: "MAX_LIFESPAN" }, 3), _jsx(SelectOption, { value: ["NO_CACHE"], children: "NO_CACHE" }, 4)] })) }) }), isEqual(cachePolicyType, ["EVICT_WEEKLY"]) ? (_jsx(SelectControl, { id: "kc-eviction-day", name: "config.evictionDay[0]", label: t("evictionDay"), labelIcon: t("evictionDayHelp"), controller: { defaultValue: "1", }, "aria-label": t("selectEvictionDay"), options: [ { key: "1", value: t("Sunday") }, { key: "2", value: t("Monday") }, { key: "3", value: t("Tuesday") }, { key: "4", value: t("Wednesday") }, { key: "5", value: t("Thursday") }, { key: "6", value: t("Friday") }, { key: "7", value: t("Saturday") }, ] })) : null, isEqual(cachePolicyType, ["EVICT_DAILY"]) || isEqual(cachePolicyType, ["EVICT_WEEKLY"]) ? (_jsxs(_Fragment, { children: [_jsx(FormGroup, { label: t("evictionHour"), labelIcon: _jsx(HelpItem, { helpText: t("evictionHourHelp"), fieldLabelId: "evictionHour" }), isRequired: true, fieldId: "kc-eviction-hour", children: _jsx(Controller, { name: "config.evictionHour", defaultValue: ["0"], control: form.control, render: ({ field }) => (_jsx(KeycloakSelect, { toggleId: "kc-eviction-hour", onToggle: toggleEvictionHour, isOpen: isEvictionHourOpen, onSelect: (value) => { field.onChange(value); toggleEvictionHour(); }, selections: field.value, variant: SelectVariant.single, "aria-label": t("selectEvictionHour"), children: hourOptions })) }) }), _jsx(FormGroup, { label: t("evictionMinute"), labelIcon: _jsx(HelpItem, { helpText: t("evictionMinuteHelp"), fieldLabelId: "evictionMinute" }), isRequired: true, fieldId: "kc-eviction-minute", children: _jsx(Controller, { name: "config.evictionMinute", defaultValue: ["0"], control: form.control, render: ({ field }) => (_jsx(KeycloakSelect, { toggleId: "kc-eviction-minute", onToggle: toggleEvictionMinute, isOpen: isEvictionMinuteOpen, onSelect: (value) => { field.onChange(value); toggleEvictionMinute(); }, selections: field.value, variant: SelectVariant.single, "aria-label": t("selectEvictionMinute"), children: minuteOptions })) }) })] })) : null, isEqual(cachePolicyType, ["MAX_LIFESPAN"]) ? (_jsx(FormGroup, { label: t("maxLifespan"), labelIcon: _jsx(HelpItem, { helpText: t("maxLifespanHelp"), fieldLabelId: "maxLifespan" }), fieldId: "kc-max-lifespan", children: _jsx(Controller, { name: "config.maxLifespan[0]", defaultValue: 0, control: form.control, render: ({ field }) => { const MIN_VALUE = 0; const setValue = (newValue) => field.onChange(Math.max(newValue, MIN_VALUE)); return (_jsx(NumberInput, { id: "kc-max-lifespan", "data-testid": "kerberos-cache-lifespan", value: field.value, min: MIN_VALUE, unit: t("ms"), type: "text", onPlus: () => field.onChange(Number(field.value) + 1), onMinus: () => field.onChange(Number(field.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, }) => { const { t } = useTranslation(); return (_jsxs(_Fragment, { children: [showSectionHeading && (_jsx(WizardSectionHeader, { title: t("cacheSettings"), description: t("cacheSettingsDescription"), showDescription: showSectionDescription })), unWrap ? (_jsx(CacheFields, { form: form })) : (_jsx(FormAccess, { role: "manage-realm", isHorizontal: true, children: _jsx(CacheFields, { form: form }) }))] })); }; //# sourceMappingURL=SettingsCache.js.map