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 "❓"; } }; function formatValue(metric: string, value: number): string { if (metric === "cls") { return value.toFixed(3); } return `${value}ms`; } function WebVitalsDashboardView({ vitals, metrics, loading, storage, copy, rumDashboardUrl, }: WebVitalsDashboardViewProps) { if (loading) { return (
{[1, 2, 3, 4, 5].map((i) => (
))}
); } return (

{copy.title}

{storage === "external" && (

{copy.externalNoticeTitle}

{copy.externalNoticeBody}

{rumDashboardUrl ? ( {copy.externalDashboardLinkLabel} ) : null}
)}
{Object.entries(vitals).map(([metric, data]) => (

{metric.toUpperCase()}

{getRatingIcon(data.rating)}
{copy.valueLabel}: {formatValue(metric, data.value)}
{copy.ratingLabel}: {data.rating.replace("-", " ")}
))}
{Object.keys(metrics).length > 0 && (

{copy.historicalMetricsTitle}

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

{metric.toUpperCase()}

{copy.countLabel}: {data.count}
{copy.averageLabel}: {formatValue(metric, data.average)}
{copy.rangeLabel}: {formatValue(metric, data.min)} -{" "} {formatValue(metric, data.max)}
{copy.goodLabel}: {data.goodCount} {copy.needsImprovementLabel}: {data.needsImprovementCount} {copy.poorLabel}: {data.poorCount}
))}
)}

{copy.performanceGuidelinesTitle}

); } export default WebVitalsDashboardView;