import type { WebVitalsDashboardViewProps } from "./WebVitalsDashboard.types"; const getRatingColor = (rating: string): string => { switch (rating) { case "good": return "text-green-600 bg-green-50"; case "needs-improvement": return "text-yellow-600 bg-yellow-50"; case "poor": return "text-red-600 bg-red-50"; default: return "text-gray-600 bg-gray-50"; } }; const getRatingIcon = (rating: string): string => { switch (rating) { case "good": return "✅"; case "needs-improvement": return "⚠️"; case "poor": return "❌"; default: return "❓"; } }; const formatValue = (metric: string, value: number): string => { if (metric === "cls") { return value.toFixed(3); } return `${value}ms`; }; function WebVitalsDashboardView({ vitals, metrics, loading, }: WebVitalsDashboardViewProps) { if (loading) { return (
{[1, 2, 3, 4, 5].map((i) => (
))}
); } return (

Web Vitals Dashboard

{Object.entries(vitals).map(([metric, data]) => (

{metric.toUpperCase()}

{getRatingIcon(data.rating)}
Value: {formatValue(metric, data.value)}
Rating: {data.rating.replace("-", " ")}
))}
{/* Historical Metrics */} {Object.keys(metrics).length > 0 && (

Historical Metrics

{Object.entries(metrics).map(([metric, data]) => (

{metric.toUpperCase()}

Count: {data.count}
Average: {formatValue(metric, data.average)}
Range: {formatValue(metric, data.min)} -{" "} {formatValue(metric, data.max)}
Good: {data.goodCount} Needs Improvement: {data.needsImprovementCount} Poor: {data.poorCount}
))}
)} {/* Performance Guidelines */}

Performance Guidelines

); } export default WebVitalsDashboardView;