From b783e89c881920e8531e78fb72ca9f1d533f6ba9 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Thu, 23 May 2024 12:44:00 +0200 Subject: [PATCH] feat: plan specific navigation (#7126) --- .../layout/MainLayout/MainLayout.tsx | 15 +- .../NavigationSidebar/NavigationSidebar.tsx | 213 ++++++++++-------- 2 files changed, 130 insertions(+), 98 deletions(-) diff --git a/frontend/src/component/layout/MainLayout/MainLayout.tsx b/frontend/src/component/layout/MainLayout/MainLayout.tsx index 29393cdbfd..879354dbb3 100644 --- a/frontend/src/component/layout/MainLayout/MainLayout.tsx +++ b/frontend/src/component/layout/MainLayout/MainLayout.tsx @@ -1,5 +1,5 @@ import { forwardRef, type ReactNode } from 'react'; -import { Box, Grid, styled } from '@mui/material'; +import { Box, Grid, styled, useMediaQuery, useTheme } from '@mui/material'; import Header from 'component/menu/Header/Header'; import Footer from 'component/menu/Footer/Footer'; import Proclamation from 'component/common/Proclamation/Proclamation'; @@ -105,6 +105,8 @@ export const MainLayout = forwardRef( const StyledMainLayoutContent = SpaciousMainLayoutContent; const sidebarNavigationEnabled = useUiFlag('navigationSidebar'); + const theme = useTheme(); + const isSmallScreen = useMediaQuery(theme.breakpoints.down('md')); return ( <> @@ -120,9 +122,16 @@ export const MainLayout = forwardRef( )} show={} /> - + ({ + display: 'flex', + mt: theme.spacing(0.25), + })} + > } /> ({ fill: theme.palette.neutral.main, @@ -49,9 +61,23 @@ export const StyledProjectIcon = styled(ProjectIcon)(({ theme }) => ({ fontSize: theme.spacing(3), })); -const StyledListItem: FC<{ href: string; text: string }> = ({ +const StyledBadgeContainer = styled('div')(({ theme }) => ({ + paddingLeft: theme.spacing(2), + display: 'flex', +})); + +const EnterprisePlanBadge = () => ( + + + + + +); + +const StyledListItem: FC<{ href: string; text: string; badge?: ReactNode }> = ({ href, text, + badge, children, }) => { return ( @@ -61,6 +87,7 @@ const StyledListItem: FC<{ href: string; text: string }> = ({ {children} + {badge} ); @@ -73,7 +100,75 @@ export const StyledBox = styled(Box)(({ theme }) => ({ minHeight: '95vh', })); +const icons: Record = { + '/applications': ApplicationsIcon, + '/context': ContextFieldsIcon, + '/feature-toggle-type': FlagTypesIcon, + '/integrations': IntegrationsIcon, + '/segments': SegmentsIcon, + '/strategies': CustomStrategiesIcon, + '/tag-types': TagTypesIcon, + '/environments': EnvironmentsIcon, + '/admin/users': UsersIcon, + '/admin/service-accounts': ServiceAccountIcon, + '/admin/groups': GroupsIcon, + '/admin/roles': RoleIcon, + '/admin/api': ApiAccessIcon, + '/admin/auth': SingleSignOnIcon, + '/admin/network': NetworkIcon, + '/admin/maintenance': MaintenanceIcon, + '/admin/banners': BannersIcon, + '/admin/instance': InstanceStatsIcon, + '/admin/license': LicenseIcon, + '/admin/instance-privacy': InstancePrivacyIcon, + '/admin/logins': LoginHistoryIcon, + '/admin/cors': CorsIcon, + '/admin/billing': BillingIcon, + '/history': EventLogIcon, +}; + +const findIconByPath = (path: string) => { + return icons[path] || EmptyIcon; +}; + +const IconRenderer: FC<{ path: string }> = ({ path }) => { + const IconComponent = findIconByPath(path); // Fallback to 'default' if the type is not found + + return ; +}; + +const useRoutes = () => { + const { uiConfig, isPro } = useUiConfig(); + 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, + }; + + const showBadge = useCallback( + (mode?: INavigationMenuItem['menu']['mode']) => { + return !!( + isPro() && + !mode?.includes('pro') && + mode?.includes('enterprise') + ); + }, + [isPro], + ); + + return { routes: filteredMainRoutes, showBadge }; +}; + export const NavigationSidebar = () => { + const { routes, showBadge } = useRoutes(); + return ( @@ -102,39 +197,14 @@ export const NavigationSidebar = () => { - - - - - - - - - - - - - - - - - - - - - + {routes.mainNavRoutes.map((route) => ( + + + + ))} @@ -150,66 +220,19 @@ export const NavigationSidebar = () => { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {routes.adminRoutes.map((route) => ( + + ) : null + } + > + + + ))}