import { useParams } from 'common' import { TableEditor } from 'icons' import { MoreVertical, RotateCcw } from 'lucide-react' import Link from 'next/link' import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, TableCell, TableRow, } from 'ui' import { ErroredTableDetails } from '../ErroredTableDetails' import { SlotLagMetrics as SlotLagMetricsType, TableState } from './ReplicationPipelineStatus.types' import { getStatusConfig, getTableSyncLagLabel } from './ReplicationPipelineStatus.utils' import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip' import { StateDot } from '@/components/ui/StateDot' import { ReplicationPipelineTableStatus } from '@/data/replication/pipeline-replication-status-query' interface TableReplicationRowProps { table: ReplicationPipelineTableStatus isRestarting: boolean showDisabledState: boolean disabledStateMessage: string isAnyRestartInProgress: boolean isPipelineStopped: boolean onSelectRestart: () => void onSelectShowError: () => void } export const TableReplicationRow = ({ table, isRestarting, showDisabledState, disabledStateMessage, isAnyRestartInProgress, isPipelineStopped, onSelectRestart, onSelectShowError, }: TableReplicationRowProps) => { const { ref } = useParams() const statusConfig = getStatusConfig(table.state as TableState['state']) const tableName = `${table.schema}.${table.name}` const canRestart = !showDisabledState && !isRestarting && !isAnyRestartInProgress const pipelineAction = isPipelineStopped ? 'start' : 'restart' const isErrorState = table.state.name === 'error' const canShowError = isErrorState && 'reason' in table.state && !showDisabledState && !isRestarting // A table copying during the initial sync reports its own slot metrics. Shown as one line rather // than a grid, so the detail survives without a table cell turning into a dashboard. const syncLag = table.table_sync_lag as SlotLagMetricsType | null | undefined const syncLagParts = syncLag == null ? undefined : getTableSyncLagLabel(syncLag) const syncLagLabel = syncLagParts !== undefined && syncLagParts.length > 0 ? syncLagParts.join(' · ') : undefined // Status column already names the state (Copying, Queued, …). Prefer the sync line when we have // one; keep the description only when it adds something the status label doesn't say. const detailsLine = syncLagLabel !== undefined ? syncLagLabel : isErrorState ? undefined : statusConfig.description return ( {table.schema}. {table.name} {isRestarting ? ( Resetting ) : showDisabledState ? ( Not available ) : ( {statusConfig.label} )} {isRestarting ? (

Resetting. The pipeline will {pipelineAction} automatically…

) : showDisabledState ? (

{disabledStateMessage}

) : isErrorState ? (

{statusConfig.description}.

) : (

{detailsLine}

)}
{canShowError && ( )}
) }