From 9410b89ed4ce397d3a1e2e31e041aae77f075245 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Mon, 26 Jul 2021 15:40:23 +0200 Subject: [PATCH] Use new routing conventions for groups routes (#913) --- src/groups/routes.ts | 7 +++++++ src/groups/routes/Groups.tsx | 19 +++++++++++++++++++ src/groups/routes/GroupsSearch.tsx | 19 +++++++++++++++++++ src/route-config.ts | 30 +++++++++--------------------- 4 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 src/groups/routes.ts create mode 100644 src/groups/routes/Groups.tsx create mode 100644 src/groups/routes/GroupsSearch.tsx diff --git a/src/groups/routes.ts b/src/groups/routes.ts new file mode 100644 index 0000000000..233b592f91 --- /dev/null +++ b/src/groups/routes.ts @@ -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; diff --git a/src/groups/routes/Groups.tsx b/src/groups/routes/Groups.tsx new file mode 100644 index 0000000000..84b1057f77 --- /dev/null +++ b/src/groups/routes/Groups.tsx @@ -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), +}); diff --git a/src/groups/routes/GroupsSearch.tsx b/src/groups/routes/GroupsSearch.tsx new file mode 100644 index 0000000000..d8be74dbd7 --- /dev/null +++ b/src/groups/routes/GroupsSearch.tsx @@ -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), +}); diff --git a/src/route-config.ts b/src/route-config.ts index 50e35b46eb..4dba0081e3 100644 --- a/src/route-config.ts +++ b/src/route-config.ts @@ -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, ];