@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
70 lines • 7.55 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { FormErrorText, HelpItem, KeycloakSelect, SelectControl, SelectVariant, useFetch, } from "../../ui-shared";
import { FormGroup, SelectOption, Switch, TextInput, ValidatedOptions, } from "@patternfly/react-core";
import { useState } from "react";
import { Controller, useFormContext, useWatch } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { useAdminClient } from "../../admin-client";
import useIsFeatureEnabled, { Feature } from "../../utils/useIsFeatureEnabled";
import { FormGroupField } from "../../identity-providers/component/FormGroupField";
import { SwitchField } from "../../identity-providers/component/SwitchField";
import { TextField } from "../../identity-providers/component/TextField";
const LoginFlow = ({ field, label, defaultValue, labelForEmpty = "none", }) => {
const { adminClient } = useAdminClient();
const { t } = useTranslation();
const { control } = useFormContext();
const [flows, setFlows] = useState();
const [open, setOpen] = useState(false);
useFetch(() => adminClient.authenticationManagement.getFlows(), (flows) => setFlows(flows.filter((flow) => flow.providerId === "basic-flow")), []);
return (_jsx(FormGroup, { label: t(label), labelIcon: _jsx(HelpItem, { helpText: t(`${label}Help`), fieldLabelId: label }), fieldId: label, children: _jsx(Controller, { name: field, defaultValue: defaultValue, control: control, render: ({ field }) => (_jsx(KeycloakSelect, { toggleId: label, onToggle: () => setOpen(!open), onSelect: (value) => {
field.onChange(value);
setOpen(false);
}, selections: field.value || t(labelForEmpty), variant: SelectVariant.single, "aria-label": t(label), isOpen: open, children: [
...(defaultValue === ""
? [
_jsx(SelectOption, { value: "", children: t(labelForEmpty) }, "empty"),
]
: []),
...((flows === null || flows === void 0 ? void 0 : flows.map((option) => (_jsx(SelectOption, { selected: option.alias === field.value, value: option.alias, children: option.alias }, option.id)))) || []),
] })) }) }));
};
const SYNC_MODES = ["IMPORT", "LEGACY", "FORCE"];
export const AdvancedSettings = ({ isOIDC, isSAML }) => {
var _a, _b, _c, _d;
const { t } = useTranslation();
const { control, register, setValue, formState: { errors }, } = useFormContext();
const filteredByClaim = useWatch({
control,
name: "config.filteredByClaim",
defaultValue: "false",
});
const claimFilterRequired = filteredByClaim === "true";
const isFeatureEnabled = useIsFeatureEnabled();
const isTransientUsersEnabled = isFeatureEnabled(Feature.TransientUsers);
const transientUsers = useWatch({
control,
name: "config.doNotStoreUsers",
defaultValue: "false",
});
const syncModeAvailable = transientUsers === "false";
return (_jsxs(_Fragment, { children: [!isOIDC && !isSAML && (_jsx(TextField, { field: "config.defaultScope", label: "scopes" })), _jsx(SwitchField, { field: "storeToken", label: "storeTokens", fieldType: "boolean" }), (isSAML || isOIDC) && (_jsx(SwitchField, { field: "addReadTokenRoleOnCreate", label: "storedTokensReadable", fieldType: "boolean" })), !isOIDC && !isSAML && (_jsxs(_Fragment, { children: [_jsx(SwitchField, { field: "config.acceptsPromptNoneForwardFromClient", label: "acceptsPromptNone" }), _jsx(SwitchField, { field: "config.disableUserInfo", label: "disableUserInfo" })] })), isOIDC && (_jsx(SwitchField, { field: "config.isAccessTokenJWT", label: "isAccessTokenJWT" })), _jsx(SwitchField, { field: "trustEmail", label: "trustEmail", fieldType: "boolean" }), _jsx(SwitchField, { field: "linkOnly", label: "accountLinkingOnly", fieldType: "boolean" }), _jsx(SwitchField, { field: "hideOnLogin", label: "hideOnLoginPage", fieldType: "boolean" }), (!isSAML || isOIDC) && (_jsx(FormGroupField, { label: "filteredByClaim", children: _jsx(Controller, { name: "config.filteredByClaim", defaultValue: "false", control: control, render: ({ field }) => (_jsx(Switch, { id: "filteredByClaim", label: t("on"), labelOff: t("off"), isChecked: field.value === "true", onChange: (_event, value) => {
field.onChange(value.toString());
} })) }) })), (!isSAML || isOIDC) && claimFilterRequired && (_jsxs(_Fragment, { children: [_jsxs(FormGroup, { label: t("claimFilterName"), labelIcon: _jsx(HelpItem, { helpText: t("claimFilterNameHelp"), fieldLabelId: "claimFilterName" }), fieldId: "kc-claim-filter-name", isRequired: true, children: [_jsx(TextInput, { isRequired: true, id: "kc-claim-filter-name", "data-testid": "claimFilterName", validated: ((_a = errors.config) === null || _a === void 0 ? void 0 : _a.claimFilterName)
? ValidatedOptions.error
: ValidatedOptions.default, ...register("config.claimFilterName", { required: true }) }), ((_b = errors.config) === null || _b === void 0 ? void 0 : _b.claimFilterName) && (_jsx(FormErrorText, { message: t("required") }))] }), _jsxs(FormGroup, { label: t("claimFilterValue"), labelIcon: _jsx(HelpItem, { helpText: t("claimFilterValueHelp"), fieldLabelId: "claimFilterName" }), fieldId: "kc-claim-filter-value", isRequired: true, children: [_jsx(TextInput, { isRequired: true, id: "kc-claim-filter-value", "data-testid": "claimFilterValue", validated: ((_c = errors.config) === null || _c === void 0 ? void 0 : _c.claimFilterValue)
? ValidatedOptions.error
: ValidatedOptions.default, ...register("config.claimFilterValue", { required: true }) }), ((_d = errors.config) === null || _d === void 0 ? void 0 : _d.claimFilterValue) && (_jsx(FormErrorText, { message: t("required") }))] })] })), _jsx(LoginFlow, { field: "firstBrokerLoginFlowAlias", label: "firstBrokerLoginFlowAliasOverride", defaultValue: "", labelForEmpty: "" }), _jsx(LoginFlow, { field: "postBrokerLoginFlowAlias", label: "postBrokerLoginFlowAlias", defaultValue: "" }), isTransientUsersEnabled && (_jsx(FormGroupField, { label: "doNotStoreUsers", children: _jsx(Controller, { name: "config.doNotStoreUsers", defaultValue: "false", control: control, render: ({ field }) => (_jsx(Switch, { id: "doNotStoreUsers", label: t("on"), labelOff: t("off"), isChecked: field.value === "true", onChange: (_event, value) => {
field.onChange(value.toString());
// if field is checked, set sync mode to import
if (value) {
setValue("config.syncMode", "IMPORT");
}
} })) }) })), syncModeAvailable && (_jsx(SelectControl, { name: "config.syncMode", label: t("syncMode"), labelIcon: t("syncModeHelp"), options: SYNC_MODES.map((syncMode) => ({
key: syncMode,
value: t(`syncModes.${syncMode.toLocaleLowerCase()}`),
})), controller: {
defaultValue: SYNC_MODES[0],
rules: { required: t("required") },
} })), _jsx(SwitchField, { field: "config.caseSensitiveOriginalUsername", label: "caseSensitiveOriginalUsername" })] }));
};
//# sourceMappingURL=AdvancedSettings.js.map