UNPKG

@keycloakify/keycloak-admin-ui

Version:
48 lines 4.21 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Divider, Nav, NavGroup, NavItem, NavList, PageSidebar, PageSidebarBody, } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; import { NavLink, useMatch, useNavigate } from "react-router-dom"; import { RealmSelector } from "./components/realm-selector/RealmSelector"; import { useAccess } from "./context/access/Access"; import { useRealm } from "./context/realm-context/RealmContext"; import { useServerInfo } from "./context/server-info/ServerInfoProvider"; import { toPage } from "./page/routes"; import { AddRealmRoute } from "./realm/routes/AddRealm"; import { routes } from "./routes"; import useIsFeatureEnabled, { Feature } from "./utils/useIsFeatureEnabled"; import "./page-nav.css"; const LeftNav = ({ title, path, id }) => { const { t } = useTranslation(); const { hasAccess } = useAccess(); const { realm } = useRealm(); const encodedRealm = encodeURIComponent(realm); const route = routes.find((route) => route.path.replace(/\/:.+?(\?|(?:(?!\/).)*|$)/g, "") === (id || path)); const accessAllowed = route && (route.handle.access instanceof Array ? hasAccess(...route.handle.access) : hasAccess(route.handle.access)); if (!accessAllowed) { return null; } return (_jsx("li", { children: _jsx(NavLink, { id: "nav-item" + path.replace("/", "-"), to: `/${encodedRealm}${path}`, className: ({ isActive }) => `pf-v5-c-nav__link${isActive ? " pf-m-current" : ""}`, children: t(title) }) })); }; export const PageNav = () => { const { t } = useTranslation(); const { hasSomeAccess } = useAccess(); const { componentTypes } = useServerInfo(); const isFeatureEnabled = useIsFeatureEnabled(); const pages = componentTypes === null || componentTypes === void 0 ? void 0 : componentTypes["org.keycloak.services.ui.extend.UiPageProvider"]; const navigate = useNavigate(); const { realmRepresentation } = useRealm(); const onSelect = (item) => { navigate(item.to); item.event.preventDefault(); }; const showManage = hasSomeAccess("view-realm", "query-groups", "query-users", "query-clients", "view-events"); const showConfigure = hasSomeAccess("view-realm", "query-clients", "view-identity-providers"); const isOnAddRealm = !!useMatch(AddRealmRoute.path); return (_jsx(PageSidebar, { className: "keycloak__page_nav__nav", children: _jsx(PageSidebarBody, { children: _jsxs(Nav, { onSelect: (_event, item) => onSelect(item), children: [_jsx(NavList, { children: _jsx(NavItem, { className: "keycloak__page_nav__nav_item__realm-selector", children: _jsx(RealmSelector, {}) }) }), _jsx(Divider, {}), showManage && !isOnAddRealm && (_jsxs(NavGroup, { "aria-label": t("manage"), title: t("manage"), children: [isFeatureEnabled(Feature.Organizations) && (realmRepresentation === null || realmRepresentation === void 0 ? void 0 : realmRepresentation.organizationsEnabled) && (_jsx(LeftNav, { title: "organizations", path: "/organizations" })), _jsx(LeftNav, { title: "clients", path: "/clients" }), _jsx(LeftNav, { title: "clientScopes", path: "/client-scopes" }), _jsx(LeftNav, { title: "realmRoles", path: "/roles" }), _jsx(LeftNav, { title: "users", path: "/users" }), _jsx(LeftNav, { title: "groups", path: "/groups" }), _jsx(LeftNav, { title: "sessions", path: "/sessions" }), _jsx(LeftNav, { title: "events", path: "/events" })] })), showConfigure && !isOnAddRealm && (_jsxs(NavGroup, { "aria-label": t("configure"), title: t("configure"), children: [_jsx(LeftNav, { title: "realmSettings", path: "/realm-settings" }), _jsx(LeftNav, { title: "authentication", path: "/authentication" }), _jsx(LeftNav, { title: "identityProviders", path: "/identity-providers" }), _jsx(LeftNav, { title: "userFederation", path: "/user-federation" }), isFeatureEnabled(Feature.DeclarativeUI) && (pages === null || pages === void 0 ? void 0 : pages.map((p) => (_jsx(LeftNav, { title: p.id, path: toPage({ providerId: p.id }).pathname, id: "/page-section" }, p.id))))] }))] }) }) })); }; //# sourceMappingURL=PageNav.js.map