Use new routing conventions for groups routes (#913)

This commit is contained in:
Jon Koops 2021-07-26 15:40:23 +02:00 committed by GitHub
parent eb382b5fa7
commit 9410b89ed4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 21 deletions

7
src/groups/routes.ts Normal file
View file

@ -0,0 +1,7 @@
import type { RouteDef } from "../route-config";
import { GroupsRoute } from "./routes/Groups";
import { GroupsSearchRoute } from "./routes/GroupsSearch";
const routes: RouteDef[] = [GroupsSearchRoute, GroupsRoute];
export default routes;

View file

@ -0,0 +1,19 @@
import type { LocationDescriptorObject } from "history";
import { generatePath } from "react-router-dom";
import type { RouteDef } from "../../route-config";
import { GroupsSection } from "../GroupsSection";
export type GroupsParams = { realm: string };
export const GroupsRoute: RouteDef = {
path: "/:realm/groups",
component: GroupsSection,
access: "query-groups",
matchOptions: {
exact: false,
},
};
export const toGroups = (params: GroupsParams): LocationDescriptorObject => ({
pathname: generatePath(GroupsRoute.path, params),
});

View file

@ -0,0 +1,19 @@
import type { LocationDescriptorObject } from "history";
import { generatePath } from "react-router-dom";
import type { RouteDef } from "../../route-config";
import { SearchGroups } from "../SearchGroups";
export type GroupsSearchParams = { realm: string };
export const GroupsSearchRoute: RouteDef = {
path: "/:realm/groups/search",
component: SearchGroups,
breadcrumb: (t) => t("groups:searchGroups"),
access: "query-groups",
};
export const toGroupsSearch = (
params: GroupsSearchParams
): LocationDescriptorObject => ({
pathname: generatePath(GroupsSearchRoute.path, params),
});

View file

@ -7,8 +7,7 @@ import clientScopesRoutes from "./client-scopes/routes";
import clientRoutes from "./clients/routes";
import dashboardRoutes from "./dashboard/routes";
import eventRoutes from "./events/routes";
import { GroupsSection } from "./groups/GroupsSection";
import { SearchGroups } from "./groups/SearchGroups";
import groupsRoutes from "./groups/routes";
import identityProviders from "./identity-providers/routes";
import { PageNotFoundSection } from "./PageNotFoundSection";
import realmRoleRoutes from "./realm-roles/routes";
@ -26,6 +25,12 @@ export type RouteDef = {
matchOptions?: MatchOptions;
};
const NotFoundRoute: RouteDef = {
path: "*",
component: PageNotFoundSection,
access: "anyone",
};
export const routes: RouteDef[] = [
...authenticationRoutes,
...clientRoutes,
@ -39,23 +44,6 @@ export const routes: RouteDef[] = [
...userFederationRoutes,
...userRoutes,
...dashboardRoutes,
{
path: "/:realm/groups/search",
component: SearchGroups,
breadcrumb: (t) => t("groups:searchGroups"),
access: "query-groups",
},
{
path: "/:realm/groups",
component: GroupsSection,
access: "query-groups",
matchOptions: {
exact: false,
},
},
{
path: "*",
component: PageNotFoundSection,
access: "anyone",
},
...groupsRoutes,
NotFoundRoute,
];