Use new routing conventions for realm routes (#890)
This commit is contained in:
parent
1860ea5b58
commit
5286eb6d5a
5 changed files with 35 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useHistory, useLocation } from "react-router-dom";
|
import { useHistory, useRouteMatch } from "react-router-dom";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
Nav,
|
Nav,
|
||||||
|
@ -13,6 +13,7 @@ import { RealmSelector } from "./components/realm-selector/RealmSelector";
|
||||||
import { useRealm } from "./context/realm-context/RealmContext";
|
import { useRealm } from "./context/realm-context/RealmContext";
|
||||||
import { useAccess } from "./context/access/Access";
|
import { useAccess } from "./context/access/Access";
|
||||||
import { routes } from "./route-config";
|
import { routes } from "./route-config";
|
||||||
|
import { AddRealmRoute } from "./realm/routes/AddRealm";
|
||||||
|
|
||||||
export const PageNav: React.FunctionComponent = () => {
|
export const PageNav: React.FunctionComponent = () => {
|
||||||
const { t } = useTranslation("common");
|
const { t } = useTranslation("common");
|
||||||
|
@ -68,8 +69,7 @@ export const PageNav: React.FunctionComponent = () => {
|
||||||
"view-identity-providers"
|
"view-identity-providers"
|
||||||
);
|
);
|
||||||
|
|
||||||
const { pathname } = useLocation();
|
const isOnAddRealm = !!useRouteMatch(AddRealmRoute.path);
|
||||||
const isOnAddRealm = () => pathname.indexOf("add-realm") === -1;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageSidebar
|
<PageSidebar
|
||||||
|
@ -80,12 +80,12 @@ export const PageNav: React.FunctionComponent = () => {
|
||||||
<RealmSelector />
|
<RealmSelector />
|
||||||
</NavItem>
|
</NavItem>
|
||||||
</NavList>
|
</NavList>
|
||||||
{isOnAddRealm() && (
|
{!isOnAddRealm && (
|
||||||
<NavGroup title="">
|
<NavGroup title="">
|
||||||
<LeftNav title="home" path="/" />
|
<LeftNav title="home" path="/" />
|
||||||
</NavGroup>
|
</NavGroup>
|
||||||
)}
|
)}
|
||||||
{showManage && isOnAddRealm() && (
|
{showManage && !isOnAddRealm && (
|
||||||
<NavGroup title={t("manage")}>
|
<NavGroup title={t("manage")}>
|
||||||
<LeftNav title="clients" path="/clients" />
|
<LeftNav title="clients" path="/clients" />
|
||||||
<LeftNav title="clientScopes" path="/client-scopes" />
|
<LeftNav title="clientScopes" path="/client-scopes" />
|
||||||
|
@ -97,7 +97,7 @@ export const PageNav: React.FunctionComponent = () => {
|
||||||
</NavGroup>
|
</NavGroup>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{showConfigure && isOnAddRealm() && (
|
{showConfigure && !isOnAddRealm && (
|
||||||
<NavGroup title={t("configure")}>
|
<NavGroup title={t("configure")}>
|
||||||
<LeftNav title="realmSettings" path="/realm-settings" />
|
<LeftNav title="realmSettings" path="/realm-settings" />
|
||||||
<LeftNav title="authentication" path="/authentication" />
|
<LeftNav title="authentication" path="/authentication" />
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { useHistory } from "react-router-dom";
|
||||||
|
|
||||||
import { useRealm } from "../../context/realm-context/RealmContext";
|
import { useRealm } from "../../context/realm-context/RealmContext";
|
||||||
import { useWhoAmI } from "../../context/whoami/WhoAmI";
|
import { useWhoAmI } from "../../context/whoami/WhoAmI";
|
||||||
|
import { toAddRealm } from "../../realm/routes/AddRealm";
|
||||||
import { toUpperCase } from "../../util";
|
import { toUpperCase } from "../../util";
|
||||||
import { RecentUsed } from "./recent-used";
|
import { RecentUsed } from "./recent-used";
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ export const RealmSelector = () => {
|
||||||
component="div"
|
component="div"
|
||||||
isBlock
|
isBlock
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
history.push(`/${realm}/add-realm`);
|
history.push(toAddRealm({ realm }));
|
||||||
setOpen(!open);
|
setOpen(!open);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
6
src/realm/routes.ts
Normal file
6
src/realm/routes.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import type { RouteDef } from "../route-config";
|
||||||
|
import { AddRealmRoute } from "./routes/AddRealm";
|
||||||
|
|
||||||
|
const routes: RouteDef[] = [AddRealmRoute];
|
||||||
|
|
||||||
|
export default routes;
|
19
src/realm/routes/AddRealm.ts
Normal file
19
src/realm/routes/AddRealm.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import type { LocationDescriptorObject } from "history";
|
||||||
|
import { generatePath } from "react-router-dom";
|
||||||
|
import type { RouteDef } from "../../route-config";
|
||||||
|
import { NewRealmForm } from "../add/NewRealmForm";
|
||||||
|
|
||||||
|
export type AddRealmParams = { realm: string };
|
||||||
|
|
||||||
|
export const AddRealmRoute: RouteDef = {
|
||||||
|
path: "/:realm/add-realm",
|
||||||
|
component: NewRealmForm,
|
||||||
|
breadcrumb: (t) => t("realm:createRealm"),
|
||||||
|
access: "manage-realm",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const toAddRealm = (
|
||||||
|
params: AddRealmParams
|
||||||
|
): LocationDescriptorObject => ({
|
||||||
|
pathname: generatePath(AddRealmRoute.path, params),
|
||||||
|
});
|
|
@ -32,7 +32,7 @@ import {
|
||||||
EditProviderCrumb,
|
EditProviderCrumb,
|
||||||
RealmSettingsSection,
|
RealmSettingsSection,
|
||||||
} from "./realm-settings/RealmSettingsSection";
|
} from "./realm-settings/RealmSettingsSection";
|
||||||
import { NewRealmForm } from "./realm/add/NewRealmForm";
|
import realmRoutes from "./realm/routes";
|
||||||
import { SessionsSection } from "./sessions/SessionsSection";
|
import { SessionsSection } from "./sessions/SessionsSection";
|
||||||
import { LdapMapperDetails } from "./user-federation/ldap/mappers/LdapMapperDetails";
|
import { LdapMapperDetails } from "./user-federation/ldap/mappers/LdapMapperDetails";
|
||||||
import { UserFederationKerberosSettings } from "./user-federation/UserFederationKerberosSettings";
|
import { UserFederationKerberosSettings } from "./user-federation/UserFederationKerberosSettings";
|
||||||
|
@ -52,12 +52,7 @@ export type RouteDef = {
|
||||||
|
|
||||||
export const routes: RouteDef[] = [
|
export const routes: RouteDef[] = [
|
||||||
...clientRoutes,
|
...clientRoutes,
|
||||||
{
|
...realmRoutes,
|
||||||
path: "/:realm/add-realm",
|
|
||||||
component: NewRealmForm,
|
|
||||||
breadcrumb: (t) => t("realm:createRealm"),
|
|
||||||
access: "manage-realm",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/:realm/clients/:clientId/roles/add-role",
|
path: "/:realm/clients/:clientId/roles/add-role",
|
||||||
component: RealmRoleTabs,
|
component: RealmRoleTabs,
|
||||||
|
|
Loading…
Reference in a new issue