feat:(frontend): side-nav enterprise items

This commit is contained in:
leandrofars 2024-09-05 12:11:03 -03:00
parent a5211f4dba
commit 636f034666
3 changed files with 165 additions and 31 deletions

View File

@ -2,6 +2,8 @@ import ChartBarIcon from '@heroicons/react/24/solid/ChartBarIcon';
import CogIcon from '@heroicons/react/24/solid/CogIcon'; import CogIcon from '@heroicons/react/24/solid/CogIcon';
import ChatBubbleLeftRightIcon from '@heroicons/react/24/solid/ChatBubbleLeftRightIcon' import ChatBubbleLeftRightIcon from '@heroicons/react/24/solid/ChatBubbleLeftRightIcon'
import MapIcon from '@heroicons/react/24/solid/MapIcon' import MapIcon from '@heroicons/react/24/solid/MapIcon'
import RectangleGroupIcon from '@heroicons/react/24/solid/RectangleGroupIcon'
import ArrowDownOnSquareStackIcon from '@heroicons/react/24/solid/ArrowDownOnSquareStackIcon'
import UserGroupIcon from '@heroicons/react/24/solid/UserGroupIcon' import UserGroupIcon from '@heroicons/react/24/solid/UserGroupIcon'
import KeyIcon from '@heroicons/react/24/solid/KeyIcon' import KeyIcon from '@heroicons/react/24/solid/KeyIcon'
import CpuChip from '@heroicons/react/24/solid/CpuChipIcon'; import CpuChip from '@heroicons/react/24/solid/CpuChipIcon';
@ -26,23 +28,34 @@ export const items = [
</SvgIcon> </SvgIcon>
) )
}, },
// {
// title: 'Chat (beta)',
// path: '/chat',
// icon: (
// <SvgIcon fontSize="small">
// <ChatBubbleLeftRightIcon/>
// </SvgIcon>
// )
// },
{ {
title: 'Map', title: 'Mass Actions',
path: '/map',
icon: ( icon: (
<SvgIcon fontSize="small"> <SvgIcon fontSize="small">
<MapIcon/> <RectangleGroupIcon color='gray'/>
</SvgIcon> </SvgIcon>
), ),
disabled: true,
children: [
{
title: 'Firmware Update',
icon: (
<SvgIcon fontSize="small">
<ArrowDownOnSquareStackIcon color='gray'/>
</SvgIcon>
),
disabled: true
}
]
},
{
title: 'Map',
icon: (
<SvgIcon fontSize="small">
<MapIcon color='gray'/>
</SvgIcon>
),
disabled: true
}, },
{ {
title: 'Credentials', title: 'Credentials',

View File

@ -1,9 +1,28 @@
import { useState } from 'react';
import NextLink from 'next/link'; import NextLink from 'next/link';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Box, ButtonBase } from '@mui/material'; import { Box, ButtonBase, Collapse, SvgIcon } from '@mui/material';
import ChevronDownIcon from '@heroicons/react/24/outline/ChevronDownIcon';
import ChevronUpIcon from '@heroicons/react/24/outline/ChevronUpIcon';
import { usePathname } from 'next/navigation';
export const SideNavItem = (props) => { export const SideNavItem = (props) => {
const { active = false, disabled, external, icon, path, title } = props; const { active = false, disabled, external, icon, path, title, children, padleft } = props;
const [open, setOpen] = useState(false);
const pathname = usePathname();
const isItemActive = (currentPath, itemPath) => {
if (currentPath === itemPath) {
return true;
}
if (currentPath.includes(itemPath) && itemPath !== '/' && itemPath !== '/mass-actions') {
return true;
}
return false;
}
const linkProps = path const linkProps = path
? external ? external
@ -18,6 +37,10 @@ export const SideNavItem = (props) => {
} }
: {}; : {};
// console.log('padleft', padleft);
// console.log('path', path);
// console.log('title', title);
return ( return (
<li> <li>
<ButtonBase <ButtonBase
@ -25,8 +48,9 @@ export const SideNavItem = (props) => {
alignItems: 'center', alignItems: 'center',
borderRadius: 1, borderRadius: 1,
display: 'flex', display: 'flex',
...(disabled ? {cursor: 'default'}: {cursor: 'pointer'}),
justifyContent: 'flex-start', justifyContent: 'flex-start',
pl: '16px', pl: padleft,
pr: '16px', pr: '16px',
py: '6px', py: '6px',
textAlign: 'left', textAlign: 'left',
@ -38,7 +62,6 @@ export const SideNavItem = (props) => {
backgroundColor: 'rgba(255, 255, 255, 0.04)' backgroundColor: 'rgba(255, 255, 255, 0.04)'
} }
}} }}
{...linkProps}
> >
{icon && ( {icon && (
<Box <Box
@ -53,6 +76,7 @@ export const SideNavItem = (props) => {
color: '#FFFFFF' color: '#FFFFFF'
}) })
}} }}
{...linkProps}
> >
{icon} {icon}
</Box> </Box>
@ -66,6 +90,32 @@ export const SideNavItem = (props) => {
fontSize: 14, fontSize: 14,
fontWeight: 600, fontWeight: 600,
lineHeight: '24px', lineHeight: '24px',
textDecoration: 'none',
whiteSpace: 'nowrap',
...(active && {
color: 'common.white'
}),
...(disabled && {
color: 'neutral.500'
})
}}
{...linkProps}
>
{title}
</Box>
{ children &&
<Box
onClick={()=>setOpen(!open)}
component="span"
sx={{
color: 'neutral.400',
flexGrow: 1,
display: 'flex',
justifyContent: 'flex-end',
fontFamily: (theme) => theme.typography.fontFamily,
fontSize: 14,
fontWeight: 600,
lineHeight: '24px',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
...(active && { ...(active && {
color: 'common.white' color: 'common.white'
@ -75,9 +125,40 @@ export const SideNavItem = (props) => {
}) })
}} }}
> >
{title} {
open ?
<SvgIcon fontSize='8px'>
<ChevronDownIcon/>
</SvgIcon>:
<SvgIcon fontSize='8px'>
<ChevronUpIcon />
</SvgIcon>
}
</Box> </Box>
}
</ButtonBase> </ButtonBase>
<Collapse in={open}>
{
children &&
(
children.map((child) => {
return (
<SideNavItem
active={isItemActive(pathname, child.path)}
disabled={child.disabled}
external={false}
icon={child.icon}
key={child.title}
path={child.path}
title={child.title}
children={child?.children}
padleft={padleft + 2}
/>
);
})
)
}
</Collapse>
</li> </li>
); );
}; };

View File

@ -5,8 +5,12 @@ import Link from 'next/link'
import { import {
Box, Box,
Button, Button,
Collapse,
Divider, Divider,
Drawer, Drawer,
List,
ListItemButton,
ListItemText,
Stack, Stack,
SvgIcon, SvgIcon,
Typography, Typography,
@ -30,7 +34,7 @@ export const SideNav = (props) => {
return true; return true;
} }
if (currentPath.includes(itemPath) && itemPath !== '/') { if (currentPath.includes(itemPath) && itemPath !== '/' && itemPath !== '/mass-actions') {
return true; return true;
} }
@ -82,7 +86,7 @@ export const SideNav = (props) => {
> >
<Link href="http://localhost/companylink" target="_blank"> <Link href="http://localhost/companylink" target="_blank">
<div style={{display:'flex',justifyContent:'center'}}> <div style={{display:'flex',justifyContent:'center'}}>
<img src="/images/logo.png" <img src={`${process.env.NEXT_PUBLIC_REST_ENDPOINT || ""}/images/logo.png`}
width={'60%'} width={'60%'}
/> />
</div> </div>
@ -113,6 +117,9 @@ export const SideNav = (props) => {
}} }}
> >
{items.map((item) => { {items.map((item) => {
if (item.title == "Map" && process.env.NEXT_PUBLIC_ENTERPRISE_VERSION != "true"){
return
}
const active = isItemActive(pathname, item.path); const active = isItemActive(pathname, item.path);
return ( return (
@ -124,9 +131,43 @@ export const SideNav = (props) => {
key={item.title} key={item.title}
path={item.path} path={item.path}
title={item.title} title={item.title}
children={item?.children}
padleft={2}
/> />
); );
})} })}
<Collapse in={open} timeout="auto" unmountOnExit>
<Box
component="span"
sx={{
color: 'neutral.400',
flexGrow: 1,
fontFamily: (theme) => theme.typography.fontFamily,
fontSize: 14,
fontWeight: 600,
lineHeight: '24px',
whiteSpace: 'nowrap',
...(true && {
color: 'common.white'
}),
...(false && {
color: 'neutral.500'
})
}}
>
{""}
</Box>
</Collapse>
{/* <List>
<Collapse in={true}>
<List disablePadding>
<ListItemButton sx={{ pl: 4 }}>
<ListItemText primary="Starred" />
oi
</ListItemButton>
</List>
</Collapse>
</List> */}
</Stack> </Stack>
</Box> </Box>
<Stack style={{position:"absolute", bottom:"2px", left:"2px"}} direction={"row"} spacing={"1"} zIndex={9999}> <Stack style={{position:"absolute", bottom:"2px", left:"2px"}} direction={"row"} spacing={"1"} zIndex={9999}>
@ -158,8 +199,7 @@ export const SideNav = (props) => {
open open
PaperProps={{ PaperProps={{
sx: { sx: {
background: `linear-gradient(0deg, ${theme.palette.neutral["800"]} 0%, ${theme.palette.primary.dark} 90%);`, background: `linear-gradient(120deg, ${theme.palette.neutral["800"]} 0%, ${theme.palette.primary.dark} 90%);`,
color: 'common.white',
width: 280 width: 280
} }
}} }}
@ -177,7 +217,7 @@ export const SideNav = (props) => {
open={open} open={open}
PaperProps={{ PaperProps={{
sx: { sx: {
background: `linear-gradient(0deg, ${theme.palette.primary.main} 0%, ${theme.palette.primary.dark} 90%);`, background: `linear-gradient(120deg, ${theme.palette.neutral["800"]} 0%, ${theme.palette.primary.dark} 90%);`,
color: 'common.white', color: 'common.white',
width: 280 width: 280
} }