ede8db53a0
* added user registration tab to realm settings * added keycloak spinner * fixed routing from all role tabs * Update src/realm-settings/RealmSettingsTabs.tsx Co-authored-by: Jenny <32821331+jenny-s51@users.noreply.github.com> * changed tab name to "associated-roles" * removed useless key attribute * removed unnessary variable * fixed pagination * rebased * fixed default role type * fixed create realm role * fixed helpItem forID * fixed test Co-authored-by: Jenny <32821331+jenny-s51@users.noreply.github.com>
108 lines
3.5 KiB
TypeScript
108 lines
3.5 KiB
TypeScript
import React, { FunctionComponent, Suspense } from "react";
|
|
import { Page } from "@patternfly/react-core";
|
|
import { HashRouter as Router, Route, Switch } from "react-router-dom";
|
|
import { ErrorBoundary } from "react-error-boundary";
|
|
|
|
import { Header } from "./PageHeader";
|
|
import { PageNav } from "./PageNav";
|
|
import { Help } from "./components/help-enabler/HelpHeader";
|
|
|
|
import { ServerInfoProvider } from "./context/server-info/ServerInfoProvider";
|
|
import { AlertProvider } from "./components/alert/Alerts";
|
|
|
|
import { AccessContextProvider, useAccess } from "./context/access/Access";
|
|
import { routes, RouteDef } from "./route-config";
|
|
import { PageBreadCrumbs } from "./components/bread-crumb/PageBreadCrumbs";
|
|
import { KeycloakSpinner } from "./components/keycloak-spinner/KeycloakSpinner";
|
|
import { ForbiddenSection } from "./ForbiddenSection";
|
|
import { SubGroups } from "./groups/SubGroupsContext";
|
|
import { RealmsProvider } from "./context/RealmsContext";
|
|
import { RealmContextProvider } from "./context/realm-context/RealmContext";
|
|
import { ErrorRenderer } from "./components/error/ErrorRenderer";
|
|
import { AdminClient } from "./context/auth/AdminClient";
|
|
import { WhoAmIContextProvider } from "./context/whoami/WhoAmI";
|
|
import type KeycloakAdminClient from "@keycloak/keycloak-admin-client";
|
|
|
|
export const mainPageContentId = "kc-main-content-page-container";
|
|
|
|
export type AdminClientProps = {
|
|
adminClient: KeycloakAdminClient;
|
|
};
|
|
|
|
const AppContexts: FunctionComponent<AdminClientProps> = ({
|
|
children,
|
|
adminClient,
|
|
}) => (
|
|
<Router>
|
|
<AdminClient.Provider value={adminClient}>
|
|
<WhoAmIContextProvider>
|
|
<RealmsProvider>
|
|
<RealmContextProvider>
|
|
<AccessContextProvider>
|
|
<Help>
|
|
<AlertProvider>
|
|
<ServerInfoProvider>
|
|
<SubGroups>{children}</SubGroups>
|
|
</ServerInfoProvider>
|
|
</AlertProvider>
|
|
</Help>
|
|
</AccessContextProvider>
|
|
</RealmContextProvider>
|
|
</RealmsProvider>
|
|
</WhoAmIContextProvider>
|
|
</AdminClient.Provider>
|
|
</Router>
|
|
);
|
|
|
|
// If someone tries to go directly to a route they don't
|
|
// have access to, show forbidden page.
|
|
type SecuredRouteProps = { route: RouteDef };
|
|
const SecuredRoute = ({ route }: SecuredRouteProps) => {
|
|
const { hasAccess } = useAccess();
|
|
const accessAllowed =
|
|
route.access instanceof Array
|
|
? hasAccess(...route.access)
|
|
: hasAccess(route.access);
|
|
|
|
if (accessAllowed)
|
|
return (
|
|
<Suspense fallback={<KeycloakSpinner />}>
|
|
<route.component />
|
|
</Suspense>
|
|
);
|
|
|
|
return <ForbiddenSection />;
|
|
};
|
|
|
|
export const App = ({ adminClient }: AdminClientProps) => {
|
|
return (
|
|
<AppContexts adminClient={adminClient}>
|
|
<Page
|
|
header={<Header />}
|
|
isManagedSidebar
|
|
sidebar={<PageNav />}
|
|
breadcrumb={<PageBreadCrumbs />}
|
|
mainContainerId={mainPageContentId}
|
|
>
|
|
<ErrorBoundary
|
|
FallbackComponent={ErrorRenderer}
|
|
onReset={() =>
|
|
(window.location.href =
|
|
window.location.origin + window.location.pathname)
|
|
}
|
|
>
|
|
<Switch>
|
|
{routes.map((route, i) => (
|
|
<Route
|
|
exact={route.matchOptions?.exact ?? true}
|
|
key={i}
|
|
path={route.path}
|
|
component={() => <SecuredRoute route={route} />}
|
|
/>
|
|
))}
|
|
</Switch>
|
|
</ErrorBoundary>
|
|
</Page>
|
|
</AppContexts>
|
|
);
|
|
};
|