theme.keycloak.v2.admin.resources.assets.EditClientScope-C3GoH0xe.js.map Maven / Gradle / Ivy
{"version":3,"file":"EditClientScope-C3GoH0xe.js","sources":["../../src/client-scopes/EditClientScope.tsx"],"sourcesContent":["import ClientScopeRepresentation from \"@keycloak/keycloak-admin-client/lib/defs/clientScopeRepresentation\";\nimport type ProtocolMapperRepresentation from \"@keycloak/keycloak-admin-client/lib/defs/protocolMapperRepresentation\";\nimport type { RoleMappingPayload } from \"@keycloak/keycloak-admin-client/lib/defs/roleRepresentation\";\nimport type { ProtocolMapperTypeRepresentation } from \"@keycloak/keycloak-admin-client/lib/defs/serverInfoRepesentation\";\nimport {\n Alert,\n AlertVariant,\n ButtonVariant,\n DropdownItem,\n PageSection,\n Tab,\n TabTitleText,\n} from \"@patternfly/react-core\";\nimport { useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { useNavigate } from \"react-router-dom\";\nimport { useHelp } from \"@keycloak/keycloak-ui-shared\";\nimport { useAdminClient } from \"../admin-client\";\nimport { useAlerts } from \"../components/alert/Alerts\";\nimport {\n AllClientScopes,\n ClientScope,\n ClientScopeDefaultOptionalType,\n changeScope,\n} from \"../components/client-scope/ClientScopeTypes\";\nimport { useConfirmDialog } from \"../components/confirm-dialog/ConfirmDialog\";\nimport { KeycloakSpinner } from \"../components/keycloak-spinner/KeycloakSpinner\";\nimport { RoleMapping, Row } from \"../components/role-mapping/RoleMapping\";\nimport {\n RoutableTabs,\n useRoutableTab,\n} from \"../components/routable-tabs/RoutableTabs\";\nimport { ViewHeader } from \"../components/view-header/ViewHeader\";\nimport { useRealm } from \"../context/realm-context/RealmContext\";\nimport { convertFormValuesToObject } from \"../util\";\nimport { useFetch } from \"../utils/useFetch\";\nimport { useParams } from \"../utils/useParams\";\nimport { MapperList } from \"./details/MapperList\";\nimport { ScopeForm } from \"./details/ScopeForm\";\nimport {\n ClientScopeParams,\n ClientScopeTab,\n toClientScope,\n} from \"./routes/ClientScope\";\nimport { toClientScopes } from \"./routes/ClientScopes\";\nimport { toMapper } from \"./routes/Mapper\";\n\nexport default function EditClientScope() {\n const { adminClient } = useAdminClient();\n\n const { t } = useTranslation();\n const navigate = useNavigate();\n const { realm } = useRealm();\n const { id } = useParams();\n const { addAlert, addError } = useAlerts();\n const { enabled } = useHelp();\n const [clientScope, setClientScope] =\n useState();\n const [key, setKey] = useState(0);\n const refresh = () => setKey(key + 1);\n\n useFetch(\n async () => {\n const clientScope = await adminClient.clientScopes.findOne({ id });\n\n if (!clientScope) {\n throw new Error(t(\"notFound\"));\n }\n\n return {\n ...clientScope,\n type: await determineScopeType(clientScope),\n };\n },\n (clientScope) => {\n setClientScope(clientScope);\n },\n [key, id],\n );\n\n async function determineScopeType(clientScope: ClientScopeRepresentation) {\n const defaultScopes =\n await adminClient.clientScopes.listDefaultClientScopes();\n const hasDefaultScope = defaultScopes.find(\n (defaultScope) => defaultScope.name === clientScope.name,\n );\n\n if (hasDefaultScope) {\n return ClientScope.default;\n }\n\n const optionalScopes =\n await adminClient.clientScopes.listDefaultOptionalClientScopes();\n const hasOptionalScope = optionalScopes.find(\n (optionalScope) => optionalScope.name === clientScope.name,\n );\n\n return hasOptionalScope ? ClientScope.optional : AllClientScopes.none;\n }\n\n const useTab = (tab: ClientScopeTab) =>\n useRoutableTab(\n toClientScope({\n realm,\n id,\n tab,\n }),\n );\n\n const settingsTab = useTab(\"settings\");\n const mappersTab = useTab(\"mappers\");\n const scopeTab = useTab(\"scope\");\n\n const onSubmit = async (formData: ClientScopeDefaultOptionalType) => {\n const clientScope = convertFormValuesToObject({\n ...formData,\n name: formData.name?.trim().replace(/ /g, \"_\"),\n });\n\n try {\n await adminClient.clientScopes.update({ id }, clientScope);\n await changeScope(adminClient, { ...clientScope, id }, clientScope.type);\n\n addAlert(t(\"updateSuccessClientScope\"), AlertVariant.success);\n } catch (error) {\n addError(\"updateErrorClientScope\", error);\n }\n };\n\n const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({\n titleKey: t(\"deleteClientScope\", {\n count: 1,\n name: clientScope?.name,\n }),\n messageKey: \"deleteConfirmClientScopes\",\n continueButtonLabel: \"delete\",\n continueButtonVariant: ButtonVariant.danger,\n onConfirm: async () => {\n try {\n await adminClient.clientScopes.del({ id });\n addAlert(t(\"deletedSuccessClientScope\"), AlertVariant.success);\n navigate(toClientScopes({ realm }));\n } catch (error) {\n addError(\"deleteErrorClientScope\", error);\n }\n },\n });\n\n const assignRoles = async (rows: Row[]) => {\n try {\n const realmRoles = rows\n .filter((row) => row.client === undefined)\n .map((row) => row.role as RoleMappingPayload)\n .flat();\n await adminClient.clientScopes.addRealmScopeMappings(\n {\n id,\n },\n realmRoles,\n );\n await Promise.all(\n rows\n .filter((row) => row.client !== undefined)\n .map((row) =>\n adminClient.clientScopes.addClientScopeMappings(\n {\n id,\n client: row.client!.id!,\n },\n [row.role as RoleMappingPayload],\n ),\n ),\n );\n addAlert(t(\"roleMappingUpdatedSuccess\"), AlertVariant.success);\n } catch (error) {\n addError(\"roleMappingUpdatedError\", error);\n }\n };\n\n const addMappers = async (\n mappers: ProtocolMapperTypeRepresentation | ProtocolMapperRepresentation[],\n ): Promise => {\n if (!Array.isArray(mappers)) {\n const mapper = mappers as ProtocolMapperTypeRepresentation;\n navigate(\n toMapper({\n realm,\n id: clientScope!.id!,\n mapperId: mapper.id!,\n }),\n );\n } else {\n try {\n await adminClient.clientScopes.addMultipleProtocolMappers(\n { id: clientScope!.id! },\n mappers as ProtocolMapperRepresentation[],\n );\n refresh();\n addAlert(t(\"mappingCreatedSuccess\"), AlertVariant.success);\n } catch (error) {\n addError(\"mappingCreatedError\", error);\n }\n }\n };\n\n const onDelete = async (mapper: ProtocolMapperRepresentation) => {\n try {\n await adminClient.clientScopes.delProtocolMapper({\n id: clientScope!.id!,\n mapperId: mapper.id!,\n });\n addAlert(t(\"mappingDeletedSuccess\"), AlertVariant.success);\n refresh();\n } catch (error) {\n addError(\"mappingDeletedError\", error);\n }\n return true;\n };\n\n if (!clientScope) {\n return ;\n }\n\n return (\n <>\n \n \n {t(\"delete\")}\n ,\n ]}\n badges={[{ text: clientScope.protocol }]}\n divider={false}\n />\n\n \n \n {t(\"settings\")}}\n {...settingsTab}\n >\n \n \n \n \n {t(\"mappers\")}}\n {...mappersTab}\n >\n \n toMapper({ realm, id: clientScope.id!, mapperId: id! })\n }\n />\n \n {t(\"scope\")}}\n {...scopeTab}\n >\n {enabled && (\n \n \n \n )}\n \n \n \n \n >\n );\n}\n"],"names":["EditClientScope","adminClient","useAdminClient","t","useTranslation","navigate","useNavigate","realm","useRealm","id","useParams","addAlert","addError","useAlerts","enabled","useHelp","clientScope","setClientScope","useState","key","setKey","refresh","useFetch","determineScopeType","defaultScope","ClientScope","optionalScope","AllClientScopes","useTab","tab","useRoutableTab","toClientScope","settingsTab","mappersTab","scopeTab","onSubmit","formData","convertFormValuesToObject","changeScope","AlertVariant","error","toggleDeleteDialog","DeleteConfirm","useConfirmDialog","ButtonVariant","toClientScopes","assignRoles","rows","realmRoles","row","addMappers","mappers","mapper","toMapper","onDelete","jsxs","Fragment","jsx","ViewHeader","DropdownItem","PageSection","RoutableTabs","Tab","TabTitleText","ScopeForm","MapperList","Alert","RoleMapping","KeycloakSpinner"],"mappings":"iiDA+CA,SAAwBA,IAAkB,CAClC,KAAA,CAAE,YAAAC,GAAgBC,IAElB,CAAE,EAAAC,GAAMC,IACRC,EAAWC,IACX,CAAE,MAAAC,GAAUC,IACZ,CAAE,GAAAC,GAAOC,KACT,CAAE,SAAAC,EAAU,SAAAC,CAAS,EAAIC,EAAU,EACnC,CAAE,QAAAC,GAAYC,IACd,CAACC,EAAaC,CAAc,EAChCC,EAAyC,EACrC,CAACC,EAAKC,CAAM,EAAIF,EAAS,CAAC,EAC1BG,EAAU,IAAMD,EAAOD,EAAM,CAAC,EAEpCG,EACE,SAAY,CACV,MAAMN,EAAc,MAAMf,EAAY,aAAa,QAAQ,CAAE,GAAAQ,EAAI,EAEjE,GAAI,CAACO,EACH,MAAM,IAAI,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