import { useState } from 'react'; import axios from 'axios'; const API = ''; const SEVERITY_COLORS = { Critical: 'var(--critical)', High: 'var(--high)', Medium: 'var(--medium)', Low: 'var(--low)', }; export default function ReportPanel({ clusters, anomalies, stats }) { const [report, setReport] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); async function generateReport() { setLoading(true); setError(null); try { const response = await axios.post(`/api/cluster/report`, { clusters, anomalies, stats }); setReport(response.data); } catch (err) { setError('Failed to generate report'); } finally { setLoading(false); } } function downloadMarkdown() { if (!report) return; const md = buildMarkdown(report); const blob = new Blob([md], { type: 'text/markdown' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'incident-report.md'; a.click(); URL.revokeObjectURL(url); } function buildMarkdown(r) { return `# Incident Report ## Executive Summary ${r.executive_summary} **Overall Severity:** ${r.overall_severity} **Affected Systems:** ${r.estimated_affected_systems?.join(', ') || 'Unknown'} ## Top Issues ${r.top_issues?.map(issue => ` ### ${issue.rank}. ${issue.label} — ${issue.severity} - **Impact:** ${issue.impact} - **Suggested Fix:** ${issue.suggested_fix} `).join('\n')} ## Anomaly Assessment ${r.anomaly_assessment} --- *Generated by Error Clustering Engine* `; } return (
ROOT CAUSE REPORT
{report && ( )}
{error && (
⚠ {error}
)} {loading && (
Analyzing clusters and generating report...
)} {report && !loading && (
{/* Header */}
{report.overall_severity?.toUpperCase()} SEVERITY {report.estimated_affected_systems?.length > 0 && (
{report.estimated_affected_systems.map(s => (
{s}
))}
)}

{report.executive_summary}

{/* Top issues */}
TOP ISSUES
{report.top_issues?.map(issue => (
#{issue.rank} {issue.label} {issue.severity?.toUpperCase()}
Impact: {issue.impact}
Fix: {issue.suggested_fix}
))}
{/* Anomalies */} {report.anomaly_assessment && (
ANOMALY ASSESSMENT

{report.anomaly_assessment}

)}
)} {!report && !loading && (
Click "Generate Report" to get an AI-powered incident analysis
)}
); }