import { ChevronRight, HelpCircle } from 'lucide-react' import Link from 'next/link' import { Button, Card, CardContent, cn, Skeleton, Tooltip, TooltipContent, TooltipTrigger, } from 'ui' import { ChartEmptyState, ChartLoadingState } from 'ui-patterns/Chart' import { LogsBarChart } from 'ui-patterns/LogsBarChart' import type { LogsBarChartDatum } from '../ProjectHome/ProjectUsage.metrics' import { getHealthStatus, type ServiceKey } from './ObservabilityOverview.utils' type ServiceConfig = { key: ServiceKey name: string description: string reportUrl?: string logsUrl: string } type ServiceData = { total: number errorRate: number errorCount: number warningCount: number eventChartData: LogsBarChartDatum[] isLoading: boolean } export type ServiceHealthTableProps = { services: ServiceConfig[] serviceData: Record onBarClick: (logsUrl: string) => (datum: LogsBarChartDatum) => void datetimeFormat: string } const colorClassMap: Record = { muted: 'bg-gray-500', destructive: 'bg-destructive', warning: 'bg-warning', brand: 'bg-brand', } const SERVICE_DESCRIPTIONS: Record = { db: 'PostgreSQL database health and performance', auth: 'Authentication and user management', functions: 'Serverless Edge Functions execution', storage: 'Object storage for files and assets', realtime: 'WebSocket connections and broadcasts', data_api: 'Incoming API requests routed through the edge network', postgrest: 'Auto-generated REST API for your database', } const formatPercent = (value: number) => value >= 1 ? `${value.toFixed(1)}%` : `${value.toFixed(2)}%` const getSubtitle = (data: ServiceData) => { if (data.total === 0) return '' const errorRate = data.errorRate const warningRate = data.total > 0 ? (data.warningCount / data.total) * 100 : 0 if (errorRate > 0) return `${formatPercent(errorRate)} errors` if (warningRate > 0) return `${formatPercent(warningRate)} warnings` return `${data.total.toLocaleString()} requests` } type ServiceCellProps = { service: ServiceConfig data: ServiceData onBarClick: (datum: LogsBarChartDatum) => void datetimeFormat: string className?: string } const ServiceCell = ({ service, data, onBarClick, datetimeFormat, className, }: ServiceCellProps) => { const reportUrl = service.reportUrl || service.logsUrl const { color } = getHealthStatus(data.errorRate, data.total) const description = SERVICE_DESCRIPTIONS[service.key] || service.description return (

{service.name}

{description && (

{description}

)}
{data.isLoading ? ( ) : ( {getSubtitle(data)} )} Go to {service.name} report
{data.isLoading ? ( ) : ( } /> )}
) } export const ServiceHealthTable = ({ services, serviceData, onBarClick, datetimeFormat, }: ServiceHealthTableProps) => { return (

Service Health

{services.map((service, index) => { const data = serviceData[service.key] if (!data) return null const isFirst = index === 0 const isLeftColumn = !isFirst && (index - 1) % 2 === 0 const restCount = services.length - 1 const lastRowCount = restCount % 2 === 0 ? 2 : 1 const isInLastRow = !isFirst && index >= services.length - lastRowCount return ( ) })}
) }