@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
79 lines • 7 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { UnmanagedAttributePolicy, } from "@keycloak/keycloak-admin-client/lib/defs/userProfileMetadata";
import { FormErrorText, HelpItem, KeycloakSpinner, SelectControl, TextControl, useEnvironment, useFetch, } from "../ui-shared";
import { ClipboardCopy, FormGroup, PageSection, Stack, StackItem, } from "@patternfly/react-core";
import { useEffect, useState } from "react";
import { Controller, FormProvider, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { useAdminClient } from "../admin-client";
import { DefaultSwitchControl } from "../components/SwitchControl";
import { FormattedLink } from "../components/external-link/FormattedLink";
import { FixedButtonsGroup } from "../components/form/FixedButtonGroup";
import { FormAccess } from "../components/form/FormAccess";
import { KeyValueInput } from "../components/key-value-form/KeyValueInput";
import { useRealm } from "../context/realm-context/RealmContext";
import { addTrailingSlash, convertAttributeNameToForm, convertToFormValues, } from "../util";
import useIsFeatureEnabled, { Feature } from "../utils/useIsFeatureEnabled";
export const RealmSettingsGeneralTab = ({ realm, save, }) => {
const { adminClient } = useAdminClient();
const { realm: realmName } = useRealm();
const [userProfileConfig, setUserProfileConfig] = useState();
useFetch(() => adminClient.users.getProfile({ realm: realmName }), (config) => setUserProfileConfig(config), []);
if (!userProfileConfig) {
return _jsx(KeycloakSpinner, {});
}
return (_jsx(RealmSettingsGeneralTabForm, { realm: realm, save: save, userProfileConfig: userProfileConfig }));
};
const REQUIRE_SSL_TYPES = ["all", "external", "none"];
const UNMANAGED_ATTRIBUTE_POLICIES = [
UnmanagedAttributePolicy.Disabled,
UnmanagedAttributePolicy.Enabled,
UnmanagedAttributePolicy.AdminView,
UnmanagedAttributePolicy.AdminEdit,
];
function RealmSettingsGeneralTabForm({ realm, save, userProfileConfig, }) {
const { environment: { serverBaseUrl }, } = useEnvironment();
const { t } = useTranslation();
const { realm: realmName } = useRealm();
const form = useForm();
const { control, handleSubmit, setValue, formState: { errors }, } = form;
const isFeatureEnabled = useIsFeatureEnabled();
const isOrganizationsEnabled = isFeatureEnabled(Feature.Organizations);
const isOpenid4vciEnabled = isFeatureEnabled(Feature.OpenId4VCI);
const setupForm = () => {
var _a;
convertToFormValues(realm, setValue);
setValue("unmanagedAttributePolicy", userProfileConfig.unmanagedAttributePolicy ||
UNMANAGED_ATTRIBUTE_POLICIES[0]);
if ((_a = realm.attributes) === null || _a === void 0 ? void 0 : _a["acr.loa.map"]) {
const result = Object.entries(JSON.parse(realm.attributes["acr.loa.map"])).flatMap(([key, value]) => ({ key, value }));
result.concat({ key: "", value: "" });
setValue(convertAttributeNameToForm("attributes.acr.loa.map"), result);
}
};
useEffect(setupForm, []);
const onSubmit = handleSubmit(async ({ unmanagedAttributePolicy, ...data }) => {
const upConfig = { ...userProfileConfig };
if (unmanagedAttributePolicy === UnmanagedAttributePolicy.Disabled) {
delete upConfig.unmanagedAttributePolicy;
}
else {
upConfig.unmanagedAttributePolicy = unmanagedAttributePolicy;
}
await save({ ...data, upConfig });
});
return (_jsx(PageSection, { variant: "light", children: _jsx(FormProvider, { ...form, children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-realm", className: "pf-u-mt-lg", onSubmit: onSubmit, children: [_jsxs(FormGroup, { label: t("realmName"), fieldId: "kc-realm-id", isRequired: true, children: [_jsx(Controller, { name: "realm", control: control, rules: {
required: { value: true, message: t("required") },
}, defaultValue: "", render: ({ field }) => (_jsx(ClipboardCopy, { "data-testid": "realmName", onChange: field.onChange, children: field.value })) }), errors.realm && (_jsx(FormErrorText, { "data-testid": "realm-id-error", message: errors.realm.message }))] }), _jsx(TextControl, { name: "displayName", label: t("displayName") }), _jsx(TextControl, { name: "displayNameHtml", label: t("htmlDisplayName") }), _jsx(TextControl, { name: convertAttributeNameToForm("attributes.frontendUrl"), type: "url", label: t("frontendUrl"), labelIcon: t("frontendUrlHelp") }), _jsx(SelectControl, { name: "sslRequired", label: t("requireSsl"), labelIcon: t("requireSslHelp"), controller: {
defaultValue: "none",
}, options: REQUIRE_SSL_TYPES.map((sslType) => ({
key: sslType,
value: t(`sslType.${sslType}`),
})) }), _jsx(FormGroup, { label: t("acrToLoAMapping"), fieldId: "acrToLoAMapping", labelIcon: _jsx(HelpItem, { helpText: t("acrToLoAMappingHelp"), fieldLabelId: "acrToLoAMapping" }), children: _jsx(KeyValueInput, { label: t("acrToLoAMapping"), name: convertAttributeNameToForm("attributes.acr.loa.map") }) }), _jsx(DefaultSwitchControl, { name: "userManagedAccessAllowed", label: t("userManagedAccess"), labelIcon: t("userManagedAccessHelp") }), isOrganizationsEnabled && (_jsx(DefaultSwitchControl, { name: "organizationsEnabled", label: t("organizationsEnabled"), labelIcon: t("organizationsEnabledHelp") })), _jsx(SelectControl, { name: "unmanagedAttributePolicy", label: t("unmanagedAttributes"), labelIcon: t("unmanagedAttributesHelpText"), controller: {
defaultValue: UNMANAGED_ATTRIBUTE_POLICIES[0],
}, options: UNMANAGED_ATTRIBUTE_POLICIES.map((policy) => ({
key: policy,
value: t(`unmanagedAttributePolicy.${policy}`),
})) }), _jsx(FormGroup, { label: t("endpoints"), labelIcon: _jsx(HelpItem, { helpText: t("endpointsHelp"), fieldLabelId: "endpoints" }), fieldId: "kc-endpoints", children: _jsxs(Stack, { children: [_jsx(StackItem, { children: _jsx(FormattedLink, { href: `${addTrailingSlash(serverBaseUrl)}realms/${realmName}/.well-known/openid-configuration`, title: t("openIDEndpointConfiguration") }) }), _jsx(StackItem, { children: _jsx(FormattedLink, { href: `${addTrailingSlash(serverBaseUrl)}realms/${realmName}/protocol/saml/descriptor`, title: t("samlIdentityProviderMetadata") }) }), isOpenid4vciEnabled && (_jsx(StackItem, { children: _jsx(FormattedLink, { href: `${addTrailingSlash(serverBaseUrl)}realms/${realmName}/.well-known/openid-credential-issuer`, title: t("oid4vcIssuerMetadata") }) }))] }) }), _jsx(FixedButtonsGroup, { name: "realmSettingsGeneralTab", reset: setupForm, isSubmit: true })] }) }) }));
}
//# sourceMappingURL=GeneralTab.js.map