Spaces:
Sleeping
Sleeping
File size: 4,610 Bytes
fee2f22 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | /**
* Sidebar component - Side navigation with quick actions and stats summary
*/
import React from 'react';
import { Link, useLocation } from 'react-router-dom';
import {
Box,
Drawer,
List,
ListItem,
ListItemButton,
ListItemIcon,
ListItemText,
Divider,
Typography,
Button,
Paper,
} from '@mui/material';
import {
Dashboard as DashboardIcon,
CloudUpload as UploadIcon,
History as HistoryIcon,
PlayArrow as StartIcon,
Analytics as StatsIcon,
} from '@mui/icons-material';
const DRAWER_WIDTH = 240;
interface SidebarProps {
stats?: {
totalJobs?: number;
completedJobs?: number;
avgAccuracy?: number;
};
}
const Sidebar: React.FC<SidebarProps> = ({ stats }) => {
const location = useLocation();
const menuItems = [
{ path: '/', label: 'Dashboard', icon: <DashboardIcon /> },
{ path: '/upload', label: 'Upload Dataset', icon: <UploadIcon /> },
{ path: '/jobs', label: 'Job History', icon: <HistoryIcon /> },
];
const isActive = (path: string): boolean => {
if (path === '/') {
return location.pathname === '/';
}
return location.pathname.startsWith(path);
};
return (
<Drawer
variant="permanent"
sx={{
width: DRAWER_WIDTH,
flexShrink: 0,
'& .MuiDrawer-paper': {
width: DRAWER_WIDTH,
boxSizing: 'border-box',
bgcolor: 'background.default',
borderRight: '1px solid',
borderColor: 'divider',
},
}}
>
{/* Quick Stats Section */}
{stats && (
<Box sx={{ p: 2 }}>
<Paper elevation={0} sx={{ p: 2, bgcolor: 'primary.light', color: 'primary.contrastText' }}>
<Typography variant="subtitle2" gutterBottom sx={{ fontWeight: 600 }}>
Quick Stats
</Typography>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
<Typography variant="body2">Total Jobs:</Typography>
<Typography variant="body2" sx={{ fontWeight: 600 }}>
{stats.totalJobs || 0}
</Typography>
</Box>
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
<Typography variant="body2">Completed:</Typography>
<Typography variant="body2" sx={{ fontWeight: 600 }}>
{stats.completedJobs || 0}
</Typography>
</Box>
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
<Typography variant="body2">Avg Accuracy:</Typography>
<Typography variant="body2" sx={{ fontWeight: 600 }}>
{stats.avgAccuracy ? `${stats.avgAccuracy.toFixed(1)}%` : 'N/A'}
</Typography>
</Box>
</Box>
</Paper>
</Box>
)}
<Divider />
{/* Main Navigation */}
<List sx={{ px: 1 }}>
{menuItems.map((item) => (
<ListItem key={item.path} disablePadding>
<ListItemButton
component={Link}
to={item.path}
selected={isActive(item.path)}
sx={{
borderRadius: 1,
mb: 0.5,
'&.Mui-selected': {
bgcolor: 'primary.main',
color: 'primary.contrastText',
'&:hover': {
bgcolor: 'primary.dark',
},
'& .MuiListItemIcon-root': {
color: 'inherit',
},
},
}}
>
<ListItemIcon sx={{ minWidth: 40 }}>{item.icon}</ListItemIcon>
<ListItemText primary={item.label} />
</ListItemButton>
</ListItem>
))}
</List>
<Divider sx={{ my: 1 }} />
{/* Quick Actions */}
<Box sx={{ p: 2 }}>
<Typography variant="subtitle2" sx={{ mb: 1, fontWeight: 600, color: 'text.secondary' }}>
Quick Actions
</Typography>
<Button
variant="contained"
fullWidth
component={Link}
to="/upload"
startIcon={<StartIcon />}
sx={{ mb: 1 }}
>
New Job
</Button>
<Button
variant="outlined"
fullWidth
component={Link}
to="/jobs"
startIcon={<StatsIcon />}
>
View Reports
</Button>
</Box>
</Drawer>
);
};
export default Sidebar;
|