import React, { useState, useEffect } from 'react'; import { Box, Card, CardContent, Typography, LinearProgress, Chip, List, ListItem, ListItemText, ListItemIcon, Avatar, IconButton, Alert, Button, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Badge, Tabs, Tab, Paper, Grid, } from '@mui/material'; import { BugReport as IncidentIcon, Schedule as SLIcon, Security as SecurityIcon, Warning as WarningIcon, CheckCircle as CheckCircleIcon, Error as ErrorIcon, TrendingUp as TrendingUpIcon, TrendingDown as TrendingDownIcon, Refresh as RefreshIcon, Notifications as NotificationsIcon, Dashboard as DashboardIcon, ViewModule as ModuleIcon, } from '@mui/icons-material'; import { useAuth } from '../../contexts/AuthContext'; import { useNavigate } from 'react-router-dom'; import apiService from '../../services/api'; import { Incident, Alert as AlertType, OnCallAssignment } from '../../types'; import ModuleOverviewCards from './ModuleOverviewCards'; interface DashboardStats { totalIncidents: number; openIncidents: number; resolvedIncidents: number; criticalIncidents: number; slaBreaches: number; activeAlerts: number; systemHealth: number; mttr: number; mtta: number; } const OverviewDashboard: React.FC = () => { const { user } = useAuth(); const navigate = useNavigate(); const [activeTab, setActiveTab] = useState(0); const [stats, setStats] = useState({ totalIncidents: 0, openIncidents: 0, resolvedIncidents: 0, criticalIncidents: 0, slaBreaches: 0, activeAlerts: 0, systemHealth: 100, mttr: 0, mtta: 0, }); const [recentIncidents, setRecentIncidents] = useState([]); const [recentAlerts, setRecentAlerts] = useState([]); const [currentOnCall, setCurrentOnCall] = useState(null); // const [systemMetrics] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { loadDashboardData(); }, []); const loadDashboardData = async () => { try { setIsLoading(true); setError(null); // Load incidents const incidentsResponse = await apiService.getIncidents({ page_size: 10 }); setRecentIncidents(incidentsResponse.results); // Load alerts const alertsResponse = await apiService.getAlerts({ page_size: 5 }); setRecentAlerts(alertsResponse.results); // Load current on-call const onCallResponse = await apiService.getCurrentOnCall(); setCurrentOnCall(onCallResponse); // Load system metrics // const metricsResponse = await apiService.getSystemMetrics(); // setSystemMetrics(metricsResponse); // Commented out as it's not used // Calculate stats const totalIncidents = incidentsResponse.count; const openIncidents = incidentsResponse.results.filter(i => i.status === 'OPEN' || i.status === 'IN_PROGRESS').length; const resolvedIncidents = incidentsResponse.results.filter(i => i.status === 'RESOLVED' || i.status === 'CLOSED').length; const criticalIncidents = incidentsResponse.results.filter(i => i.severity === 'CRITICAL' || i.severity === 'EMERGENCY').length; const activeAlerts = alertsResponse.results.filter(a => a.status === 'TRIGGERED').length; setStats({ totalIncidents, openIncidents, resolvedIncidents, criticalIncidents, slaBreaches: 0, // This would come from SLA API activeAlerts, systemHealth: 95, // This would be calculated from health checks mttr: 2.5, // This would come from analytics mtta: 0.5, // This would come from analytics }); } catch (error) { console.error('Failed to load dashboard data:', error); setError('Failed to load dashboard data'); } finally { setIsLoading(false); } }; const getSeverityColor = (severity: string) => { switch (severity) { case 'CRITICAL': case 'EMERGENCY': return 'error'; case 'HIGH': return 'warning'; case 'MEDIUM': return 'info'; case 'LOW': return 'success'; default: return 'default'; } }; const getStatusColor = (status: string) => { switch (status) { case 'OPEN': return 'error'; case 'IN_PROGRESS': return 'warning'; case 'RESOLVED': return 'success'; case 'CLOSED': return 'default'; default: return 'default'; } }; const formatTime = (timestamp: string) => { return new Date(timestamp).toLocaleString(); }; const handleModuleClick = (moduleId: string) => { // Navigate to the specific module page const moduleRoutes: { [key: string]: string } = { incident_intelligence: '/incidents', security: '/security', monitoring: '/monitoring', sla_oncall: '/sla', automation_orchestration: '/automation', collaboration_war_rooms: '/collaboration', analytics_predictive_insights: '/analytics', knowledge_learning: '/knowledge', compliance_governance: '/compliance', }; const route = moduleRoutes[moduleId]; if (route) { navigate(route); } }; const handleTabChange = (event: React.SyntheticEvent, newValue: number) => { setActiveTab(newValue); }; const StatCard: React.FC<{ title: string; value: string | number; icon: React.ReactNode; color: string; trend?: 'up' | 'down' | 'neutral'; trendValue?: string; }> = ({ title, value, icon, color, trend, trendValue }) => ( {title} {value} {trend && trendValue && ( {trend === 'up' ? ( ) : trend === 'down' ? ( ) : null} {trendValue} )} {icon} ); if (isLoading) { return ( Loading dashboard... ); } if (error) { return ( Retry }> {error} ); } return ( {/* Welcome Section */} Welcome back, {user?.first_name || user?.username}! Enterprise Incident Management Dashboard - Real-time system overview {/* Dashboard Tabs */} } label="Dashboard Overview" iconPosition="start" /> } label="Module Status" iconPosition="start" /> {/* Tab Content */} {activeTab === 0 && ( <> {/* Stats Cards */} } color="primary" trend="up" trendValue="+12% from last week" /> } color="warning" trend="down" trendValue="-5% from yesterday" /> } color="error" trend="neutral" trendValue="No change" /> } color="success" trend="up" trendValue="+2% from last hour" /> {/* Performance Metrics */} } color="info" trend="down" trendValue="-0.5h from last week" /> } color="secondary" trend="down" trendValue="-0.2h from last week" /> } color="warning" trend="up" trendValue="+3 from yesterday" /> } color="error" trend="down" trendValue="-1 from last week" /> {/* Main Content Grid */} {/* Recent Incidents */} Recent Incidents Title Severity Status Assigned To Created {recentIncidents.map((incident) => ( {incident.title} {incident.assigned_to ? ( {incident.assigned_to.first_name?.[0]} {incident.assigned_to.first_name} {incident.assigned_to.last_name} ) : ( Unassigned )} {formatTime(incident.created_at)} ))}
{/* Sidebar */} {/* Current On-Call */} {currentOnCall && ( Current On-Call {currentOnCall.user.first_name?.[0]} {currentOnCall.user.first_name} {currentOnCall.user.last_name} {currentOnCall.rotation.team_name} Until {formatTime(currentOnCall.end_time)} )} {/* Recent Alerts */} Recent Alerts {recentAlerts.map((alert) => ( {formatTime(alert.triggered_at)}
} /> ))} {/* System Status */} System Status Overall Health {stats.systemHealth}% 90 ? 'success' : stats.systemHealth > 70 ? 'warning' : 'error'} /> )} {/* Module Status Tab */} {activeTab === 1 && ( )} ); }; export default OverviewDashboard;