Lazy load user tabs component to prevent circular dependencies (#1432)
This commit is contained in:
parent
d0c6bc4cc1
commit
6cf586f447
4 changed files with 16 additions and 8 deletions
12
src/App.tsx
12
src/App.tsx
|
@ -1,5 +1,5 @@
|
||||||
import React, { FunctionComponent } from "react";
|
import React, { FunctionComponent, Suspense } from "react";
|
||||||
import { Page } from "@patternfly/react-core";
|
import { Page, Spinner } from "@patternfly/react-core";
|
||||||
import { HashRouter as Router, Route, Switch } from "react-router-dom";
|
import { HashRouter as Router, Route, Switch } from "react-router-dom";
|
||||||
import { ErrorBoundary } from "react-error-boundary";
|
import { ErrorBoundary } from "react-error-boundary";
|
||||||
|
|
||||||
|
@ -60,7 +60,13 @@ const SecuredRoute = ({ route }: SecuredRouteProps) => {
|
||||||
? hasAccess(...route.access)
|
? hasAccess(...route.access)
|
||||||
: hasAccess(route.access);
|
: hasAccess(route.access);
|
||||||
|
|
||||||
if (accessAllowed) return <route.component />;
|
if (accessAllowed) {
|
||||||
|
return (
|
||||||
|
<Suspense fallback={<Spinner />}>
|
||||||
|
<route.component />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return <ForbiddenSection />;
|
return <ForbiddenSection />;
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,7 +28,7 @@ import { toUsers } from "./routes/Users";
|
||||||
import { UserRoleMapping } from "./UserRoleMapping";
|
import { UserRoleMapping } from "./UserRoleMapping";
|
||||||
import { UserAttributes } from "./UserAttributes";
|
import { UserAttributes } from "./UserAttributes";
|
||||||
|
|
||||||
export const UsersTabs = () => {
|
const UsersTabs = () => {
|
||||||
const { t } = useTranslation("users");
|
const { t } = useTranslation("users");
|
||||||
const { addAlert, addError } = useAlerts();
|
const { addAlert, addError } = useAlerts();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
@ -225,3 +225,5 @@ export const UsersTabs = () => {
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default UsersTabs;
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import type { LocationDescriptorObject } from "history";
|
import type { LocationDescriptorObject } from "history";
|
||||||
|
import { lazy } from "react";
|
||||||
import { generatePath } from "react-router-dom";
|
import { generatePath } from "react-router-dom";
|
||||||
import type { RouteDef } from "../../route-config";
|
import type { RouteDef } from "../../route-config";
|
||||||
import { UsersTabs } from "../UsersTabs";
|
|
||||||
|
|
||||||
export type AddUserParams = { realm: string };
|
export type AddUserParams = { realm: string };
|
||||||
|
|
||||||
export const AddUserRoute: RouteDef = {
|
export const AddUserRoute: RouteDef = {
|
||||||
path: "/:realm/users/add-user",
|
path: "/:realm/users/add-user",
|
||||||
component: UsersTabs,
|
component: lazy(() => import("../UsersTabs")),
|
||||||
breadcrumb: (t) => t("users:createUser"),
|
breadcrumb: (t) => t("users:createUser"),
|
||||||
access: "manage-users",
|
access: "manage-users",
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type { LocationDescriptorObject } from "history";
|
import type { LocationDescriptorObject } from "history";
|
||||||
|
import { lazy } from "react";
|
||||||
import { generatePath } from "react-router-dom";
|
import { generatePath } from "react-router-dom";
|
||||||
import type { RouteDef } from "../../route-config";
|
import type { RouteDef } from "../../route-config";
|
||||||
import { UsersTabs } from "../UsersTabs";
|
|
||||||
|
|
||||||
export type UserTab = "settings" | "groups" | "consents" | "attributes";
|
export type UserTab = "settings" | "groups" | "consents" | "attributes";
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ export type UserParams = {
|
||||||
|
|
||||||
export const UserRoute: RouteDef = {
|
export const UserRoute: RouteDef = {
|
||||||
path: "/:realm/users/:id/:tab",
|
path: "/:realm/users/:id/:tab",
|
||||||
component: UsersTabs,
|
component: lazy(() => import("../UsersTabs")),
|
||||||
breadcrumb: (t) => t("users:userDetails"),
|
breadcrumb: (t) => t("users:userDetails"),
|
||||||
access: "manage-users",
|
access: "manage-users",
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue