UNPKG

@keycloakify/keycloak-admin-ui

Version:
81 lines 3.71 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { Link } from "react-router-dom"; import { Tooltip } from "@patternfly/react-core"; import { useRealm } from "../context/realm-context/RealmContext"; import { toClient } from "../clients/routes/Client"; import { toGroups } from "../groups/routes/Groups"; import { toClientScope } from "../client-scopes/routes/ClientScope"; import { toUser } from "../user/routes/User"; import { toRealmRole } from "../realm-roles/routes/RealmRole"; import { toFlow } from "../authentication/routes/Flow"; import { toEditOrganization } from "../organizations/routes/EditOrganization"; const MAX_TEXT_LENGTH = 38; const Truncate = ({ text, children, }) => { const definedText = text || ""; const needsTruncation = definedText.length > MAX_TEXT_LENGTH; const truncatedText = definedText.substring(0, MAX_TEXT_LENGTH); return needsTruncation ? (_jsx(Tooltip, { content: text, children: children(truncatedText + "…") })) : (children(definedText)); }; const isLinkable = (event) => { var _a, _b; if (event.operationType === "DELETE") { return false; } return (event.resourceType === "USER" || event.resourceType === "GROUP_MEMBERSHIP" || event.resourceType === "GROUP" || event.resourceType === "CLIENT" || event.resourceType === "ORGANIZATION" || event.resourceType === "ORGANIZATION_MEMBERSHIP" || ((_a = event.resourceType) === null || _a === void 0 ? void 0 : _a.startsWith("AUTHORIZATION_RESOURCE")) || event.resourceType === "CLIENT_SCOPE" || event.resourceType === "AUTH_FLOW" || ((_b = event.resourcePath) === null || _b === void 0 ? void 0 : _b.startsWith("roles-by-id"))); }; const idRegex = new RegExp(/([0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12})/); const createLink = (realm, event) => { var _a, _b; const part = idRegex.exec(event.resourcePath); if (!part) { console.warn("event didn't contain a valid link", event); return ""; } const id = part[1]; if (event.resourceType === "CLIENT" || ((_a = event.resourceType) === null || _a === void 0 ? void 0 : _a.startsWith("AUTHORIZATION_RESOURCE"))) { return toClient({ realm, clientId: id, tab: event.resourceType === "CLIENT" ? "settings" : "authorization", }); } if (event.resourceType === "GROUP") { return toGroups({ realm, id }); } if (event.resourceType === "CLIENT_SCOPE") { return toClientScope({ realm, id, tab: "settings" }); } if (event.resourceType === "USER" || event.resourceType === "GROUP_MEMBERSHIP") { return toUser({ realm, id, tab: "settings" }); } if (event.resourceType === "AUTH_FLOW") { return toFlow({ realm, id, usedBy: "-" }); } if ((_b = event.resourcePath) === null || _b === void 0 ? void 0 : _b.startsWith("roles-by-id")) { return toRealmRole({ realm, id, tab: "details" }); } if (event.resourceType === "ORGANIZATION") { return toEditOrganization({ realm, id, tab: "settings" }); } if (event.resourceType === "ORGANIZATION_MEMBERSHIP") { return toEditOrganization({ realm, id, tab: "members" }); } return ""; }; export const ResourceLink = ({ event }) => { const { realm } = useRealm(); return (_jsx(Truncate, { text: event.resourcePath, children: (text) => isLinkable(event) ? (_jsx(Link, { to: createLink(realm, event), children: text })) : (_jsx("span", { children: text })) })); }; export const CellResourceLinkRenderer = (adminEvent) => _jsx(ResourceLink, { event: adminEvent }); //# sourceMappingURL=ResourceLinks.js.map