Use CompatRoute for routes that can be migrated (#3113)

This commit is contained in:
Jon Koops 2022-08-16 15:08:44 +02:00 committed by GitHub
parent 7114edac73
commit d5755088f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 38 additions and 11 deletions

View file

@ -1,7 +1,11 @@
import { FunctionComponent, Suspense } from "react";
import { Page } from "@patternfly/react-core";
import { HashRouter as Router, Route, Switch } from "react-router-dom";
import { CompatRouter } from "react-router-dom-v5-compat";
import {
HashRouter as Router,
Route as LegacyRoute,
Switch,
} from "react-router-dom";
import { CompatRouter, CompatRoute } from "react-router-dom-v5-compat";
import { ErrorBoundary } from "react-error-boundary";
import type Keycloak from "keycloak-js";
import type KeycloakAdminClient from "@keycloak/keycloak-admin-client";
@ -97,7 +101,10 @@ export const App = ({ keycloak, adminClient }: AdminClientProps) => {
>
<ServerInfoProvider>
<Switch>
{routes.map((route, i) => (
{routes.map((route, i) => {
const Route = route.legacy ? LegacyRoute : CompatRoute;
return (
<Route
key={i}
path={route.path}
@ -105,7 +112,8 @@ export const App = ({ keycloak, adminClient }: AdminClientProps) => {
>
<SecuredRoute route={route} />
</Route>
))}
);
})}
</Switch>
</ServerInfoProvider>
</ErrorBoundary>

View file

@ -12,6 +12,7 @@ export const AuthenticationRoute: RouteDef = {
component: lazy(() => import("../AuthenticationSection")),
breadcrumb: (t) => t("authentication"),
access: ["view-realm", "view-identity-providers", "view-clients"],
legacy: true,
};
export const toAuthentication = (

View file

@ -15,6 +15,7 @@ export const FlowRoute: RouteDef = {
component: lazy(() => import("../FlowDetails")),
breadcrumb: (t) => t("authentication:flowDetails"),
access: "view-authorization",
legacy: true,
};
export const toFlow = (params: FlowParams): LocationDescriptorObject => ({

View file

@ -17,6 +17,7 @@ export const ClientScopeRoute: RouteDef = {
component: lazy(() => import("../form/ClientScopeForm")),
breadcrumb: (t) => t("client-scopes:clientScopeDetails"),
access: "view-clients",
legacy: true,
};
export const toClientScope = (

View file

@ -15,6 +15,7 @@ export const ClientsRoute: RouteDef = {
component: lazy(() => import("../ClientsSection")),
breadcrumb: (t) => t("clients:clientList"),
access: "query-clients",
legacy: true,
};
export const toClients = (params: ClientsParams): LocationDescriptorObject => ({

View file

@ -16,6 +16,7 @@ export const DedicatedScopeDetailsRoute: RouteDef = {
component: lazy(() => import("../scopes/DedicatedScopes")),
breadcrumb: (t) => t("clients:dedicatedScopes"),
access: "view-clients",
legacy: true,
};
export const toDedicatedScope = (

View file

@ -17,6 +17,7 @@ export const NewPermissionRoute: RouteDef = {
component: lazy(() => import("../authorization/PermissionDetails")),
breadcrumb: (t) => t("clients:createPermission"),
access: "view-clients",
legacy: true,
};
export const toNewPermission = (

View file

@ -14,6 +14,7 @@ export const ResourceDetailsRoute: RouteDef = {
component: lazy(() => import("../authorization/ResourceDetails")),
breadcrumb: (t) => t("clients:createResource"),
access: "view-clients",
legacy: true,
};
export const toResourceDetails = (

View file

@ -14,6 +14,7 @@ export const ScopeDetailsRoute: RouteDef = {
component: lazy(() => import("../authorization/ScopeDetails")),
breadcrumb: (t) => t("clients:createAuthorizationScope"),
access: "manage-clients",
legacy: true,
};
export const toScopeDetails = (

View file

@ -12,6 +12,7 @@ export const DashboardRoute: RouteDef = {
component: lazy(() => import("../Dashboard")),
breadcrumb: (t) => t("common:home"),
access: "anyone",
legacy: true,
};
export const toDashboard = (

View file

@ -15,6 +15,7 @@ export const EventsRoute: RouteDef = {
component: lazy(() => import("../EventsSection")),
breadcrumb: (t) => t("events:title"),
access: "view-events",
legacy: true,
};
export const toEvents = (params: EventsParams): LocationDescriptorObject => ({

View file

@ -12,6 +12,7 @@ export const GroupsRoute: RouteDef = {
matchOptions: {
exact: false,
},
legacy: true,
};
export const toGroups = (params: GroupsParams): LocationDescriptorObject => ({

View file

@ -21,6 +21,7 @@ export const ClientRoleRoute: RouteDef = {
component: lazy(() => import("../RealmRoleTabs")),
breadcrumb: (t) => t("roles:roleDetails"),
access: "view-realm",
legacy: true,
};
export const toClientRole = (

View file

@ -20,6 +20,7 @@ export const RealmRoleRoute: RouteDef = {
component: lazy(() => import("../RealmRoleTabs")),
breadcrumb: (t) => t("roles:roleDetails"),
access: ["view-realm", "view-users"],
legacy: true,
};
export const toRealmRole = (

View file

@ -13,6 +13,7 @@ export const NewClientPolicyConditionRoute: RouteDef = {
component: lazy(() => import("../NewClientPolicyCondition")),
breadcrumb: (t) => t("realm-settings:addCondition"),
access: "manage-clients",
legacy: true,
};
export const toNewClientPolicyCondition = (

View file

@ -14,6 +14,7 @@ export const EditClientPolicyConditionRoute: RouteDef = {
component: lazy(() => import("../NewClientPolicyCondition")),
breadcrumb: (t) => t("realm-settings:editCondition"),
access: "manage-clients",
legacy: true,
};
export const toEditClientPolicyCondition = (

View file

@ -28,6 +28,7 @@ export const RealmSettingsRoute: RouteDef = {
component: lazy(() => import("../RealmSettingsSection")),
breadcrumb: (t) => t("realmSettings"),
access: "view-realm",
legacy: true,
};
export const toRealmSettings = (

View file

@ -23,6 +23,7 @@ export type RouteDef = {
breadcrumb?: (t: TFunction) => string | ComponentType<any>;
access: AccessType | AccessType[];
matchOptions?: MatchOptions;
legacy?: boolean;
};
const NotFoundRoute: RouteDef = {

View file

@ -16,6 +16,7 @@ export const UserFederationLdapRoute: RouteDef = {
component: lazy(() => import("../UserFederationLdapSettings")),
breadcrumb: (t) => t("common:settings"),
access: "view-realm",
legacy: true,
};
export const toUserFederationLdap = (

View file

@ -12,6 +12,7 @@ export const UsersRoute: RouteDef = {
component: lazy(() => import("../UsersSection")),
breadcrumb: (t) => t("users:title"),
access: "query-users",
legacy: true,
};
export const toUsers = (params: UsersParams): LocationDescriptorObject => ({