UNPKG

@keycloakify/keycloak-admin-ui

Version:
74 lines 3.83 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { useAlerts, useFetch } from "../../ui-shared"; import { AlertVariant, PageSection, Tab, TabTitleText, } from "@patternfly/react-core"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import { useAdminClient } from "../../admin-client"; import { MapperList } from "../../client-scopes/details/MapperList"; import { KeycloakSpinner } from "../../ui-shared"; import { RoutableTabs, useRoutableTab, } from "../../components/routable-tabs/RoutableTabs"; import { ViewHeader } from "../../components/view-header/ViewHeader"; import { useParams } from "../../utils/useParams"; import { toDedicatedScope, } from "../../clients/routes/DedicatedScopeDetails"; import { toMapper } from "../../clients/routes/Mapper"; import { DedicatedScope } from "../../clients/scopes/DedicatedScope"; export default function DedicatedScopes() { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const navigate = useNavigate(); const { realm, clientId } = useParams(); const { addAlert, addError } = useAlerts(); const [client, setClient] = useState(); useFetch(() => adminClient.clients.findOne({ id: clientId }), setClient, []); const useTab = (tab) => useRoutableTab(toDedicatedScope({ realm, clientId, tab })); const mappersTab = useTab("mappers"); const scopeTab = useTab("scope"); if (!client) { return _jsx(KeycloakSpinner, {}); } const addMappers = async (mappers) => { if (!Array.isArray(mappers)) { const mapper = mappers; navigate(toMapper({ realm, id: client.id, mapperId: mapper.id, })); } else { try { await adminClient.clients.addMultipleProtocolMappers({ id: client.id }, mappers); setClient(await adminClient.clients.findOne({ id: client.id })); addAlert(t("mappingCreatedSuccess"), AlertVariant.success); } catch (error) { addError("mappingCreatedError", error); } } }; const onDeleteMapper = async (mapper) => { var _a; try { await adminClient.clients.delProtocolMapper({ id: client.id, mapperId: mapper.id, }); setClient({ ...client, protocolMappers: (_a = client.protocolMappers) === null || _a === void 0 ? void 0 : _a.filter((m) => m.id !== mapper.id), }); addAlert(t("mappingDeletedSuccess"), AlertVariant.success); } catch (error) { addError("mappingDeletedError", error); } return true; }; return (_jsxs(_Fragment, { children: [_jsx(ViewHeader, { titleKey: client.clientId + "-dedicated", subKey: "dedicatedScopeExplain", divider: false }), _jsx(PageSection, { variant: "light", className: "pf-v5-u-p-0", children: _jsxs(RoutableTabs, { isBox: true, mountOnEnter: true, defaultLocation: toDedicatedScope({ realm, clientId, tab: "mappers", }), children: [_jsx(Tab, { title: _jsx(TabTitleText, { children: t("mappers") }), "data-testid": "mappersTab", ...mappersTab, children: _jsx(MapperList, { model: client, onAdd: addMappers, onDelete: onDeleteMapper, detailLink: (mapperId) => toMapper({ realm, id: client.id, mapperId }) }) }), _jsx(Tab, { title: _jsx(TabTitleText, { children: t("scope") }), "data-testid": "scopeTab", ...scopeTab, children: _jsx(DedicatedScope, { client: client }) })] }) })] })); } //# sourceMappingURL=DedicatedScopes.js.map