UNPKG

@keycloakify/keycloak-admin-ui

Version:
49 lines 3.95 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { Button, Modal, ModalVariant, Popover, Text, TextContent, TextVariants, } from "@patternfly/react-core"; import { CheckCircleIcon } from "@patternfly/react-icons"; import { useTranslation } from "react-i18next"; import { useAdminClient } from "../../admin-client"; import { fetchUsedBy } from "../../components/role-mapping/resource"; import { KeycloakDataTable } from "../../ui-shared"; import useToggle from "../../utils/useToggle"; import { REALM_FLOWS } from "../../authentication/AuthenticationSection"; import style from "@keycloakify/keycloak-admin-ui/authentication/components/used-by.module.css"; import { useRealm } from "../../context/realm-context/RealmContext"; const Label = ({ label }) => (_jsxs(_Fragment, { children: [_jsx(CheckCircleIcon, { className: style.label }), " ", label] })); const UsedByModal = ({ id, isSpecificClient, onClose }) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const loader = async (first, max, search) => { const result = await fetchUsedBy(adminClient, { id, type: isSpecificClient ? "clients" : "idp", first: first || 0, max: max || 10, search, }); return result.map((p) => ({ name: p })); }; return (_jsx(Modal, { header: _jsxs(TextContent, { children: [_jsx(Text, { component: TextVariants.h1, children: t("flowUsedBy") }), _jsx(Text, { children: t("flowUsedByDescription", { value: isSpecificClient ? t("clients") : t("identiyProviders"), }) })] }), variant: ModalVariant.medium, isOpen: true, onClose: onClose, actions: [ _jsx(Button, { "data-testid": "cancel", id: "modal-cancel", onClick: onClose, children: t("close") }, "cancel"), ], children: _jsx(KeycloakDataTable, { loader: loader, isPaginated: true, ariaLabelKey: "usedBy", searchPlaceholderKey: "search", columns: [ { name: "name", }, ] }) })); }; export const UsedBy = ({ authType: { id, usedBy } }) => { var _a; const { t } = useTranslation(); const { realmRepresentation: realm } = useRealm(); const [open, toggle] = useToggle(); const key = (_a = Object.entries(realm).find((e) => e[1] === (usedBy === null || usedBy === void 0 ? void 0 : usedBy.values[0]))) === null || _a === void 0 ? void 0 : _a[0]; return (_jsxs(_Fragment, { children: [open && (_jsx(UsedByModal, { id: id, onClose: toggle, isSpecificClient: (usedBy === null || usedBy === void 0 ? void 0 : usedBy.type) === "SPECIFIC_CLIENTS" })), ((usedBy === null || usedBy === void 0 ? void 0 : usedBy.type) === "SPECIFIC_PROVIDERS" || (usedBy === null || usedBy === void 0 ? void 0 : usedBy.type) === "SPECIFIC_CLIENTS") && (usedBy.values.length <= 8 ? (_jsx(Popover, { "aria-label": t("usedBy"), bodyContent: _jsxs("div", { children: [t("appliedBy" + (usedBy.type === "SPECIFIC_CLIENTS" ? "Clients" : "Providers")), " ", usedBy.values.map((used, index) => (_jsxs(_Fragment, { children: [_jsx("strong", { children: used }), index < usedBy.values.length - 1 ? ", " : ""] })))] }, `usedBy-${id}-${usedBy.values}`), children: _jsx(Button, { variant: "link", className: style.label, children: _jsx(Label, { label: t(`used.${usedBy.type}`) }) }) }, id)) : (_jsx(Button, { variant: "link", className: style.label, onClick: toggle, children: _jsx(Label, { label: t(`used.${usedBy.type}`) }) }))), (usedBy === null || usedBy === void 0 ? void 0 : usedBy.type) === "DEFAULT" && (_jsx(Label, { label: t(`flow.${REALM_FLOWS.get(key)}`) })), !(usedBy === null || usedBy === void 0 ? void 0 : usedBy.type) && t("used.notInUse")] })); }; //# sourceMappingURL=UsedBy.js.map