theme.keycloak.v2.admin.resources.assets.NewClientPolicyCondition-BGdDHdFi.js.map Maven / Gradle / Ivy
{"version":3,"file":"NewClientPolicyCondition-BGdDHdFi.js","sources":["../../src/realm-settings/NewClientPolicyCondition.tsx"],"sourcesContent":["import type { ConfigPropertyRepresentation } from \"@keycloak/keycloak-admin-client/lib/defs/authenticatorConfigInfoRepresentation\";\nimport type ClientPolicyConditionRepresentation from \"@keycloak/keycloak-admin-client/lib/defs/clientPolicyConditionRepresentation\";\nimport type ClientPolicyRepresentation from \"@keycloak/keycloak-admin-client/lib/defs/clientPolicyRepresentation\";\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 { camelCase } from \"lodash-es\";\nimport { useState } from \"react\";\nimport { Controller, FormProvider, useForm } from \"react-hook-form\";\nimport { useTranslation } from \"react-i18next\";\nimport { Link, useNavigate, useParams } 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 { useRealm } from \"../context/realm-context/RealmContext\";\nimport { useServerInfo } from \"../context/server-info/ServerInfoProvider\";\nimport { useFetch } from \"../utils/useFetch\";\nimport { toEditClientPolicy } from \"./routes/EditClientPolicy\";\nimport type { EditClientPolicyConditionParams } from \"./routes/EditCondition\";\n\nexport type ItemType = { value: string };\n\ntype ConfigProperty = ConfigPropertyRepresentation & {\n conditions: any;\n config: any;\n};\n\nexport default function NewClientPolicyCondition() {\n const { adminClient } = useAdminClient();\n\n const { t } = useTranslation();\n const { addAlert, addError } = useAlerts();\n const navigate = useNavigate();\n const { realm } = useRealm();\n\n const [openConditionType, setOpenConditionType] = useState(false);\n const [isGlobalPolicy, setIsGlobalPolicy] = useState(false);\n const [policies, setPolicies] = useState([]);\n\n const [condition, setCondition] = useState<\n ClientPolicyConditionRepresentation[]\n >([]);\n const [conditionData, setConditionData] =\n useState();\n const [conditionType, setConditionType] = useState(\"\");\n const [conditionProperties, setConditionProperties] = useState<\n ConfigPropertyRepresentation[]\n >([]);\n\n const { policyName, conditionName } =\n useParams();\n\n const serverInfo = useServerInfo();\n const form = useForm();\n\n const conditionTypes =\n serverInfo.componentTypes?.[\n \"org.keycloak.services.clientpolicy.condition.ClientPolicyConditionProvider\"\n ];\n\n const setupForm = (condition: ClientPolicyConditionRepresentation) => {\n form.reset({ config: condition.configuration || {} });\n };\n\n useFetch(\n () =>\n adminClient.clientPolicies.listPolicies({\n includeGlobalPolicies: true,\n }),\n\n (policies) => {\n setPolicies(policies.policies ?? []);\n\n if (conditionName) {\n let currentPolicy = policies.policies?.find(\n (item) => item.name === policyName,\n );\n if (currentPolicy === undefined) {\n currentPolicy = policies.globalPolicies?.find(\n (item) => item.name === policyName,\n );\n setIsGlobalPolicy(currentPolicy !== undefined);\n }\n\n const typeAndConfigData = currentPolicy?.conditions?.find(\n (item) => item.condition === conditionName,\n );\n\n const currentCondition = conditionTypes?.find(\n (condition) => condition.id === conditionName,\n );\n\n setConditionData(typeAndConfigData!);\n setConditionProperties(currentCondition?.properties!);\n setupForm(typeAndConfigData!);\n }\n },\n [],\n );\n\n const save = async (configPolicy: ConfigProperty) => {\n const configValues = configPolicy.config;\n\n const writeConfig = () => {\n return conditionProperties.reduce((r: any, p) => {\n r[p.name!] = configValues[p.name!];\n return r;\n }, {});\n };\n\n const updatedPolicies = policies.map((policy) => {\n if (policy.name !== policyName) {\n return policy;\n }\n\n let conditions = policy.conditions ?? [];\n\n if (conditionName) {\n const createdCondition = {\n condition: conditionData?.condition,\n configuration: writeConfig(),\n };\n\n const index = conditions.findIndex(\n (condition) => conditionName === condition.condition,\n );\n\n if (index === -1) {\n return;\n }\n\n const newConditions = [\n ...conditions.slice(0, index),\n createdCondition,\n ...conditions.slice(index + 1),\n ];\n\n return {\n ...policy,\n conditions: newConditions,\n };\n }\n\n conditions = conditions.concat({\n condition: condition[0].condition,\n configuration: writeConfig(),\n });\n\n return {\n ...policy,\n conditions,\n };\n }) as ClientPolicyRepresentation[];\n\n try {\n await adminClient.clientPolicies.updatePolicy({\n policies: updatedPolicies,\n });\n setPolicies(updatedPolicies);\n navigate(toEditClientPolicy({ realm, policyName: policyName! }));\n addAlert(\n conditionName\n ? t(\"updateClientConditionSuccess\")\n : t(\"createClientConditionSuccess\"),\n AlertVariant.success,\n );\n } catch (error) {\n addError(\"createClientConditionError\", error);\n }\n };\n\n return (\n <>\n \n \n \n \n }\n >\n (\n setOpenConditionType(toggle)}\n onSelect={(value) => {\n field.onChange(value);\n setConditionProperties(\n (value as ComponentTypeRepresentation).properties,\n );\n setConditionType((value as ComponentTypeRepresentation).id);\n setCondition([\n {\n condition: (value as ComponentTypeRepresentation).id,\n },\n ]);\n setOpenConditionType(false);\n }}\n selections={conditionName ? conditionName : conditionType}\n variant={SelectVariant.single}\n aria-label={t(\"conditionType\")}\n isOpen={openConditionType}\n >\n {conditionTypes?.map((condition) => (\n \n {condition.id}\n \n ))}\n \n )}\n />\n \n\n \n \n \n {!isGlobalPolicy && (\n \n \n \n \n )}\n \n {isGlobalPolicy && (\n \n \n \n )}\n \n >\n );\n}\n"],"names":["NewClientPolicyCondition","adminClient","useAdminClient","t","useTranslation","addAlert","addError","useAlerts","navigate","useNavigate","realm","useRealm","openConditionType","setOpenConditionType","useState","isGlobalPolicy","setIsGlobalPolicy","policies","setPolicies","condition","setCondition","conditionData","setConditionData","conditionType","setConditionType","conditionProperties","setConditionProperties","policyName","conditionName","useParams","serverInfo","useServerInfo","form","useForm","conditionTypes","setupForm","useFetch","currentPolicy","item","typeAndConfigData","currentCondition","save","configPolicy","configValues","writeConfig","r","p","updatedPolicies","policy","conditions","createdCondition","index","newConditions","toEditClientPolicy","AlertVariant","error","jsxs","Fragment","jsx","ViewHeader","PageSection","FormAccess","FormGroup","HelpItem","camelCase","Controller","field","KeycloakSelect","toggle","value","SelectVariant","SelectOption","FormProvider","DynamicComponents","ActionGroup","Button","props","Link"],"mappings":"4wCAwCA,SAAwBA,IAA2B,CAC3C,KAAA,CAAE,YAAAC,GAAgBC,IAElB,CAAE,EAAAC,GAAMC,IACR,CAAE,SAAAC,EAAU,SAAAC,CAAS,EAAIC,EAAU,EACnCC,EAAWC,IACX,CAAE,MAAAC,GAAUC,IAEZ,CAACC,EAAmBC,CAAoB,EAAIC,EAAS,EAAK,EAC1D,CAACC,EAAgBC,CAAiB,EAAIF,EAAS,EAAK,EACpD,CAACG,EAAUC,CAAW,EAAIJ,EAAuC,CAAE,CAAA,EAEnE,CAACK,EAAWC,CAAY,EAAIN,EAEhC,CAAE,CAAA,EACE,CAACO,EAAeC,CAAgB,EACpCR,EAA8C,EAC1C,CAACS,EAAeC,CAAgB,EAAIV,EAAS,EAAE,EAC/C,CAACW,EAAqBC,CAAsB,EAAIZ,EAEpD,CAAE,CAAA,EAEE,CAAE,WAAAa,EAAY,cAAAC,CAAc,EAChCC,EAA2C,EAEvCC,EAAaC,IACbC,EAAOC,IAEPC,EACJJ,EAAW,iBACT,4EACF,EAEIK,EAAahB,GAAmD,CACpEa,EAAK,MAAM,CAAE,OAAQb,EAAU,eAAiB,GAAI,CAAA,EAGtDiB,EACE,IACEnC,EAAY,eAAe,aAAa,CACtC,sBAAuB,EAAA,CACxB,EAEFgB,GAAa,CAGZ,GAFYA,EAAAA,EAAS,UAAY,CAAA,CAAE,EAE/BW,EAAe,CACb,IAAAS,EAAgBpB,EAAS,UAAU,KACpCqB,GAASA,EAAK,OAASX,CAAA,EAEtBU,IAAkB,SACpBA,EAAgBpB,EAAS,gBAAgB,KACtCqB,GAASA,EAAK,OAASX,CAAA,EAE1BX,EAAkBqB,IA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