import React, { useState, useContext } 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 { DataLoader } from "./components/data-loader/DataLoader"; import { HttpClientContext } from "./http-service/HttpClientContext"; import { RealmRepresentation } from "./realm/models/Realm"; export const PageNav: React.FunctionComponent = () => { const { t } = useTranslation("common"); const httpClient = useContext(HttpClientContext)!; const realmLoader = async () => { const response = await httpClient.doGet( "/admin/realms" ); return response.data; }; 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(); }; const makeNavItem = (title: string, path: string) => { return ( {t(title)} ); }; return ( {(realmList) => ( {makeNavItem("clients", "clients")} {makeNavItem("clientScopes", "client-scopes")} {makeNavItem("realmRoles", "realm-roles")} {makeNavItem("users", "users")} {makeNavItem("groups", "groups")} {makeNavItem("sessions", "sessions")} {makeNavItem("events", "events")} {makeNavItem("realmSettings", "realm-settings")} {makeNavItem("authentication", "authentication")} {makeNavItem("identityProviders", "identity-providers")} {makeNavItem("userFederation", "user-federation")} } /> )} ); };