import { Info } from 'lucide-react' import { Tooltip, TooltipContent, TooltipTrigger } from 'ui' import { SlotLagMetricKey, SlotLagMetrics } from './ReplicationPipelineStatus.types' import { getFormattedLagValue } from './ReplicationPipelineStatus.utils' const SLOT_LAG_FIELDS: { key: SlotLagMetricKey label: string type: 'bytes' | 'duration' description: string }[] = [ { key: 'confirmed_flush_lsn_bytes', label: 'WAL Flush lag (size)', type: 'bytes', description: 'Bytes between the newest WAL record applied locally and the latest flushed WAL record acknowledged by ETL.', }, { key: 'flush_lag', label: 'WAL Flush lag (time)', type: 'duration', description: 'Time between flushing recent WAL locally and receiving notification that ETL has written and flushed it.', }, { key: 'safe_wal_size_bytes', label: 'Remaining WAL size', type: 'bytes', description: 'Bytes still available to write to WAL before this slot risks entering the "lost" state.', }, ] export const SlotLagMetricsInline = ({ tableName, metrics, }: { tableName: string metrics: SlotLagMetrics }) => { return (
{tableName}
{SLOT_LAG_FIELDS.map(({ key, label, type }) => { const { display } = getFormattedLagValue(type, metrics[key]) return ( {label} {display} ) })}
) } export const SlotLagMetricsList = ({ metrics, size = 'default', showMetricInfo = true, }: { metrics: SlotLagMetrics size?: 'default' | 'compact' showMetricInfo?: boolean }) => { const gridClasses = size === 'default' ? 'grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-y-4 gap-x-6' : 'grid-cols-2 gap-y-2 gap-x-4' const labelClasses = size === 'default' ? 'text-xs text-foreground-light' : 'text-[11px] text-foreground-lighter' const valueClasses = size === 'default' ? 'text-sm font-medium text-foreground' : 'text-xs font-medium text-foreground' return (
{SLOT_LAG_FIELDS.map(({ key, label, type, description }) => (
{label} {showMetricInfo && ( {description} )}
{(() => { const { display, detail } = getFormattedLagValue(type, metrics[key]) return (
{display} {detail && {detail}}
) })()}
))}
) }