import React, { useState } from "react"; import { useHistory } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { Nav, NavItem, NavGroup, NavList, PageSidebar, } from "@patternfly/react-core"; import { RealmSelector } from "./components/realm-selector/RealmSelector"; import { useRealm } from "./context/realm-context/RealmContext"; import { DataLoader } from "./components/data-loader/DataLoader"; import { useAdminClient } from "./context/auth/AdminClient"; import { useAccess } from "./context/access/Access"; import { routes } from "./route-config"; export const PageNav: React.FunctionComponent = () => { const { t } = useTranslation("common"); const { hasAccess, hasSomeAccess } = useAccess(); const adminClient = useAdminClient(); const realmLoader = async () => { return await adminClient.realms.find(); }; const history = useHistory(); let initialItem = history.location.pathname; if (initialItem === "/") initialItem = "/client-list"; const [activeItem, setActiveItem] = useState(initialItem); type SelectedItem = { groupId: number | string; itemId: number | string; to: string; event: React.FormEvent; }; const onSelect = (item: SelectedItem) => { setActiveItem(item.to); history.push(item.to); item.event.preventDefault(); }; type LeftNavProps = { title: string; path: string }; const LeftNav = ({ title, path }: LeftNavProps) => { const { realm } = useRealm(); const route = routes(() => {}).find( (route) => route.path.substr("/:realm".length) === path ); if (!route || !hasAccess(route.access)) return <>; return ( {t(title)} ); }; const showManage = hasSomeAccess( "view-realm", "query-groups", "query-users", "query-clients", "view-events" ); const showConfigure = hasSomeAccess( "view-realm", "query-clients", "view-identity-providers" ); return ( {(realmList) => ( )} {showManage && ( )} {showConfigure && ( )} } /> ); };