All Downloads are FREE. Search and download functionalities are using the official Maven repository.

theme.keycloak.v2.admin.resources.assets.ClientProfileForm-Bj_Zx5Ql.js.map Maven / Gradle / Ivy

There is a newer version: 26.0.7
Show newest version
{"version":3,"file":"ClientProfileForm-Bj_Zx5Ql.js","sources":["../../src/realm-settings/ClientProfileForm.tsx"],"sourcesContent":["import type ClientProfileRepresentation from \"@keycloak/keycloak-admin-client/lib/defs/clientProfileRepresentation\";\nimport type ClientProfilesRepresentation from \"@keycloak/keycloak-admin-client/lib/defs/clientProfilesRepresentation\";\nimport {\n  HelpItem,\n  TextAreaControl,\n  TextControl,\n} from \"@keycloak/keycloak-ui-shared\";\nimport {\n  ActionGroup,\n  AlertVariant,\n  Button,\n  ButtonVariant,\n  DataList,\n  DataListCell,\n  DataListItem,\n  DataListItemCells,\n  DataListItemRow,\n  Divider,\n  DropdownItem,\n  Flex,\n  FlexItem,\n  Label,\n  PageSection,\n  Text,\n  TextVariants,\n} from \"@patternfly/react-core\";\nimport { PlusCircleIcon, TrashIcon } from \"@patternfly/react-icons\";\nimport { Fragment, useMemo, useState } from \"react\";\nimport { FormProvider, useFieldArray, 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 { useConfirmDialog } from \"../components/confirm-dialog/ConfirmDialog\";\nimport { FormAccess } from \"../components/form/FormAccess\";\nimport { KeycloakSpinner } from \"../components/keycloak-spinner/KeycloakSpinner\";\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 { toAddExecutor } from \"./routes/AddExecutor\";\nimport { toClientPolicies } from \"./routes/ClientPolicies\";\nimport { ClientProfileParams, toClientProfile } from \"./routes/ClientProfile\";\nimport { toExecutor } from \"./routes/Executor\";\n\nimport \"./realm-settings-section.css\";\n\ntype ClientProfileForm = Required;\n\nconst defaultValues: ClientProfileForm = {\n  name: \"\",\n  description: \"\",\n  executors: [],\n};\n\nexport default function ClientProfileForm() {\n  const { adminClient } = useAdminClient();\n\n  const { t } = useTranslation();\n  const navigate = useNavigate();\n  const form = useForm({\n    defaultValues,\n    mode: \"onChange\",\n  });\n\n  const {\n    handleSubmit,\n    setValue,\n    getValues,\n    formState: { isDirty },\n    control,\n  } = form;\n\n  const { fields: profileExecutors, remove } = useFieldArray({\n    name: \"executors\",\n    control,\n  });\n\n  const { addAlert, addError } = useAlerts();\n  const [profiles, setProfiles] = useState();\n  const [isGlobalProfile, setIsGlobalProfile] = useState(false);\n  const { realm, profileName } = useParams();\n  const serverInfo = useServerInfo();\n  const executorTypes = useMemo(\n    () =>\n      serverInfo.componentTypes?.[\n        \"org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider\"\n      ],\n    [],\n  );\n  const [executorToDelete, setExecutorToDelete] = useState<{\n    idx: number;\n    name: string;\n  }>();\n  const editMode = profileName ? true : false;\n  const [key, setKey] = useState(0);\n  const reload = () => setKey(key + 1);\n\n  useFetch(\n    () =>\n      adminClient.clientPolicies.listProfiles({ includeGlobalProfiles: true }),\n    (profiles) => {\n      setProfiles({\n        globalProfiles: profiles.globalProfiles,\n        profiles: profiles.profiles?.filter((p) => p.name !== profileName),\n      });\n      const globalProfile = profiles.globalProfiles?.find(\n        (p) => p.name === profileName,\n      );\n      const profile = profiles.profiles?.find((p) => p.name === profileName);\n      setIsGlobalProfile(globalProfile !== undefined);\n      setValue(\"name\", globalProfile?.name ?? profile?.name ?? \"\");\n      setValue(\n        \"description\",\n        globalProfile?.description ?? profile?.description ?? \"\",\n      );\n      setValue(\n        \"executors\",\n        globalProfile?.executors ?? profile?.executors ?? [],\n      );\n    },\n    [key],\n  );\n\n  const save = async (form: ClientProfileForm) => {\n    const updatedProfiles = form;\n\n    try {\n      await adminClient.clientPolicies.createProfiles({\n        ...profiles,\n        profiles: [...(profiles?.profiles || []), updatedProfiles],\n      });\n\n      addAlert(\n        editMode\n          ? t(\"updateClientProfileSuccess\")\n          : t(\"createClientProfileSuccess\"),\n        AlertVariant.success,\n      );\n\n      navigate(toClientProfile({ realm, profileName: form.name }));\n    } catch (error) {\n      addError(\n        editMode ? \"updateClientProfileError\" : \"createClientProfileError\",\n        error,\n      );\n    }\n  };\n\n  const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({\n    titleKey: executorToDelete?.name!\n      ? t(\"deleteExecutorProfileConfirmTitle\")\n      : t(\"deleteClientProfileConfirmTitle\"),\n    messageKey: executorToDelete?.name!\n      ? t(\"deleteExecutorProfileConfirm\", {\n          executorName: executorToDelete.name!,\n        })\n      : t(\"deleteClientProfileConfirm\", {\n          profileName,\n        }),\n    continueButtonLabel: t(\"delete\"),\n    continueButtonVariant: ButtonVariant.danger,\n\n    onConfirm: async () => {\n      if (executorToDelete?.name!) {\n        remove(executorToDelete.idx);\n        try {\n          await adminClient.clientPolicies.createProfiles({\n            ...profiles,\n            profiles: [...(profiles!.profiles || []), getValues()],\n          });\n          addAlert(t(\"deleteExecutorSuccess\"), AlertVariant.success);\n          navigate(toClientProfile({ realm, profileName }));\n        } catch (error) {\n          addError(t(\"deleteExecutorError\"), error);\n        }\n      } else {\n        try {\n          await adminClient.clientPolicies.createProfiles(profiles);\n          addAlert(t(\"deleteClientSuccess\"), AlertVariant.success);\n          navigate(toClientPolicies({ realm, tab: \"profiles\" }));\n        } catch (error) {\n          addError(t(\"deleteClientError\"), error);\n        }\n      }\n    },\n  });\n\n  if (!profiles) {\n    return ;\n  }\n\n  return (\n    <>\n      \n      {t(\"global\")}\n            ) : (\n              \"\"\n            ),\n          },\n        ]}\n        divider\n        dropdownItems={\n          editMode && !isGlobalProfile\n            ? [\n                \n                  {t(\"deleteClientProfile\")}\n                ,\n              ]\n            : undefined\n        }\n      />\n      \n        \n          \n            \n            \n            \n              {!isGlobalProfile && (\n                 handleSubmit(save)()}\n                  data-testid=\"saveCreateProfile\"\n                  isDisabled={!isDirty}\n                >\n                  {t(\"save\")}\n                \n              )}\n              {editMode && !isGlobalProfile && (\n                \n                  {t(\"reload\")}\n                \n              )}\n              {!editMode && !isGlobalProfile && (\n                 (\n                    \n                  )}\n                  data-testid={\"cancelCreateProfile\"}\n                >\n                  {t(\"cancel\")}\n                \n              )}\n            \n            {editMode && (\n              <>\n                \n                  \n                    \n                      {t(\"executors\")}\n                      \n                    \n                  \n                  {!isGlobalProfile && (\n                    \n                       (\n                          \n                        )}\n                        variant=\"link\"\n                        className=\"kc-addExecutor\"\n                        data-testid=\"addExecutor\"\n                        icon={}\n                      >\n                        {t(\"addExecutor\")}\n                      \n                    \n                  )}\n                \n                {profileExecutors.length > 0 && (\n                  <>\n                    \n                      {profileExecutors.map((executor, idx) => (\n                        \n                          \n                            \n                                  {executor.configuration ? (\n                                     (\n                                        \n                                      )}\n                                      variant=\"link\"\n                                      data-testid=\"editExecutor\"\n                                    >\n                                      {executor.executor}\n                                    \n                                  ) : (\n                                    \n                                      {executor.executor}\n                                    \n                                  )}\n                                  {executorTypes\n                                    ?.filter(\n                                      (type) => type.id === executor.executor,\n                                    )\n                                    .map((type) => (\n                                      \n                                        \n                                        {!isGlobalProfile && (\n                                          \n                                            }\n                                            onClick={() => {\n                                              toggleDeleteDialog();\n                                              setExecutorToDelete({\n                                                idx: idx,\n                                                name: type.id,\n                                              });\n                                            }}\n                                            aria-label={t(\"remove\")}\n                                          />\n                                        )}\n                                      \n                                    ))}\n                                ,\n                              ]}\n                            />\n                          \n                        \n                      ))}\n                    \n                    {isGlobalProfile && (\n                       (\n                          \n                        )}\n                        variant=\"primary\"\n                        className=\"kc-backToPolicies\"\n                        data-testid=\"backToClientPolicies\"\n                      >\n                        {t(\"back\")}\n                      \n                    )}\n                  \n                )}\n                {profileExecutors.length === 0 && (\n                  <>\n                    \n                    \n                      {t(\"emptyExecutors\")}\n                    \n                  \n                )}\n              \n            )}\n          \n        \n      \n    \n  );\n}\n"],"names":["defaultValues","ClientProfileForm","adminClient","useAdminClient","useTranslation","navigate","useNavigate","form","useForm","handleSubmit","setValue","getValues","isDirty","control","profileExecutors","remove","useFieldArray","addAlert","addError","useAlerts","profiles","setProfiles","useState","isGlobalProfile","setIsGlobalProfile","realm","profileName","useParams","serverInfo","useServerInfo","executorTypes","useMemo","executorToDelete","setExecutorToDelete","editMode","key","setKey","reload","useFetch","p","globalProfile","profile","save","updatedProfiles","AlertVariant","toClientProfile","error","toggleDeleteDialog","DeleteConfirm","useConfirmDialog","ButtonVariant","toClientPolicies","jsxs","Fragment","jsx","ViewHeader","Label","DropdownItem","PageSection","FormProvider","FormAccess","TextControl","TextAreaControl","ActionGroup","Button","props","Link","Flex","FlexItem","Text","TextVariants","HelpItem","toAddExecutor","PlusCircleIcon","DataList","executor","idx","DataListItem","DataListItemRow","DataListItemCells","DataListCell","toExecutor","type","TrashIcon","Divider","KeycloakSpinner"],"mappings":"80BAiDA,MAAMA,GAAmC,CACvC,KAAM,GACN,YAAa,GACb,UAAW,CAAC,CACd,EAEA,SAAwBC,IAAoB,CACpC,KAAA,CAAE,YAAAC,GAAgBC,IAElB,CAAE,GAAMC,IACRC,EAAWC,IACXC,EAAOC,EAA2B,CACtC,cAAAR,GACA,KAAM,UAAA,CACP,EAEK,CACJ,aAAAS,EACA,SAAAC,EACA,UAAAC,EACA,UAAW,CAAE,QAAAC,CAAQ,EACrB,QAAAC,CACE,EAAAN,EAEE,CAAE,OAAQO,EAAkB,OAAAC,CAAA,EAAWC,EAAc,CACzD,KAAM,YACN,QAAAH,CAAA,CACD,EAEK,CAAE,SAAAI,EAAU,SAAAC,CAAS,EAAIC,EAAU,EACnC,CAACC,EAAUC,CAAW,EAAIC,EAAuC,EACjE,CAACC,EAAiBC,CAAkB,EAAIF,EAAS,EAAK,EACtD,CAAE,MAAAG,EAAO,YAAAC,CAAY,EAAIC,GAA+B,EACxDC,EAAaC,IACbC,EAAgBC,GACpB,IACEH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