1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-31 13:47:02 +02:00

chore: clean up frontend routes (#9533)

This commit is contained in:
David Leek 2025-03-14 08:18:01 +01:00 committed by GitHub
parent 0d0530b61c
commit 8ab1a49294
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 38 additions and 102 deletions

View File

@ -115,11 +115,7 @@ export const CommandBar = () => {
const [value, setValue] = useState<string>(''); const [value, setValue] = useState<string>('');
const { routes } = useRoutes(); const { routes } = useRoutes();
const allRoutes: Record<string, IPageRouteInfo> = {}; const allRoutes: Record<string, IPageRouteInfo> = {};
for (const route of [ for (const route of [...routes.mainNavRoutes, ...routes.adminRoutes]) {
...routes.mainNavRoutes,
...routes.adminRoutes,
...routes.mobileRoutes,
]) {
allRoutes[route.path] = { allRoutes[route.path] = {
path: route.path, path: route.path,
route: route.route, route: route.route,

View File

@ -1,18 +1,15 @@
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { getCondensedRoutes, getRoutes } from 'component/menu/routes'; import { getNavRoutes } from 'component/menu/routes';
import { useAdminRoutes } from 'component/admin/useAdminRoutes'; import { useAdminRoutes } from 'component/admin/useAdminRoutes';
import { filterByConfig, mapRouteLink } from 'component/common/util'; import { filterByConfig, mapRouteLink } from 'component/common/util';
export const useRoutes = () => { export const useRoutes = () => {
const { uiConfig } = useUiConfig(); const { uiConfig } = useUiConfig();
const routes = getRoutes(); const routes = getNavRoutes();
const adminRoutes = useAdminRoutes(); const adminRoutes = useAdminRoutes();
const filteredMainRoutes = { const filteredMainRoutes = {
mainNavRoutes: getCondensedRoutes(routes.mainNavRoutes) mainNavRoutes: routes
.filter(filterByConfig(uiConfig))
.map(mapRouteLink),
mobileRoutes: getCondensedRoutes(routes.mobileRoutes)
.filter(filterByConfig(uiConfig)) .filter(filterByConfig(uiConfig))
.map(mapRouteLink), .map(mapRouteLink),
adminRoutes, adminRoutes,

View File

@ -3,7 +3,6 @@ import { Link } from 'react-router-dom';
import { Divider, Drawer, styled } from '@mui/material'; import { Divider, Drawer, styled } from '@mui/material';
import { ReactComponent as UnleashLogo } from 'assets/img/logoDarkWithText.svg'; import { ReactComponent as UnleashLogo } from 'assets/img/logoDarkWithText.svg';
import { ReactComponent as UnleashLogoWhite } from 'assets/img/logoWithWhiteText.svg'; import { ReactComponent as UnleashLogoWhite } from 'assets/img/logoWithWhiteText.svg';
import type { INavigationMenuItem } from 'interfaces/route';
import styles from './DrawerMenu.module.scss'; // FIXME: useStyle - theme import styles from './DrawerMenu.module.scss'; // FIXME: useStyle - theme
import theme from 'themes/theme'; import theme from 'themes/theme';
import { ThemeMode } from 'component/common/ThemeMode/ThemeMode'; import { ThemeMode } from 'component/common/ThemeMode/ThemeMode';
@ -32,18 +31,12 @@ interface IDrawerMenuProps {
href: string; href: string;
title: string; title: string;
}>; }>;
routes: {
mainNavRoutes: INavigationMenuItem[];
mobileRoutes: INavigationMenuItem[];
adminRoutes: INavigationMenuItem[];
};
} }
export const DrawerMenu: VFC<IDrawerMenuProps> = ({ export const DrawerMenu: VFC<IDrawerMenuProps> = ({
links = [], links = [],
open = false, open = false,
toggleDrawer, toggleDrawer,
routes,
}) => { }) => {
return ( return (
<Drawer <Drawer

View File

@ -21,13 +21,10 @@ import { ReactComponent as CelebatoryUnleashLogo } from 'assets/img/unleashHolid
import { DrawerMenu } from './DrawerMenu/DrawerMenu'; import { DrawerMenu } from './DrawerMenu/DrawerMenu';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { focusable } from 'themes/themeStyles'; import { focusable } from 'themes/themeStyles';
import { getCondensedRoutes, getRoutes } from 'component/menu/routes';
import DarkModeOutlined from '@mui/icons-material/DarkModeOutlined'; import DarkModeOutlined from '@mui/icons-material/DarkModeOutlined';
import LightModeOutlined from '@mui/icons-material/LightModeOutlined'; import LightModeOutlined from '@mui/icons-material/LightModeOutlined';
import { filterByConfig, mapRouteLink } from 'component/common/util';
import { useThemeMode } from 'hooks/useThemeMode'; import { useThemeMode } from 'hooks/useThemeMode';
import { Notifications } from 'component/common/Notifications/Notifications'; import { Notifications } from 'component/common/Notifications/Notifications';
import { useAdminRoutes } from 'component/admin/useAdminRoutes';
import InviteLinkButton from './InviteLink/InviteLinkButton/InviteLinkButton'; import InviteLinkButton from './InviteLink/InviteLinkButton/InviteLinkButton';
import { useUiFlag } from 'hooks/useUiFlag'; import { useUiFlag } from 'hooks/useUiFlag';
import { CommandBar } from 'component/commandBar/CommandBar'; import { CommandBar } from 'component/commandBar/CommandBar';
@ -105,19 +102,6 @@ const Header = () => {
const toggleDrawer = () => setOpenDrawer((prev) => !prev); const toggleDrawer = () => setOpenDrawer((prev) => !prev);
const celebatoryUnleash = useUiFlag('celebrateUnleash'); const celebatoryUnleash = useUiFlag('celebrateUnleash');
const routes = getRoutes();
const adminRoutes = useAdminRoutes();
const filteredMainRoutes = {
mainNavRoutes: getCondensedRoutes(routes.mainNavRoutes)
.filter(filterByConfig(uiConfig))
.map(mapRouteLink),
mobileRoutes: getCondensedRoutes(routes.mobileRoutes)
.filter(filterByConfig(uiConfig))
.map(mapRouteLink),
adminRoutes,
};
if (smallScreen) { if (smallScreen) {
return ( return (
<HeaderComponent position='static'> <HeaderComponent position='static'>
@ -139,7 +123,6 @@ const Header = () => {
links={uiConfig.links} links={uiConfig.links}
open={openDrawer} open={openDrawer}
toggleDrawer={toggleDrawer} toggleDrawer={toggleDrawer}
routes={filteredMainRoutes}
/> />
<StyledUserContainer> <StyledUserContainer>
<UserProfile /> <UserProfile />

View File

@ -12,9 +12,7 @@ exports[`returns all baseRoutes 1`] = `
}, },
{ {
"component": [Function], "component": [Function],
"menu": { "menu": {},
"mobile": true,
},
"path": "/personal", "path": "/personal",
"title": "Dashboard", "title": "Dashboard",
"type": "protected", "type": "protected",
@ -92,9 +90,7 @@ exports[`returns all baseRoutes 1`] = `
}, },
{ {
"component": [Function], "component": [Function],
"menu": { "menu": {},
"mobile": true,
},
"path": "/projects", "path": "/projects",
"title": "Projects", "title": "Projects",
"type": "protected", "type": "protected",
@ -108,9 +104,7 @@ exports[`returns all baseRoutes 1`] = `
}, },
{ {
"component": [Function], "component": [Function],
"menu": { "menu": {},
"mobile": true,
},
"path": "/search", "path": "/search",
"title": "Search", "title": "Search",
"type": "protected", "type": "protected",
@ -125,9 +119,7 @@ exports[`returns all baseRoutes 1`] = `
}, },
}, },
"hidden": false, "hidden": false,
"menu": { "menu": {},
"mobile": true,
},
"path": "/playground", "path": "/playground",
"title": "Playground", "title": "Playground",
"type": "protected", "type": "protected",
@ -135,9 +127,7 @@ exports[`returns all baseRoutes 1`] = `
{ {
"component": [Function], "component": [Function],
"enterprise": true, "enterprise": true,
"menu": { "menu": {},
"mobile": true,
},
"path": "/insights", "path": "/insights",
"title": "Insights", "title": "Insights",
"type": "protected", "type": "protected",
@ -153,8 +143,7 @@ exports[`returns all baseRoutes 1`] = `
{ {
"component": [Function], "component": [Function],
"menu": { "menu": {
"advanced": true, "main": true,
"mobile": true,
}, },
"path": "/applications", "path": "/applications",
"title": "Applications", "title": "Applications",
@ -179,8 +168,7 @@ exports[`returns all baseRoutes 1`] = `
{ {
"component": [Function], "component": [Function],
"menu": { "menu": {
"advanced": true, "main": true,
"mobile": true,
}, },
"path": "/context", "path": "/context",
"title": "Context fields", "title": "Context fields",
@ -189,8 +177,7 @@ exports[`returns all baseRoutes 1`] = `
{ {
"component": [Function], "component": [Function],
"menu": { "menu": {
"advanced": true, "main": true,
"mobile": true,
}, },
"path": "/feature-toggle-type/*", "path": "/feature-toggle-type/*",
"title": "Feature flag types", "title": "Feature flag types",
@ -223,8 +210,7 @@ exports[`returns all baseRoutes 1`] = `
{ {
"component": [Function], "component": [Function],
"menu": { "menu": {
"advanced": true, "main": true,
"mobile": true,
}, },
"path": "/strategies", "path": "/strategies",
"title": "Strategy types", "title": "Strategy types",
@ -249,8 +235,7 @@ exports[`returns all baseRoutes 1`] = `
"component": [Function], "component": [Function],
"enterprise": true, "enterprise": true,
"menu": { "menu": {
"advanced": true, "main": true,
"mobile": true,
}, },
"path": "/environments", "path": "/environments",
"title": "Environments", "title": "Environments",
@ -268,7 +253,7 @@ exports[`returns all baseRoutes 1`] = `
"component": [Function], "component": [Function],
"flag": "releasePlans", "flag": "releasePlans",
"menu": { "menu": {
"advanced": true, "main": true,
"mode": [ "mode": [
"enterprise", "enterprise",
], ],
@ -324,8 +309,7 @@ exports[`returns all baseRoutes 1`] = `
{ {
"component": [Function], "component": [Function],
"menu": { "menu": {
"advanced": true, "main": true,
"mobile": true,
}, },
"path": "/tag-types", "path": "/tag-types",
"title": "Tag types", "title": "Tag types",
@ -383,8 +367,7 @@ exports[`returns all baseRoutes 1`] = `
"component": [Function], "component": [Function],
"hidden": false, "hidden": false,
"menu": { "menu": {
"advanced": true, "main": true,
"mobile": true,
}, },
"path": "/integrations", "path": "/integrations",
"title": "Integrations", "title": "Integrations",
@ -412,8 +395,7 @@ exports[`returns all baseRoutes 1`] = `
"component": [Function], "component": [Function],
"hidden": false, "hidden": false,
"menu": { "menu": {
"advanced": true, "main": true,
"mobile": true,
}, },
"path": "/segments", "path": "/segments",
"title": "Segments", "title": "Segments",

View File

@ -68,7 +68,7 @@ export const routes: IRoute[] = [
title: 'Dashboard', title: 'Dashboard',
component: PersonalDashboard, component: PersonalDashboard,
type: 'protected', type: 'protected',
menu: { mobile: true }, menu: {},
}, },
// Project // Project
@ -127,7 +127,7 @@ export const routes: IRoute[] = [
title: 'Projects', title: 'Projects',
component: ProjectList, component: ProjectList,
type: 'protected', type: 'protected',
menu: { mobile: true }, menu: {},
}, },
{ {
path: '/projects-archive', path: '/projects-archive',
@ -143,7 +143,7 @@ export const routes: IRoute[] = [
title: 'Search', title: 'Search',
component: FeatureToggleListTable, component: FeatureToggleListTable,
type: 'protected', type: 'protected',
menu: { mobile: true }, menu: {},
}, },
// Playground // Playground
@ -153,7 +153,7 @@ export const routes: IRoute[] = [
component: LazyPlayground, component: LazyPlayground,
hidden: false, hidden: false,
type: 'protected', type: 'protected',
menu: { mobile: true }, menu: {},
}, },
// Insights // Insights
@ -162,7 +162,7 @@ export const routes: IRoute[] = [
title: 'Insights', title: 'Insights',
component: Insights, component: Insights,
type: 'protected', type: 'protected',
menu: { mobile: true }, menu: {},
enterprise: true, enterprise: true,
}, },
@ -180,7 +180,7 @@ export const routes: IRoute[] = [
title: 'Applications', title: 'Applications',
component: PaginatedApplicationList, component: PaginatedApplicationList,
type: 'protected', type: 'protected',
menu: { mobile: true, advanced: true }, menu: { main: true },
}, },
// Context // Context
@ -205,7 +205,7 @@ export const routes: IRoute[] = [
title: 'Context fields', title: 'Context fields',
component: ContextList, component: ContextList,
type: 'protected', type: 'protected',
menu: { mobile: true, advanced: true }, menu: { main: true },
}, },
// Feature types // Feature types
@ -214,7 +214,7 @@ export const routes: IRoute[] = [
title: 'Feature flag types', title: 'Feature flag types',
component: FeatureTypesList, component: FeatureTypesList,
type: 'protected', type: 'protected',
menu: { mobile: true, advanced: true }, menu: { main: true },
}, },
// Strategies // Strategies
@ -247,7 +247,7 @@ export const routes: IRoute[] = [
title: 'Strategy types', title: 'Strategy types',
component: StrategiesList, component: StrategiesList,
type: 'protected', type: 'protected',
menu: { mobile: true, advanced: true }, menu: { main: true },
}, },
{ {
path: '/environments/create', path: '/environments/create',
@ -269,7 +269,7 @@ export const routes: IRoute[] = [
title: 'Environments', title: 'Environments',
component: EnvironmentTable, component: EnvironmentTable,
type: 'protected', type: 'protected',
menu: { mobile: true, advanced: true }, menu: { main: true },
enterprise: true, enterprise: true,
}, },
{ {
@ -287,7 +287,7 @@ export const routes: IRoute[] = [
title: 'Release management', title: 'Release management',
component: ReleaseManagement, component: ReleaseManagement,
type: 'protected', type: 'protected',
menu: { advanced: true, mode: ['enterprise'] }, menu: { main: true, mode: ['enterprise'] },
flag: 'releasePlans', flag: 'releasePlans',
}, },
{ {
@ -333,7 +333,7 @@ export const routes: IRoute[] = [
title: 'Tag types', title: 'Tag types',
component: TagTypeList, component: TagTypeList,
type: 'protected', type: 'protected',
menu: { mobile: true, advanced: true }, menu: { main: true },
}, },
// Integrations // Integrations
@ -391,7 +391,7 @@ export const routes: IRoute[] = [
component: IntegrationList, component: IntegrationList,
hidden: false, hidden: false,
type: 'protected', type: 'protected',
menu: { mobile: true, advanced: true }, menu: { main: true },
}, },
{ {
path: '/integrations/signals', path: '/integrations/signals',
@ -427,7 +427,7 @@ export const routes: IRoute[] = [
component: SegmentTable, component: SegmentTable,
hidden: false, hidden: false,
type: 'protected', type: 'protected',
menu: { mobile: true, advanced: true }, menu: { main: true },
}, },
// History // History
@ -518,24 +518,7 @@ export const routes: IRoute[] = [
export const getRoute = (path: string) => export const getRoute = (path: string) =>
routes.find((route) => route.path === path); routes.find((route) => route.path === path);
export const baseRoutes = routes.filter((route) => !route.hidden); const getCondensedRoutes = (routes: IRoute[]): INavigationMenuItem[] => {
const computeRoutes = () => {
const mainNavRoutes = baseRoutes.filter((route) => route.menu.advanced);
const adminRoutes = routes.filter((route) => route.menu.adminSettings);
const mobileRoutes = routes.filter((route) => route.menu.mobile);
const computedRoutes = {
mainNavRoutes,
adminRoutes,
mobileRoutes,
};
return () => {
return computedRoutes;
};
};
export const getCondensedRoutes = (routes: IRoute[]): INavigationMenuItem[] => {
return routes.map((route) => { return routes.map((route) => {
return { return {
path: route.path, path: route.path,
@ -549,4 +532,7 @@ export const getCondensedRoutes = (routes: IRoute[]): INavigationMenuItem[] => {
}); });
}; };
export const getRoutes = computeRoutes(); export const baseRoutes = routes.filter((route) => !route.hidden);
export const getNavRoutes = () => {
return getCondensedRoutes(baseRoutes.filter((route) => route.menu.main));
};

View File

@ -29,8 +29,7 @@ export interface INavigationMenuItem {
} }
interface IRouteMenu { interface IRouteMenu {
mobile?: boolean; main?: boolean;
advanced?: boolean;
adminSettings?: boolean; adminSettings?: boolean;
mode?: Array<'pro' | 'enterprise'>; mode?: Array<'pro' | 'enterprise'>;
billing?: boolean; billing?: boolean;