2020-09-09 09:07:17 +00:00
|
|
|
import React, { useState, useContext } from "react";
|
|
|
|
import { useHistory } from "react-router-dom";
|
2020-09-14 18:10:54 +00:00
|
|
|
import {
|
|
|
|
Nav,
|
|
|
|
NavItem,
|
|
|
|
NavGroup,
|
|
|
|
NavList,
|
|
|
|
PageSidebar,
|
|
|
|
} from "@patternfly/react-core";
|
2020-09-01 14:51:59 +00:00
|
|
|
import { RealmSelector } from "./components/realm-selector/RealmSelector";
|
2020-09-08 17:20:29 +00:00
|
|
|
import { DataLoader } from "./components/data-loader/DataLoader";
|
|
|
|
import { HttpClientContext } from "./http-service/HttpClientContext";
|
2020-09-10 18:04:03 +00:00
|
|
|
import { Realm } from "./realm/models/Realm";
|
2020-08-04 12:59:41 +00:00
|
|
|
|
2020-09-04 18:16:11 +00:00
|
|
|
export const PageNav: React.FunctionComponent = () => {
|
2020-09-08 17:20:29 +00:00
|
|
|
const httpClient = useContext(HttpClientContext)!;
|
|
|
|
const realmLoader = async () => {
|
|
|
|
const response = await httpClient.doGet<Realm[]>("/admin/realms");
|
|
|
|
return response.data;
|
|
|
|
};
|
2020-09-09 09:07:17 +00:00
|
|
|
|
|
|
|
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<HTMLInputElement>;
|
|
|
|
};
|
|
|
|
|
|
|
|
const onSelect = (item: SelectedItem) => {
|
|
|
|
setActiveItem(item.to);
|
|
|
|
history.push(item.to);
|
|
|
|
item.event.preventDefault();
|
|
|
|
};
|
|
|
|
|
|
|
|
const makeNavItem = (title: string, path: string) => {
|
|
|
|
return (
|
|
|
|
<NavItem
|
|
|
|
id={"nav-item-" + path}
|
|
|
|
to={"/" + path}
|
|
|
|
isActive={activeItem === "/" + path}
|
|
|
|
>
|
|
|
|
{title}
|
|
|
|
</NavItem>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-08-04 12:59:41 +00:00
|
|
|
return (
|
|
|
|
<PageSidebar
|
|
|
|
nav={
|
2020-09-09 09:07:17 +00:00
|
|
|
<Nav onSelect={onSelect}>
|
2020-09-14 18:10:54 +00:00
|
|
|
<NavList>
|
|
|
|
<NavItem className="keycloak__page_nav__nav_item__realm-selector">
|
|
|
|
<DataLoader loader={realmLoader}>
|
|
|
|
{(realmList) => (
|
|
|
|
<RealmSelector realm="Master" realmList={realmList || []} />
|
|
|
|
)}
|
|
|
|
</DataLoader>
|
|
|
|
</NavItem>
|
|
|
|
</NavList>
|
2020-09-09 09:07:17 +00:00
|
|
|
<NavGroup title="Manage">
|
|
|
|
{makeNavItem("Clients", "clients")}
|
|
|
|
{makeNavItem("Client Scopes", "client-scopes")}
|
|
|
|
{makeNavItem("Realm Roles", "realm-roles")}
|
|
|
|
{makeNavItem("Users", "users")}
|
|
|
|
{makeNavItem("Groups", "groups")}
|
|
|
|
{makeNavItem("Sessions", "sessions")}
|
|
|
|
{makeNavItem("Events", "events")}
|
|
|
|
</NavGroup>
|
|
|
|
|
|
|
|
<NavGroup title="Configure">
|
|
|
|
{makeNavItem("Realm settings", "realm-settings")}
|
|
|
|
{makeNavItem("Authentication", "authentication")}
|
|
|
|
{makeNavItem("Identity providers", "identity-providers")}
|
|
|
|
{makeNavItem("User federation", "user-federation")}
|
|
|
|
</NavGroup>
|
2020-08-04 12:59:41 +00:00
|
|
|
</Nav>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|