8000 check for feature flags in Root.tsx's mapRoutes function by DevDuki · Pull Request #38816 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

check for feature flags in Root.tsx's mapRoutes function #38816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions js/apps/account-ui/src/root/Root.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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:
Expand All @@ -28,6 +41,7 @@ function mapRoutes(content: MenuItem[]): RouteObject[] {
: undefined,
};
})
.filter((item) => !!item)
.flat();
}

Expand All @@ -49,7 +63,7 @@ export const Root = () => {
</Page>
),
errorElement: <ErrorPage />,
children: mapRoutes(content),
children: mapRoutes(context, content),
},
]);
},
Expand Down
Loading
0