Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(studio): polish replicated table controls (#50446)

Danny White2a46c006530b
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
index 05feac6a0ea..ab7127b1f9a 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
@@ -8,11 +8,13 @@ import {
CardContent,
DropdownMenu,
DropdownMenuContent,
+ DropdownMenuItem,
DropdownMenuTrigger,
Table,
TableBody,
TableHead,
TableHeader,
+ TableHeadSort,
TableRow,
} from 'ui'
import { Input } from 'ui-patterns/DataInputs/Input'
@@ -28,15 +30,35 @@ import { PipelineHealthSection } from './PipelineHealthSection'
import { getDisabledStateConfig } from './ReplicationPipelineStatus.utils'
import { TableReplicationRow } from './TableReplicationRow'
import { AlertError } from '@/components/ui/AlertError'
-import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
+import { TableRowNoResults } from '@/components/ui/TableRowNoResults'
import { useReplicationPipelineByIdQuery } from '@/data/replication/pipeline-by-id-query'
-import { useReplicationPipelineReplicationStatusQuery } from '@/data/replication/pipeline-replication-status-query'
+import {
+ useReplicationPipelineReplicationStatusQuery,
+ type ReplicationPipelineTableStatus,
+} from '@/data/replication/pipeline-replication-status-query'
import { useReplicationPipelineStatusQuery } from '@/data/replication/pipeline-status-query'
+import { onSearchInputEscape } from '@/lib/keyboard'
import {
PipelineStatusRequestStatus,
usePipelineRequestStatus,
} from '@/state/replication-pipeline-request-status'
+type TableSortColumn = 'table' | 'status'
+type TableSort = `${TableSortColumn}:${'asc' | 'desc'}`
+
+const TABLE_STATE_SORT_ORDER: ReplicationPipelineTableStatus['state']['name'][] = [
+ 'error',
+ 'copying_table',
+ 'copied_table',
+ 'following_wal',
+ 'queued',
+]
+
+const compareTableStates = (
+ a: ReplicationPipelineTableStatus['state'],
+ b: ReplicationPipelineTableStatus['state']
+) => TABLE_STATE_SORT_ORDER.indexOf(a.name) - TABLE_STATE_SORT_ORDER.indexOf(b.name)
+
/**
* Component for displaying replication pipeline status and table replication details.
* Supports both legacy 'error' state and new 'errored' state with retry policies.
@@ -98,27 +120,44 @@ export const ReplicationPipelineStatus = () => {
const statusName = getStatusName(pipelineStatusData?.status)
const config = getDisabledStateConfig({ requestStatus, statusName })
- // Sort tables by schema and name for consistent ordering (memoized)
const tableStatuses = useMemo(
- () =>
- (replicationStatusData?.table_statuses || []).sort(
- (a, b) => a.schema.localeCompare(b.schema) || a.name.localeCompare(b.name)
- ),
+ () => replicationStatusData?.table_statuses ?? [],
[replicationStatusData?.table_statuses]
)
const applyLagMetrics = replicationStatusData?.apply_lag
- // Filter tables based on search (memoized)
- const filteredTableStatuses = useMemo(
- () =>
+ const [sort, setSort] = useState<TableSort>('status:asc')
+ const [sortColumn, sortDirection] = sort.split(':') as [TableSortColumn, 'asc' | 'desc']
+
+ const getAriaSort = (column: TableSortColumn) => {
+ if (sortColumn !== column) return 'none'
+ return sortDirection === 'asc' ? 'ascending' : 'descending'
+ }
+
+ const handleSortChange = (column: TableSortColumn) => {
+ if (sortColumn !== column) return setSort(`${column}:asc`)
+ setSort(`${column}:${sortDirection === 'asc' ? 'desc' : 'asc'}`)
+ }
+
+ const filteredTableStatuses = useMemo(() => {
+ const items =
searchString.length === 0
- ? tableStatuses
+ ? [...tableStatuses]
: tableStatuses.filter((table) =>
`${table.schema}.${table.name}`.toLowerCase().includes(searchString.toLowerCase())
- ),
- [tableStatuses, searchString]
- )
+ )
+
+ items.sort((a, b) => {
+ const byName = a.schema.localeCompare(b.schema) || a.name.localeCompare(b.name)
+ const comparison =
+ sortColumn === 'table' ? byName : compareTableStates(a.state, b.state) || byName
+
+ return sortDirection === 'asc' ? comparison : -comparison
+ })
+
+ return items
+ }, [tableStatuses, searchString, sortColumn, sortDirection])
const erroredTables = useMemo(
() => tableStatuses.filter((table) => table.state.name === 'error'),
@@ -139,6 +178,7 @@ export const ReplicationPipelineStatus = () => {
requestStatus === PipelineStatusRequestStatus.RestartRequested
const isPipelineBusy = isEnablingDisabling || isAnyRestartInProgress
const showDisabledState = isPipelineBusy || !isPipelineActionable
+ const canResetErroredTables = hasErroredTables && !isAnyRestartInProgress && !showDisabledState
const lastKnownStateMessage =
statusName === PipelineStatusName.STOPPED
? 'Showing the last known table state before the pipeline was stopped.'
@@ -192,25 +232,27 @@ export const ReplicationPipelineStatus = () => {
icon={<Search />}
size="tiny"
className="text-xs w-52"
- placeholder="Search for tables"
+ placeholder="Search tables"
value={searchString}
disabled={isPipelineError}
onChange={(e) => setSearchString(e.target.value)}
+ onKeyDown={onSearchInputEscape(searchString, setSearchString)}
actions={
- searchString.length > 0 && [
- <X
- key="close"
- className="mx-2 cursor-pointer text-foreground"
- size={14}
- strokeWidth={1.5}
+ searchString.length > 0 && (
+ <Button
+ aria-label="Clear search"
+ variant="text"
+ icon={<X />}
+ className="p-0 h-5 w-5"
onClick={() => setSearchString('')}
- />,
- ]
+ />
+ )
}
/>
<div className="flex items-center">
<Button
size="tiny"
+ variant="default"
className="rounded-r-none hover:z-10 focus-visible:z-10 focus-visible:rounded-r-sm"
icon={<RotateCcw />}
disabled={isAnyRestartInProgress || showDisabledState || isPipelineError}
@@ -220,33 +262,35 @@ export const ReplicationPipelineStatus = () => {
setShowBatchRestartDialog(true)
}}
>
- Restart all tables
+ Reset all tables
</Button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
- aria-label="More restart options"
+ variant="default"
+ aria-label="More reset options"
icon={<ChevronDown />}
className="shrink-0 rounded-l-none px-[4px] py-[5px] -ml-px focus-visible:z-10 focus-visible:rounded-l-sm"
disabled={showDisabledState || isPipelineError}
/>
</DropdownMenuTrigger>
- <DropdownMenuContent align="end" className="w-44">
- <DropdownMenuItemTooltip
- disabled={!hasErroredTables || isAnyRestartInProgress || showDisabledState}
+ <DropdownMenuContent align="end" className="w-52">
+ <DropdownMenuItem
+ className="data-disabled:pointer-events-auto data-disabled:cursor-not-allowed"
+ disabled={!canResetErroredTables}
onClick={() => {
+ if (!canResetErroredTables) return
setBatchRestartMode('errored')
setShowBatchRestartDialog(true)
}}
- tooltip={{
- content: {
- side: 'left',
- text: !hasErroredTables ? 'No failed tables' : undefined,
- },
- }}
>
- Restart failed tables only
- </DropdownMenuItemTooltip>
+ <div className="flex flex-col gap-y-0.5">
+ <p>Reset failed tables only</p>
+ {!hasErroredTables && (
+ <p className="text-foreground-lighter">No failed tables</p>
+ )}
+ </div>
+ </DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
@@ -264,13 +308,43 @@ export const ReplicationPipelineStatus = () => {
<Table>
<TableHeader>
<TableRow>
- <TableHead key="table">Table</TableHead>
- <TableHead key="status">Status</TableHead>
+ <TableHead key="table" aria-sort={getAriaSort('table')}>
+ <TableHeadSort
+ column="table"
+ currentSort={sort}
+ onSortChange={handleSortChange}
+ >
+ Table
+ </TableHeadSort>
+ </TableHead>
+ <TableHead key="status" aria-sort={getAriaSort('status')}>
+ <TableHeadSort
+ column="status"
+ currentSort={sort}
+ onSortChange={handleSortChange}
+ >
+ Status
+ </TableHeadSort>
+ </TableHead>
<TableHead key="details">Details</TableHead>
<TableHead key="actions" />
</TableRow>
</TableHeader>
<TableBody>
+ <TableRow className="sr-only" aria-live="polite" role="status">
+ <td colSpan={4}>
+ {filteredTableStatuses.length === 0 && searchString.length > 0
+ ? `No results found for “${searchString}”`
+ : ''}
+ </td>
+ </TableRow>
+ {filteredTableStatuses.length === 0 && (
+ <TableRowNoResults
+ className="[&>td]:hover:bg-inherit"
+ colSpan={4}
+ search={searchString}
+ />
+ )}
{filteredTableStatuses.map((table) => {
const isRestarting = restartingTableIds.has(table.id)
const isErrorState = table.state.name === 'error'
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.test.ts b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.test.ts
new file mode 100644
index 00000000000..d614e0badd3
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.test.ts
@@ -0,0 +1,42 @@
+import { describe, expect, test } from 'vitest'
+
+import { getTableSyncLagLabel } from './ReplicationPipelineStatus.utils'
+
+describe('getTableSyncLagLabel', () => {
+ test('omits healthy slot details when the table has caught up', () => {
+ expect(
+ getTableSyncLagLabel({
+ active: true,
+ wal_status: 'reserved',
+ restart_lsn_bytes: 0,
+ confirmed_flush_lsn_bytes: 0,
+ safe_wal_size_bytes: null,
+ })
+ ).toEqual([])
+ })
+
+ test('reports the backlog and last check-in', () => {
+ expect(
+ getTableSyncLagLabel({
+ active: true,
+ wal_status: 'reserved',
+ restart_lsn_bytes: 4096,
+ confirmed_flush_lsn_bytes: 2048,
+ safe_wal_size_bytes: null,
+ reply_time_lag: 4800,
+ })
+ ).toEqual(['2 KB waiting to sync', 'Last check-in 4.80 s'])
+ })
+
+ test('reports slot risk without treating the expected inactive connection as a fault', () => {
+ expect(
+ getTableSyncLagLabel({
+ active: false,
+ wal_status: 'unreserved',
+ restart_lsn_bytes: 0,
+ confirmed_flush_lsn_bytes: 0,
+ safe_wal_size_bytes: null,
+ })
+ ).toEqual(['Some changes at risk'])
+ })
+})
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx
index 515273449fe..29e15b43e3d 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.utils.tsx
@@ -1,56 +1,45 @@
import dayjs from 'dayjs'
-import { Badge } from 'ui'
+import duration from 'dayjs/plugin/duration'
import { getPipelineDisplayState, normalizePipelineStatusName } from '../Pipeline.utils'
-import { RetryPolicy, SlotWalStatus, TableState } from './ReplicationPipelineStatus.types'
+import type { StateDotVariant } from '../StateDot'
+import {
+ RetryPolicy,
+ SlotLagMetrics,
+ SlotWalStatus,
+ TableState,
+} from './ReplicationPipelineStatus.types'
import { ReplicationPipelineStatusData } from '@/data/replication/pipeline-status-query'
import { formatBytes } from '@/lib/helpers'
import { PipelineStatusRequestStatus } from '@/state/replication-pipeline-request-status'
-export const getStatusConfig = (state: TableState['state']) => {
+dayjs.extend(duration)
+
+export const getStatusConfig = (
+ state: TableState['state']
+): { variant: StateDotVariant; label: string; description: string; isPulsing?: boolean } => {
switch (state.name) {
case 'queued':
- return {
- badge: <Badge variant="warning">Queued</Badge>,
- description: 'Table is waiting for the pipeline to pick it up for replication.',
- tooltip: 'Table is waiting for the pipeline to pick it up for replication.',
- color: 'text-warning',
- }
+ return { variant: 'default', label: 'Queued', description: 'Waiting to copy' }
case 'copying_table':
return {
- badge: <Badge variant="success">Copying</Badge>,
- description: "Table's existing rows are being copied during the initial sync.",
- tooltip: "Table's existing rows are being copied during the initial sync.",
- color: 'text-brand-600',
+ variant: 'default',
+ label: 'Copying',
+ description: 'Copying existing rows',
+ isPulsing: true,
}
case 'copied_table':
return {
- badge: <Badge variant="success">Copied</Badge>,
- description: 'Initial sync is complete and the table is preparing for ongoing replication.',
- tooltip: 'Initial sync is complete and the table is preparing for ongoing replication.',
- color: 'text-success-600',
+ variant: 'default',
+ label: 'Copied',
+ description: 'Copy finished, about to start streaming',
}
case 'following_wal':
- return {
- badge: <Badge variant="success">Live</Badge>,
- description: 'Table is receiving ongoing changes from the WAL.',
- tooltip: 'Table is receiving ongoing changes from the WAL.',
- color: 'text-success-600',
- }
+ return { variant: 'success', label: 'Live', description: 'Streaming changes as they happen' }
case 'error':
- return {
- badge: <Badge variant="destructive">Error</Badge>,
- description: 'Replication is paused because the table encountered an error.',
- tooltip: 'Replication is paused because the table encountered an error.',
- color: 'text-destructive-600',
- }
+ return { variant: 'destructive', label: 'Error', description: 'Stopped after an error' }
default:
- return {
- badge: <Badge variant="warning">Unknown</Badge>,
- description: 'Table status is unavailable.',
- tooltip: 'Table status is unavailable.',
- color: 'text-warning',
- }
+ return { variant: 'warning', label: 'Unknown', description: 'Table status is unavailable' }
}
}
@@ -272,3 +261,28 @@ export const getSlotHealthSeverity = (slot?: {
getSlotBudgetSeverity(slot.restart_lsn_bytes, slot.safe_wal_size_bytes)
)
}
+
+/**
+ * A table's own replication slot, as a short list of phrases for one table cell. Skips anything
+ * that carries no signal, such as a zero backlog or a reserved WAL status, so the line only ever
+ * says what's worth reading. Connection is skipped on purpose: a copying table's slot is inactive
+ * until the copy finishes, so flagging it would look like a fault.
+ */
+export const getTableSyncLagLabel = (metrics: SlotLagMetrics): string[] => {
+ const parts: string[] = []
+
+ const pendingBytes = metrics.confirmed_flush_lsn_bytes
+ if (typeof pendingBytes === 'number' && pendingBytes > 0) {
+ parts.push(`${formatBytes(pendingBytes, pendingBytes < 1024 ? 0 : 1)} waiting to sync`)
+ }
+
+ if (metrics.wal_status === 'unreserved') parts.push('Some changes at risk')
+ if (metrics.wal_status === 'lost') parts.push('Some changes lost')
+
+ const replyLag = metrics.reply_time_lag
+ if (typeof replyLag === 'number' && replyLag > 0) {
+ parts.push(`Last check-in ${getFormattedLagValue('duration', replyLag).display}`)
+ }
+
+ return parts
+}
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/TableReplicationRow.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/TableReplicationRow.tsx
index 9f2de762d7e..4b5b0c970cc 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/TableReplicationRow.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/TableReplicationRow.tsx
@@ -1,13 +1,22 @@
import { useParams } from 'common'
-import { ExternalLink, RotateCcw } from 'lucide-react'
+import { TableEditor } from 'icons'
+import { MoreVertical, RotateCcw } from 'lucide-react'
import Link from 'next/link'
-import { Badge, Button, TableCell, TableRow, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
+import {
+ Button,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+ TableCell,
+ TableRow,
+} from 'ui'
import { ErroredTableDetails } from '../ErroredTableDetails'
-import { TableState } from './ReplicationPipelineStatus.types'
-import { getStatusConfig } from './ReplicationPipelineStatus.utils'
-import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
-import { InlineLinkClassName } from '@/components/ui/InlineLink'
+import { StateDot } from '../StateDot'
+import { SlotLagMetrics as SlotLagMetricsType, TableState } from './ReplicationPipelineStatus.types'
+import { getStatusConfig, getTableSyncLagLabel } from './ReplicationPipelineStatus.utils'
+import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
import { ReplicationPipelineTableStatus } from '@/data/replication/pipeline-replication-status-query'
interface TableReplicationRowProps {
@@ -32,87 +41,107 @@ export const TableReplicationRow = ({
onSelectShowError,
}: TableReplicationRowProps) => {
const { ref } = useParams()
- const isErrorState = table.state.name === 'error'
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 (
<TableRow>
- <TableCell className="align-top">
- <div className="flex items-center gap-x-2">
- <p>
- {table.schema}.{table.name}
- </p>
-
- <ButtonTooltip
- asChild
- variant="text"
- className="px-1.5"
- icon={<ExternalLink />}
- tooltip={{
- content: { side: 'bottom', text: 'Table Editor' },
- }}
- >
- <Link
- target="_blank"
- rel="noopener noreferrer"
- href={`/project/${ref}/editor/${table.id}`}
- />
- </ButtonTooltip>
- </div>
- </TableCell>
+ <TableCell>{tableName}</TableCell>
- <TableCell className="align-top">
+ <TableCell>
{isRestarting ? (
- <Badge variant="default">Restarting</Badge>
+ <StateDot variant="warning" isPulsing>
+ Resetting
+ </StateDot>
) : showDisabledState ? (
- <Badge variant="default">Not Available</Badge>
+ <StateDot variant="default">Not available</StateDot>
) : (
- statusConfig.badge
+ <StateDot
+ variant={statusConfig.variant}
+ isPulsing={statusConfig.isPulsing}
+ pulseDelayMs={statusConfig.isPulsing ? (table.id % 8) * 55 : undefined}
+ >
+ {statusConfig.label}
+ </StateDot>
)}
</TableCell>
- <TableCell className="align-top">
+ <TableCell>
{isRestarting ? (
<p className="text-sm text-foreground-lighter">
- Replication is being restarted for this table. The pipeline will restart automatically.
+ Resetting. The pipeline will {pipelineAction} automatically…
</p>
) : showDisabledState ? (
<p className="text-sm text-foreground-lighter">{disabledStateMessage}</p>
- ) : (
- <div className="flex flex-col gap-y-3">
- <div className="text-sm text-foreground">
- {statusConfig.description}{' '}
- {isErrorState && 'reason' in table.state && (
- <button
- tabIndex={0}
- className={InlineLinkClassName}
- onClick={() => onSelectShowError()}
- >
- View error.
- </button>
- )}
- </div>
- {table.state.name === 'error' && <ErroredTableDetails table={table} />}
+ ) : isErrorState ? (
+ <div className="flex flex-col gap-y-3 text-sm text-foreground-lighter">
+ <p>{statusConfig.description}.</p>
+ <ErroredTableDetails table={table} />
</div>
+ ) : (
+ <p className="text-sm text-foreground-lighter">{detailsLine}</p>
)}
</TableCell>
- <TableCell className="align-top">
- <div className="flex items-center justify-end">
- <Tooltip>
- <TooltipTrigger asChild>
+ <TableCell>
+ <div className="flex items-center justify-end gap-x-2">
+ {canShowError && (
+ <Button variant="default" onClick={onSelectShowError}>
+ View error
+ </Button>
+ )}
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
<Button
- className="w-7"
- icon={<RotateCcw />}
- disabled={showDisabledState || isRestarting || isAnyRestartInProgress}
- aria-label={`Restart replication for ${table.schema}.${table.name}`}
- onClick={onSelectRestart}
+ variant="default"
+ className="px-1.25 hit-area-2"
+ aria-label={`Options for ${tableName}`}
+ icon={<MoreVertical />}
/>
- </TooltipTrigger>
- <TooltipContent side="bottom" align="center">
- {isPipelineStopped ? 'Reset table and start pipeline' : 'Reset and restart pipeline'}
- </TooltipContent>
- </Tooltip>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent side="bottom" align="end" className="w-64">
+ <DropdownMenuItemTooltip
+ className="gap-x-2"
+ disabled={!canRestart}
+ onClick={onSelectRestart}
+ tooltip={{
+ content: {
+ side: 'left',
+ text: canRestart ? undefined : disabledStateMessage,
+ },
+ }}
+ >
+ <RotateCcw size={14} />
+ <span>Reset table</span>
+ </DropdownMenuItemTooltip>
+ <DropdownMenuItem className="gap-x-2" asChild>
+ <Link
+ target="_blank"
+ rel="noopener noreferrer"
+ href={`/project/${ref}/editor/${table.id}`}
+ >
+ <TableEditor size={14} />
+ <span>View in Table Editor</span>
+ </Link>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
</div>
</TableCell>
</TableRow>