import { Divider, Nav, NavGroup, NavItem, NavList, PageSidebar, } from "@patternfly/react-core"; import { FormEvent } from "react"; 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 { AddRealmRoute } from "./realm/routes/AddRealm"; import { routes } from "./route-config"; import "./page-nav.css"; type LeftNavProps = { title: string; path: string }; const LeftNav = ({ title, path }: LeftNavProps) => { const { t } = useTranslation("common"); const { hasAccess } = useAccess(); const { realm } = useRealm(); const route = routes.find( (route) => route.path.replace(/\/:.+?(\?|(?:(?!\/).)*|$)/g, "") === path ); const accessAllowed = route && (route.handle.access instanceof Array ? hasAccess(...route.handle.access) : hasAccess(route.handle.access)); if (!accessAllowed) { return null; } return (
  • `pf-c-nav__link${isActive ? " pf-m-current" : ""}` } > {t(title)}
  • ); }; export const PageNav = () => { const { t } = useTranslation("common"); const { hasSomeAccess } = useAccess(); const navigate = useNavigate(); type SelectedItem = { groupId: number | string; itemId: number | string; to: string; event: FormEvent; }; const onSelect = (item: SelectedItem) => { 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 ( {showManage && !isOnAddRealm && ( )} {showConfigure && !isOnAddRealm && ( )} } /> ); };