mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-10 15:32:05 -03:30
check for feature flags in Root.tsx's mapRoutes function before adding a new menu item (#38816)
Closes #38783 Signed-off-by: Dusan Misic <dusan.misic@inventage.com> Co-authored-by: Dusan Misic <dmisic@inventage.com>
This commit is contained in:
parent
5da45a31d4
commit
be95c3553d
@ -1,4 +1,8 @@
|
||||
import { ErrorPage, useEnvironment } from "@keycloak/keycloak-ui-shared";
|
||||
import {
|
||||
ErrorPage,
|
||||
useEnvironment,
|
||||
KeycloakContext,
|
||||
} from "@keycloak/keycloak-ui-shared";
|
||||
import { Page, Spinner } from "@patternfly/react-core";
|
||||
import { Suspense, useState } from "react";
|
||||
import {
|
||||
@ -14,12 +18,21 @@ import { Header } from "./Header";
|
||||
import { MenuItem, PageNav } from "./PageNav";
|
||||
import { routes } from "../routes";
|
||||
|
||||
function mapRoutes(content: MenuItem[]): RouteObject[] {
|
||||
function mapRoutes(
|
||||
context: KeycloakContext<Environment>,
|
||||
content: MenuItem[],
|
||||
): RouteObject[] {
|
||||
return content
|
||||
.map((item) => {
|
||||
if ("children" in item) {
|
||||
return mapRoutes(item.children);
|
||||
return mapRoutes(context, item.children);
|
||||
}
|
||||
|
||||
// Do not add route disabled via feature flags
|
||||
if (item.isVisible && !context.environment.features[item.isVisible]) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
...item,
|
||||
element:
|
||||
@ -28,6 +41,7 @@ function mapRoutes(content: MenuItem[]): RouteObject[] {
|
||||
: undefined,
|
||||
};
|
||||
})
|
||||
.filter((item) => !!item)
|
||||
.flat();
|
||||
}
|
||||
|
||||
@ -49,7 +63,7 @@ export const Root = () => {
|
||||
</Page>
|
||||
),
|
||||
errorElement: <ErrorPage />,
|
||||
children: mapRoutes(content),
|
||||
children: mapRoutes(context, content),
|
||||
},
|
||||
]);
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user