From 799c157511f7c2497120ccfa57bf60b8fe810326 Mon Sep 17 00:00:00 2001 From: Jigawatt <4837231+bufanoc@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:38:10 -0500 Subject: [PATCH] Create Layout.js --- frontend/src/components/Layout.js | 149 ++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 frontend/src/components/Layout.js diff --git a/frontend/src/components/Layout.js b/frontend/src/components/Layout.js new file mode 100644 index 0000000..305412a --- /dev/null +++ b/frontend/src/components/Layout.js @@ -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: , path: '/' }, + { text: 'Logical Switches', icon: , path: '/logical-switches' }, + { text: 'Logical Routers', icon: , path: '/logical-routers' }, + { text: 'Load Balancers', icon: , path: '/load-balancers' }, + { text: 'ACLs', icon: , path: '/acls' }, + { text: 'Settings', icon: , 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 = ( +
+ + + OVN Manager + + + + + {menuItems.map((item) => ( + navigate(item.path)} + selected={location.pathname === item.path} + sx={{ + '&.Mui-selected': { + backgroundColor: theme.palette.primary.main + '20', + }, + }} + > + + {item.icon} + + + + ))} + +
+ ); + + return ( + + + + + + + + {menuItems.find(item => item.path === location.pathname)?.text || 'OVN Manager'} + + + + + + {drawer} + + + {drawer} + + + + + {children} + + + ); +} + +export default Layout;