2020-09-14 18:10:54 +00:00
|
|
|
import {
|
2023-01-20 14:28:32 +00:00
|
|
|
Divider,
|
2020-09-14 18:10:54 +00:00
|
|
|
Nav,
|
|
|
|
NavGroup,
|
2023-01-20 14:28:32 +00:00
|
|
|
NavItem,
|
2020-09-14 18:10:54 +00:00
|
|
|
NavList,
|
|
|
|
PageSidebar,
|
|
|
|
} from "@patternfly/react-core";
|
2023-01-20 14:28:32 +00:00
|
|
|
import { FormEvent } from "react";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { NavLink, useMatch, useNavigate } from "react-router-dom";
|
2021-04-08 19:20:35 +00:00
|
|
|
|
2020-09-01 14:51:59 +00:00
|
|
|
import { RealmSelector } from "./components/realm-selector/RealmSelector";
|
2020-10-21 11:31:41 +00:00
|
|
|
import { useAccess } from "./context/access/Access";
|
2023-01-20 14:28:32 +00:00
|
|
|
import { useRealm } from "./context/realm-context/RealmContext";
|
2021-07-22 07:13:35 +00:00
|
|
|
import { AddRealmRoute } from "./realm/routes/AddRealm";
|
2023-01-20 14:28:32 +00:00
|
|
|
import { routes } from "./route-config";
|
2020-08-04 12:59:41 +00:00
|
|
|
|
2022-08-24 08:41:54 +00:00
|
|
|
import "./page-nav.css";
|
|
|
|
|
2023-01-20 14:28:32 +00:00
|
|
|
export const PageNav = () => {
|
2020-09-21 12:54:42 +00:00
|
|
|
const { t } = useTranslation("common");
|
2020-10-21 11:31:41 +00:00
|
|
|
const { hasAccess, hasSomeAccess } = useAccess();
|
2021-01-12 12:39:37 +00:00
|
|
|
const { realm } = useRealm();
|
2022-08-16 13:09:14 +00:00
|
|
|
const navigate = useNavigate();
|
2020-09-09 09:07:17 +00:00
|
|
|
|
|
|
|
type SelectedItem = {
|
|
|
|
groupId: number | string;
|
|
|
|
itemId: number | string;
|
|
|
|
to: string;
|
2022-08-03 12:12:07 +00:00
|
|
|
event: FormEvent<HTMLInputElement>;
|
2020-09-09 09:07:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const onSelect = (item: SelectedItem) => {
|
2022-08-16 13:09:14 +00:00
|
|
|
navigate(item.to);
|
2020-09-09 09:07:17 +00:00
|
|
|
item.event.preventDefault();
|
|
|
|
};
|
|
|
|
|
2020-10-21 11:31:41 +00:00
|
|
|
type LeftNavProps = { title: string; path: string };
|
|
|
|
const LeftNav = ({ title, path }: LeftNavProps) => {
|
2021-07-21 09:20:32 +00:00
|
|
|
const route = routes.find(
|
2021-03-05 10:42:06 +00:00
|
|
|
(route) => route.path.replace(/\/:.+?(\?|(?:(?!\/).)*|$)/g, "") === path
|
2021-01-05 19:49:33 +00:00
|
|
|
);
|
2021-08-09 20:20:49 +00:00
|
|
|
|
|
|
|
const accessAllowed =
|
|
|
|
route &&
|
|
|
|
(route.access instanceof Array
|
|
|
|
? hasAccess(...route.access)
|
|
|
|
: hasAccess(route.access));
|
|
|
|
|
|
|
|
if (!accessAllowed) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-09-09 09:07:17 +00:00
|
|
|
return (
|
2022-07-06 12:22:52 +00:00
|
|
|
<li>
|
|
|
|
<NavLink
|
|
|
|
id={"nav-item" + path.replace("/", "-")}
|
|
|
|
to={`/${realm}${path}`}
|
2023-01-11 14:49:03 +00:00
|
|
|
className={({ isActive }) =>
|
|
|
|
`pf-c-nav__link${isActive ? " pf-m-current" : ""}`
|
2022-07-06 12:22:52 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
{t(title)}
|
|
|
|
</NavLink>
|
|
|
|
</li>
|
2020-09-09 09:07:17 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-10-21 11:31:41 +00:00
|
|
|
const showManage = hasSomeAccess(
|
|
|
|
"view-realm",
|
|
|
|
"query-groups",
|
|
|
|
"query-users",
|
2020-10-28 18:17:15 +00:00
|
|
|
"query-clients",
|
2020-10-21 11:31:41 +00:00
|
|
|
"view-events"
|
|
|
|
);
|
|
|
|
|
|
|
|
const showConfigure = hasSomeAccess(
|
|
|
|
"view-realm",
|
|
|
|
"query-clients",
|
|
|
|
"view-identity-providers"
|
|
|
|
);
|
|
|
|
|
2023-01-11 14:49:03 +00:00
|
|
|
const isOnAddRealm = !!useMatch(AddRealmRoute.path);
|
2021-02-09 12:32:41 +00:00
|
|
|
|
2020-08-04 12:59:41 +00:00
|
|
|
return (
|
2020-11-12 19:08:09 +00:00
|
|
|
<PageSidebar
|
2022-08-24 08:41:54 +00:00
|
|
|
className="keycloak__page_nav__nav"
|
2020-11-12 19:08:09 +00:00
|
|
|
nav={
|
|
|
|
<Nav onSelect={onSelect}>
|
|
|
|
<NavList>
|
2021-05-03 16:44:47 +00:00
|
|
|
<NavItem className="keycloak__page_nav__nav_item__realm-selector">
|
|
|
|
<RealmSelector />
|
|
|
|
</NavItem>
|
2020-11-12 19:08:09 +00:00
|
|
|
</NavList>
|
2021-08-17 12:50:31 +00:00
|
|
|
<Divider />
|
2021-07-22 07:13:35 +00:00
|
|
|
{showManage && !isOnAddRealm && (
|
2021-08-17 12:50:31 +00:00
|
|
|
<NavGroup aria-label={t("manage")} title={t("manage")}>
|
2020-11-12 19:08:09 +00:00
|
|
|
<LeftNav title="clients" path="/clients" />
|
|
|
|
<LeftNav title="clientScopes" path="/client-scopes" />
|
|
|
|
<LeftNav title="realmRoles" path="/roles" />
|
|
|
|
<LeftNav title="users" path="/users" />
|
|
|
|
<LeftNav title="groups" path="/groups" />
|
|
|
|
<LeftNav title="sessions" path="/sessions" />
|
|
|
|
<LeftNav title="events" path="/events" />
|
|
|
|
</NavGroup>
|
|
|
|
)}
|
2020-09-09 09:07:17 +00:00
|
|
|
|
2021-07-22 07:13:35 +00:00
|
|
|
{showConfigure && !isOnAddRealm && (
|
2021-08-17 12:50:31 +00:00
|
|
|
<NavGroup aria-label={t("configure")} title={t("configure")}>
|
2020-11-12 19:08:09 +00:00
|
|
|
<LeftNav title="realmSettings" path="/realm-settings" />
|
|
|
|
<LeftNav title="authentication" path="/authentication" />
|
|
|
|
<LeftNav title="identityProviders" path="/identity-providers" />
|
|
|
|
<LeftNav title="userFederation" path="/user-federation" />
|
|
|
|
</NavGroup>
|
|
|
|
)}
|
|
|
|
</Nav>
|
|
|
|
}
|
|
|
|
/>
|
2020-08-04 12:59:41 +00:00
|
|
|
);
|
|
|
|
};
|