Files
supabase/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
T
Danny White 5951fb6c47 fix(studio): polish Pipelines loading and update cues (#50963)
## Problem

Pipelines loading causes layout shifts, and the update cue is hard to
connect to its menu action.

- Resolves
[PIPE-1078](https://linear.app/supabase/issue/PIPE-1078/show-destination-rows-while-details-are-loading)
- Resolves
[DEPR-688](https://linear.app/supabase/issue/DEPR-688/widen-the-update-available-modal)
- Resolves
[DEPR-691](https://linear.app/supabase/issue/DEPR-691/clarify-the-update-available-indicator-in-pipeline-actions)

## Solution

Reserve space for the graph and list while loading, show destination
rows before their details arrive, align the detail header, and stack
version values in the update dialog. Match the primary-colour dot on the
options button and its Update available menu item. Give the status
tooltip more room.

| Before | After |
| --- | --- |
| <img width="408" height="346" alt="8294"
src="https://github.com/user-attachments/assets/9a44dfe0-5473-4809-b705-fd6077efe44b"
/> | <img width="844" height="738" alt="CleanShot 2026-09-28 at 17 10
34@2x"
src="https://github.com/user-attachments/assets/4eba3f16-6dc4-4c02-83b4-9689203859bd"
/> |


| After |
| --- |
| <img width="426" height="472" alt="CleanShot 2026-09-28 at 17 11
27@2x"
src="https://github.com/user-attachments/assets/8b3c181c-b48e-4803-a24a-fb7dce3957d4"
/> |
| _Links ambiguous dot to dropdown menu item_  |
| <img width="1942" height="262" alt="CleanShot 2026-09-28 at 17 29
18@2x"
src="https://github.com/user-attachments/assets/efc047bb-a8ea-4041-bd0d-fa2cb15f4414"
/> |
| _Better alignment with nav bar above it_ |

## Review instructions

1. Reload Database > Pipelines and check the loading layout and
destination rows.
2. Open a pipeline detail page and check its header, update dialog, and
matching update dots.

## Checklist

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Destination rows now appear while pipeline details are loading, with
controls becoming available when the details finish loading.

* **Style**
* Loading states on the replication page now use diagram and
table-shaped placeholders.
* Updated replication page spacing, version-status tooltips, update
indicators, and the version comparison layout.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-29 11:42:58 +10:00

288 lines
11 KiB
TypeScript

import { useParams } from 'common'
import { ChevronRight, Minus } from 'lucide-react'
import { useRouter } from 'next/router'
import { useState } from 'react'
import { toast } from 'sonner'
import { cn, TableCell, TableRow } from 'ui'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import { DeleteDestination } from './DeleteDestination'
import { DestinationLogo } from './DestinationLogo'
import { DetailSubtext } from './DetailSubtext'
import { PipelineStatePill } from './PipelineStatePill'
import { PipelineStatusName } from './Replication.constants'
import {
getFormattedLagValue,
getInitialSyncProgress,
} from './ReplicationPipelineStatus/ReplicationPipelineStatus.utils'
import { RowMenu } from './RowMenu'
import { UpdateVersionModal } from './UpdateVersionModal'
import { useDestinationInformation } from './useDestinationInformation'
import { AlertError } from '@/components/ui/AlertError'
import { useDeleteDestinationPipelineMutation } from '@/data/replication/delete-destination-pipeline-mutation'
import { useReplicationPipelineReplicationStatusQuery } from '@/data/replication/pipeline-replication-status-query'
import { useReplicationPipelineStatusQuery } from '@/data/replication/pipeline-status-query'
import { useReplicationPipelineVersionQuery } from '@/data/replication/pipeline-version-query'
import { useStopPipelineMutation } from '@/data/replication/stop-pipeline-mutation'
import { createNavigationHandler } from '@/lib/navigation'
import {
PipelineStatusRequestStatus,
usePipelineRequestStatus,
} from '@/state/replication-pipeline-request-status'
import { type ResponseError } from '@/types'
interface DestinationRowProps {
destinationId: number
}
export const DestinationRow = ({ destinationId }: DestinationRowProps) => {
const router = useRouter()
const { ref: projectRef } = useParams()
const [showDeleteDestinationForm, setShowDeleteDestinationForm] = useState(false)
const [isDeleting, setIsDeleting] = useState(false)
const [showUpdateVersionModal, setShowUpdateVersionModal] = useState(false)
const { type, statusName, destination, pipeline, pipelineStatus, pipelineFetcher } =
useDestinationInformation({
id: destinationId,
})
const {
error: pipelineError,
isPending: isPipelineLoading,
isError: isPipelineError,
} = pipelineFetcher
const destinationName = destination?.name ?? pipeline?.destination_name ?? ''
const {
error: pipelineStatusError,
isPending: isPipelineStatusLoading,
isError: isPipelineStatusError,
isSuccess: isPipelineStatusSuccess,
} = useReplicationPipelineStatusQuery({
projectRef,
pipelineId: pipeline?.id,
})
const { getRequestStatus } = usePipelineRequestStatus()
const requestStatus = pipeline?.id
? getRequestStatus(pipeline.id)
: PipelineStatusRequestStatus.None
const { mutateAsync: stopPipeline } = useStopPipelineMutation({ onError: () => {} })
const { mutateAsync: deleteDestinationPipeline } = useDeleteDestinationPipelineMutation({
onError: () => {},
})
// Fetch table-level replication status to surface errors in list view
const {
data: replicationStatusData,
isPending: isReplicationStatusLoading,
isError: isReplicationStatusError,
} = useReplicationPipelineReplicationStatusQuery({ projectRef, pipelineId: pipeline?.id }, {})
const tableStatuses = replicationStatusData?.table_statuses ?? []
const errorCount = tableStatuses.filter((t) => t.state?.name === 'error').length
const applyLag = replicationStatusData?.apply_lag
// Show the byte-based slot lag (WAL the destination hasn't confirmed flushing yet). The
// time-based flush_lag from pg_stat_replication is routinely NULL for logical slots that are
// idle or don't report timed feedback, whereas confirmed_flush_lsn_bytes is always populated.
const lagBytes = applyLag?.confirmed_flush_lsn_bytes
const lag = getFormattedLagValue('bytes', lagBytes)
// The lag figure only covers ongoing changes, so it reads as "Caught up" while an initial copy
// is still running. Say what's actually happening instead.
const { syncingCount } = getInitialSyncProgress(tableStatuses)
const isInitialSyncRunning = syncingCount > 0
const isCaughtUp = lagBytes === 0
// Hide old table errors while an optimistic lifecycle action is displayed.
const isPipelineStopped = statusName === PipelineStatusName.STOPPED
const isTransitioning = requestStatus !== PipelineStatusRequestStatus.None
const hasTableErrors = errorCount > 0 && !isPipelineStopped && !isTransitioning
// Check if a newer pipeline version is available (one-time check cached for session)
const { data: versionData } = useReplicationPipelineVersionQuery({
projectRef,
pipelineId: pipeline?.id,
})
const hasUpdate = Boolean(versionData?.new_version)
const handleNavigation = pipeline
? createNavigationHandler(`/project/${projectRef}/database/pipelines/${pipeline.id}`, router)
: undefined
const onDeleteClick = async () => {
if (!projectRef) {
return console.error('Project ref is required')
}
if (!pipeline) {
return toast.error('No pipeline found')
}
try {
setIsDeleting(true)
await stopPipeline({ projectRef, pipelineId: pipeline.id, waitUntilStopped: true })
await deleteDestinationPipeline({
projectRef,
destinationId: destinationId,
pipelineId: pipeline.id,
})
// Close dialog after successful deletion
setShowDeleteDestinationForm(false)
toast.success(`Deleted pipeline "${destinationName}"`)
} catch (error) {
toast.error(`Failed to delete pipeline: ${(error as ResponseError).message}`)
} finally {
setIsDeleting(false)
}
}
// Five distinct states, so early returns rather than a ternary chain.
const renderLag = () => {
if (isReplicationStatusLoading) return <ShimmeringLoader />
if (isInitialSyncRunning)
return <span className="text-foreground-light whitespace-nowrap">Initial sync</span>
if (isReplicationStatusError || !applyLag)
return (
<>
<Minus size={18} className="text-foreground-lighter" aria-hidden />
<span className="sr-only">Lag unavailable</span>
</>
)
if (isCaughtUp)
return <span className="text-foreground-light whitespace-nowrap">Caught up</span>
return <span className="text-foreground-light whitespace-nowrap">{lag.display}</span>
}
return (
<>
{isPipelineError && (
<TableRow>
<TableCell colSpan={6}>
<AlertError error={pipelineError} subject="Failed to retrieve pipeline information" />
</TableCell>
</TableRow>
)}
{(isPipelineLoading || pipeline) && (
<TableRow
className={cn('relative', pipeline && 'cursor-pointer focus-inset')}
onClick={handleNavigation}
onAuxClick={handleNavigation}
onKeyDown={handleNavigation}
tabIndex={pipeline ? 0 : undefined}
>
<TableCell className="!pr-1">
{type ? <DestinationLogo type={type} hasErrors={hasTableErrors} /> : null}
</TableCell>
<TableCell className="max-w-[180px]">
{isPipelineLoading && !destinationName ? (
<ShimmeringLoader />
) : (
<div className="flex flex-col gap-y-0.5">
<p className="text-sm font-medium text-foreground truncate">
{destinationName || type}
</p>
{pipeline && (
<DetailSubtext className="flex items-center gap-x-1.5">
<span>#{pipeline.id}</span>
<span aria-hidden>&middot;</span>
<span>{type}</span>
{hasTableErrors && (
<>
<span aria-hidden>&middot;</span>
<span className="text-destructive">
{errorCount} table error{errorCount === 1 ? '' : 's'}
</span>
</>
)}
</DetailSubtext>
)}
</div>
)}
</TableCell>
<TableCell>
{isPipelineLoading || !pipeline ? (
<ShimmeringLoader />
) : (
<PipelineStatePill
pipelineStatus={pipelineStatus?.status}
error={pipelineStatusError}
isLoading={isPipelineStatusLoading}
isError={isPipelineStatusError}
isSuccess={isPipelineStatusSuccess}
requestStatus={requestStatus}
projectRef={projectRef}
pipelineId={pipeline?.id}
/>
)}
</TableCell>
<TableCell>
<div aria-live="polite" aria-atomic="true">
{isReplicationStatusLoading && <span className="sr-only">Loading lag</span>}
{renderLag()}
</div>
</TableCell>
<TableCell>
{isPipelineLoading || !pipeline ? (
<ShimmeringLoader />
) : (
pipeline.config.publication_name
)}
</TableCell>
<TableCell>
<div className="flex items-center justify-end gap-x-2">
{pipeline ? (
<>
<div
onClick={(event) => event.stopPropagation()}
onAuxClick={(event) => event.stopPropagation()}
onKeyDown={(event) => event.stopPropagation()}
>
<RowMenu
destinationId={destinationId}
pipeline={pipeline}
pipelineStatus={pipelineStatus?.status}
error={pipelineStatusError}
isLoading={isPipelineStatusLoading}
isError={isPipelineStatusError}
onDeleteClick={() => setShowDeleteDestinationForm(true)}
hasUpdate={hasUpdate}
onUpdateClick={() => setShowUpdateVersionModal(true)}
/>
</div>
<ChevronRight
size={16}
strokeWidth={1.5}
className="text-foreground-lighter"
aria-hidden
/>
<button tabIndex={-1} className="sr-only">
Go to pipeline details
</button>
</>
) : (
<ShimmeringLoader className="h-6 w-6 py-0" />
)}
</div>
</TableCell>
</TableRow>
)}
<DeleteDestination
visible={showDeleteDestinationForm}
setVisible={setShowDeleteDestinationForm}
onDelete={onDeleteClick}
isLoading={isDeleting}
name={destinationName}
/>
<UpdateVersionModal
visible={showUpdateVersionModal}
pipeline={pipeline}
onClose={() => setShowUpdateVersionModal(false)}
/>
</>
)
}