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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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