-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import React, { useState } from 'react'; | ||
import { useNavigate, useLocation } from 'react-router-dom'; | ||
import { | ||
Box, | ||
Drawer, | ||
AppBar, | ||
Toolbar, | ||
List, | ||
Typography, | ||
Divider, | ||
IconButton, | ||
ListItem, | ||
ListItemIcon, | ||
ListItemText, | ||
useTheme, | ||
} from '@mui/material'; | ||
import { | ||
Menu as MenuIcon, | ||
Dashboard as DashboardIcon, | ||
Router as RouterIcon, | ||
Security as SecurityIcon, | ||
Settings as SettingsIcon, | ||
SwapHoriz as SwitchIcon, | ||
Balance as LoadBalancerIcon, | ||
} from '@mui/icons-material'; | ||
|
||
const drawerWidth = 240; | ||
|
||
const menuItems = [ | ||
{ text: 'Dashboard', icon: <DashboardIcon />, path: '/' }, | ||
{ text: 'Logical Switches', icon: <SwitchIcon />, path: '/logical-switches' }, | ||
{ text: 'Logical Routers', icon: <RouterIcon />, path: '/logical-routers' }, | ||
{ text: 'Load Balancers', icon: <LoadBalancerIcon />, path: '/load-balancers' }, | ||
{ text: 'ACLs', icon: <SecurityIcon />, path: '/acls' }, | ||
{ text: 'Settings', icon: <SettingsIcon />, path: '/settings' }, | ||
]; | ||
|
||
function Layout({ children }) { | ||
const theme = useTheme(); | ||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
const [mobileOpen, setMobileOpen] = useState(false); | ||
|
||
const handleDrawerToggle = () => { | ||
setMobileOpen(!mobileOpen); | ||
}; | ||
|
||
const drawer = ( | ||
<div> | ||
<Toolbar> | ||
<Typography variant="h6" noWrap component="div"> | ||
OVN Manager | ||
</Typography> | ||
</Toolbar> | ||
<Divider /> | ||
<List> | ||
{menuItems.map((item) => ( | ||
<ListItem | ||
button | ||
key={item.text} | ||
onClick={() => navigate(item.path)} | ||
selected={location.pathname === item.path} | ||
sx={{ | ||
'&.Mui-selected': { | ||
backgroundColor: theme.palette.primary.main + '20', | ||
}, | ||
}} | ||
> | ||
<ListItemIcon sx={{ color: location.pathname === item.path ? theme.palette.primary.main : 'inherit' }}> | ||
{item.icon} | ||
</ListItemIcon> | ||
<ListItemText primary={item.text} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
</div> | ||
); | ||
|
||
return ( | ||
<Box sx={{ display: 'flex' }}> | ||
<AppBar | ||
position="fixed" | ||
sx={{ | ||
width: { sm: `calc(100% - ${drawerWidth}px)` }, | ||
ml: { sm: `${drawerWidth}px` }, | ||
}} | ||
> | ||
<Toolbar> | ||
<IconButton | ||
color="inherit" | ||
aria-label="open drawer" | ||
edge="start" | ||
onClick={handleDrawerToggle} | ||
sx={{ mr: 2, display: { sm: 'none' } }} | ||
> | ||
<MenuIcon /> | ||
</IconButton> | ||
<Typography variant="h6" noWrap component="div"> | ||
{menuItems.find(item => item.path === location.pathname)?.text || 'OVN Manager'} | ||
</Typography> | ||
</Toolbar> | ||
</AppBar> | ||
<Box | ||
component="nav" | ||
sx={{ width: { sm: drawerWidth }, flexShrink: { sm: 0 } }} | ||
> | ||
<Drawer | ||
variant="temporary" | ||
open={mobileOpen} | ||
onClose={handleDrawerToggle} | ||
ModalProps={{ | ||
keepMounted: true, | ||
}} | ||
sx={{ | ||
display: { xs: 'block', sm: 'none' }, | ||
'& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth }, | ||
}} | ||
> | ||
{drawer} | ||
</Drawer> | ||
<Drawer | ||
variant="permanent" | ||
sx={{ | ||
display: { xs: 'none', sm: 'block' }, | ||
'& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth }, | ||
}} | ||
open | ||
> | ||
{drawer} | ||
</Drawer> | ||
</Box> | ||
<Box | ||
component="main" | ||
sx={{ | ||
flexGrow: 1, | ||
p: 3, | ||
width: { sm: `calc(100% - ${drawerWidth}px)` }, | ||
minHeight: '100vh', | ||
backgroundColor: theme.palette.background.default, | ||
}} | ||
> | ||
<Toolbar /> | ||
{children} | ||
</Box> | ||
</Box> | ||
); | ||
} | ||
|
||
export default Layout; |