Lazy load user tabs component to prevent circular dependencies (#1432)

This commit is contained in:
Jon Koops 2021-10-27 16:15:30 +02:00 committed by GitHub
parent d0c6bc4cc1
commit 6cf586f447
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 8 deletions

View file

@ -1,5 +1,5 @@
import React, { FunctionComponent } from "react";
import { Page } from "@patternfly/react-core";
import React, { FunctionComponent, Suspense } from "react";
import { Page, Spinner } from "@patternfly/react-core";
import { HashRouter as Router, Route, Switch } from "react-router-dom";
import { ErrorBoundary } from "react-error-boundary";
@ -60,7 +60,13 @@ const SecuredRoute = ({ route }: SecuredRouteProps) => {
? hasAccess(...route.access)
: hasAccess(route.access);
if (accessAllowed) return <route.component />;
if (accessAllowed) {
return (
<Suspense fallback={<Spinner />}>
<route.component />
</Suspense>
);
}
return <ForbiddenSection />;
};

View file

@ -28,7 +28,7 @@ import { toUsers } from "./routes/Users";
import { UserRoleMapping } from "./UserRoleMapping";
import { UserAttributes } from "./UserAttributes";
export const UsersTabs = () => {
const UsersTabs = () => {
const { t } = useTranslation("users");
const { addAlert, addError } = useAlerts();
const history = useHistory();
@ -225,3 +225,5 @@ export const UsersTabs = () => {
</>
);
};
export default UsersTabs;

View file

@ -1,13 +1,13 @@
import type { LocationDescriptorObject } from "history";
import { lazy } from "react";
import { generatePath } from "react-router-dom";
import type { RouteDef } from "../../route-config";
import { UsersTabs } from "../UsersTabs";
export type AddUserParams = { realm: string };
export const AddUserRoute: RouteDef = {
path: "/:realm/users/add-user",
component: UsersTabs,
component: lazy(() => import("../UsersTabs")),
breadcrumb: (t) => t("users:createUser"),
access: "manage-users",
};

View file

@ -1,7 +1,7 @@
import type { LocationDescriptorObject } from "history";
import { lazy } from "react";
import { generatePath } from "react-router-dom";
import type { RouteDef } from "../../route-config";
import { UsersTabs } from "../UsersTabs";
export type UserTab = "settings" | "groups" | "consents" | "attributes";
@ -13,7 +13,7 @@ export type UserParams = {
export const UserRoute: RouteDef = {
path: "/:realm/users/:id/:tab",
component: UsersTabs,
component: lazy(() => import("../UsersTabs")),
breadcrumb: (t) => t("users:userDetails"),
access: "manage-users",
};