theme.keycloak.v2.admin.resources.assets.ExecutorForm-BtMpq0Ui.js.map Maven / Gradle / Ivy
{"version":3,"file":"ExecutorForm-BtMpq0Ui.js","sources":["../../src/realm-settings/ExecutorForm.tsx"],"sourcesContent":["import type { ConfigPropertyRepresentation } from \"@keycloak/keycloak-admin-client/lib/defs/authenticatorConfigInfoRepresentation\";\nimport type ClientProfileRepresentation from \"@keycloak/keycloak-admin-client/lib/defs/clientProfileRepresentation\";\nimport type ComponentTypeRepresentation from \"@keycloak/keycloak-admin-client/lib/defs/componentTypeRepresentation\";\nimport {\n HelpItem,\n KeycloakSelect,\n SelectVariant,\n} from \"@keycloak/keycloak-ui-shared\";\nimport {\n ActionGroup,\n AlertVariant,\n Button,\n FormGroup,\n PageSection,\n SelectOption,\n} from \"@patternfly/react-core\";\nimport { useState } from \"react\";\nimport { Controller, FormProvider, useForm } from \"react-hook-form\";\nimport { useTranslation } from \"react-i18next\";\nimport { Link, useNavigate } from \"react-router-dom\";\nimport { useAdminClient } from \"../admin-client\";\nimport { useAlerts } from \"../components/alert/Alerts\";\nimport { DynamicComponents } from \"../components/dynamic/DynamicComponents\";\nimport { FormAccess } from \"../components/form/FormAccess\";\nimport { ViewHeader } from \"../components/view-header/ViewHeader\";\nimport { useServerInfo } from \"../context/server-info/ServerInfoProvider\";\nimport { useFetch } from \"../utils/useFetch\";\nimport { useParams } from \"../utils/useParams\";\nimport { ClientProfileParams, toClientProfile } from \"./routes/ClientProfile\";\nimport type { ExecutorParams } from \"./routes/Executor\";\n\ntype ExecutorForm = {\n config?: object;\n executor: string;\n};\n\nconst defaultValues: ExecutorForm = {\n config: {},\n executor: \"\",\n};\n\nexport default function ExecutorForm() {\n const { adminClient } = useAdminClient();\n\n const { t } = useTranslation();\n const navigate = useNavigate();\n const { realm, profileName } = useParams();\n const { executorName } = useParams();\n const { addAlert, addError } = useAlerts();\n const [selectExecutorTypeOpen, setSelectExecutorTypeOpen] = useState(false);\n const serverInfo = useServerInfo();\n const executorTypes =\n serverInfo.componentTypes?.[\n \"org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider\"\n ];\n const [executors, setExecutors] = useState([]);\n const [executorProperties, setExecutorProperties] = useState<\n ConfigPropertyRepresentation[]\n >([]);\n const [globalProfiles, setGlobalProfiles] = useState<\n ClientProfileRepresentation[]\n >([]);\n const [profiles, setProfiles] = useState([]);\n const form = useForm({ defaultValues });\n const { control, reset, handleSubmit } = form;\n const editMode = !!executorName;\n\n const setupForm = (profiles: ClientProfileRepresentation[]) => {\n const profile = profiles.find((profile) => profile.name === profileName);\n const executor = profile?.executors?.find(\n (executor) => executor.executor === executorName,\n );\n if (executor) reset({ config: executor.configuration });\n };\n\n useFetch(\n () =>\n adminClient.clientPolicies.listProfiles({ includeGlobalProfiles: true }),\n (profiles) => {\n setGlobalProfiles(profiles.globalProfiles!);\n setProfiles(profiles.profiles!);\n\n setupForm(profiles.profiles!);\n setupForm(profiles.globalProfiles!);\n },\n [],\n );\n\n const save = async () => {\n const formValues = form.getValues();\n const updatedProfiles = profiles.map((profile) => {\n if (profile.name !== profileName) {\n return profile;\n }\n\n const executors = (profile.executors ?? []).concat({\n executor: formValues.executor,\n configuration: formValues.config || {},\n });\n\n if (editMode) {\n const profileExecutor = profile.executors!.find(\n (executor) => executor.executor === executorName,\n );\n profileExecutor!.configuration = {\n ...profileExecutor!.configuration,\n ...formValues.config,\n };\n }\n\n if (editMode) {\n return profile;\n }\n return {\n ...profile,\n executors,\n };\n });\n try {\n await adminClient.clientPolicies.createProfiles({\n profiles: updatedProfiles,\n globalProfiles: globalProfiles,\n });\n addAlert(\n editMode ? t(\"updateExecutorSuccess\") : t(\"addExecutorSuccess\"),\n AlertVariant.success,\n );\n\n navigate(toClientProfile({ realm, profileName }));\n } catch (error) {\n addError(editMode ? \"updateExecutorError\" : \"addExecutorError\", error);\n }\n };\n\n const globalProfile = globalProfiles.find(\n (globalProfile) => globalProfile.name === profileName,\n );\n\n const profileExecutorType = executorTypes?.find(\n (executor) => executor.id === executorName,\n );\n\n const editedProfileExecutors =\n profileExecutorType?.properties.map(\n (property) => {\n const globalDefaultValues = editMode ? property.defaultValue : \"\";\n return {\n ...property,\n defaultValue: globalDefaultValues,\n };\n },\n );\n\n return (\n <>\n \n \n \n 0 && executors[0].helpText! !== \"\" ? (\n \n ) : editMode ? (\n \n ) : undefined\n }\n >\n (\n setSelectExecutorTypeOpen(isOpen)}\n onSelect={(value) => {\n reset({ ...defaultValues, executor: value.toString() });\n const selectedExecutor = executorTypes?.filter(\n (type) => type.id === value,\n );\n setExecutors(selectedExecutor ?? []);\n setExecutorProperties(\n selectedExecutor?.[0].properties ?? [],\n );\n setSelectExecutorTypeOpen(false);\n }}\n selections={editMode ? executorName : field.value}\n variant={SelectVariant.single}\n data-testid=\"executorType-select\"\n aria-label={t(\"executorType\")}\n isOpen={selectExecutorTypeOpen}\n maxHeight={580}\n isDisabled={editMode}\n >\n {executorTypes?.map((option) => (\n \n {option.id}\n \n ))}\n \n )}\n />\n \n \n \n \n {!globalProfile && (\n \n \n \n \n )}\n \n {editMode && globalProfile && (\n \n \n \n )}\n \n >\n );\n}\n"],"names":["defaultValues","ExecutorForm","adminClient","useAdminClient","t","useTranslation","navigate","useNavigate","realm","profileName","useParams","executorName","addAlert","addError","useAlerts","selectExecutorTypeOpen","setSelectExecutorTypeOpen","useState","executorTypes","useServerInfo","executors","setExecutors","executorProperties","setExecutorProperties","globalProfiles","setGlobalProfiles","profiles","setProfiles","form","useForm","control","reset","handleSubmit","editMode","setupForm","executor","profile","useFetch","save","formValues","updatedProfiles","profileExecutor","AlertVariant","toClientProfile","error","globalProfile","profileExecutorType","editedProfileExecutors","property","globalDefaultValues","jsxs","Fragment","jsx","ViewHeader","PageSection","FormAccess","FormGroup","HelpItem","Controller","field","KeycloakSelect","isOpen","value","selectedExecutor","type","SelectVariant","option","SelectOption","FormProvider","DynamicComponents","ActionGroup","Button","props","Link"],"mappings":"yrCAoCA,MAAMA,EAA8B,CAClC,OAAQ,CA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