2020-09-09 09:07:17 +00:00
|
|
|
import React, { useState, useContext } from "react";
|
|
|
|
import { useHistory } from "react-router-dom";
|
2020-09-21 12:54:42 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
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-15 19:44:28 +00:00
|
|
|
import { RealmRepresentation } 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-21 12:54:42 +00:00
|
|
|
const { t } = useTranslation("common");
|
2020-09-08 17:20:29 +00:00
|
|
|
const httpClient = useContext(HttpClientContext)!;
|
|
|
|
const realmLoader = async () => {
|
2020-09-15 19:44:28 +00:00
|
|
|
const response = await httpClient.doGet<RealmRepresentation[]>(
|
|
|
|
"/admin/realms"
|
|
|
|
);
|
2020-09-08 17:20:29 +00:00
|
|
|
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}
|
|
|
|
>
|
2020-09-21 12:54:42 +00:00
|
|
|
{t(title)}
|
2020-09-09 09:07:17 +00:00
|
|
|
</NavItem>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-08-04 12:59:41 +00:00
|
|
|
return (
|
2020-09-17 11:37:30 +00:00
|
|
|
<DataLoader loader={realmLoader}>
|
|
|
|
{(realmList) => (
|
|
|
|
<PageSidebar
|
|
|
|
nav={
|
|
|
|
<Nav onSelect={onSelect}>
|
|
|
|
<NavList>
|
|
|
|
<NavItem className="keycloak__page_nav__nav_item__realm-selector">
|
|
|
|
<RealmSelector realmList={realmList || []} />
|
|
|
|
</NavItem>
|
|
|
|
</NavList>
|
2020-09-21 12:54:42 +00:00
|
|
|
<NavGroup title={t("manage")}>
|
|
|
|
{makeNavItem("clients", "clients")}
|
|
|
|
{makeNavItem("clientScopes", "client-scopes")}
|
|
|
|
{makeNavItem("realmRoles", "realm-roles")}
|
|
|
|
{makeNavItem("users", "users")}
|
|
|
|
{makeNavItem("groups", "groups")}
|
|
|
|
{makeNavItem("sessions", "sessions")}
|
|
|
|
{makeNavItem("events", "events")}
|
2020-09-17 11:37:30 +00:00
|
|
|
</NavGroup>
|
2020-09-09 09:07:17 +00:00
|
|
|
|
2020-09-21 12:54:42 +00:00
|
|
|
<NavGroup title={t("configure")}>
|
|
|
|
{makeNavItem("realmSettings", "realm-settings")}
|
|
|
|
{makeNavItem("authentication", "authentication")}
|
|
|
|
{makeNavItem("identityProviders", "identity-providers")}
|
|
|
|
{makeNavItem("userFederation", "user-federation")}
|
2020-09-17 11:37:30 +00:00
|
|
|
</NavGroup>
|
|
|
|
</Nav>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</DataLoader>
|
2020-08-04 12:59:41 +00:00
|
|
|
);
|
|
|
|
};
|