Files
Riccardo Busetti 324c724117 ref(replication): Improve replication copy and UI (#46793)
This PR improves the replication UI in the following ways:
- Adds a new selecion picker for destinations which is split by the
destination location and it's clearer and can scale more when we add
more destinations.
- Adds a much improved section on lag, highlighting new metrics that
could help debug issues more easily.
- Improves the copy across the whole code.
- Fixes the 2d topological view of replication with better status
handling.

### Screenshots

<img width="1270" height="777" alt="image"
src="https://github.com/user-attachments/assets/0ffc890e-2f80-47e5-bdb1-75071adda024"
/>

<img width="1665" height="656" alt="image"
src="https://github.com/user-attachments/assets/23a27a02-acb2-4891-af95-5bc1d6ec7bfe"
/>

<img width="1454" height="247" alt="image"
src="https://github.com/user-attachments/assets/c8799983-aa63-42b2-9370-ae4e009c1573"
/>

<img width="1120" height="340" alt="image"
src="https://github.com/user-attachments/assets/20a18ad6-e5a9-40ec-80d4-42d6f783d868"
/>

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

* **New Features**
  * Live slot health indicators, legend, and connection badges.
  * Grouped destination type dropdown with alpha badges.

* **Improvements**
* Clearer UI copy for external destinations, alpha disclaimers, and
onboarding flows.
* Consolidated "n/a" handling for lag displays and richer metric
tooltips.
* Simplified replication diagram visuals and clearer table/row
status/lag presentation.
* Replication status responses now include expanded slot health and lag
metrics.

* **Tests**
* New test suites covering destination selection and destination row
states.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-06-11 10:58:36 +00:00

194 lines
5.8 KiB
TypeScript

import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath, type EdgeProps } from '@xyflow/react'
import { useParams } from 'common'
import { ArrowRight, Loader2, Square, X, type LucideIcon } from 'lucide-react'
import { useMemo } from 'react'
import { cn } from 'ui'
import { getStatusName } from '../Pipeline.utils'
import { STATUS_REFRESH_FREQUENCY_MS } from '../Replication.constants'
import { REPLICA_STATUS } from '@/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.constants'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { useReplicationPipelineStatusQuery } from '@/data/replication/pipeline-status-query'
import { useReplicationPipelinesQuery } from '@/data/replication/pipelines-query'
import {
PipelineStatusRequestStatus,
usePipelineRequestStatus,
} from '@/state/replication-pipeline-request-status'
type EdgeData = {
type: string
identifier: string
shiftEdgeEnd: boolean
}
interface ReplicationState {
isComingUp: boolean
isReplicating: boolean
isFailed: boolean
}
interface EdgeVisual {
Icon: LucideIcon
// CSS color shared by the icon and the connecting line so they always match.
color: string
opacity: number
dashArray: string
shouldAnimate: boolean
shouldSpin?: boolean
isFilled?: boolean
strokeWidth?: number
}
// Picks the icon + line appearance for a replication state. Both the icon and the line are derived
// here from the same state so they always stay in sync. We deliberately don't surface lag: the line
// just communicates whether data is moving, stopped, starting, or broken.
const getEdgeVisual = ({ isComingUp, isReplicating, isFailed }: ReplicationState): EdgeVisual => {
if (isFailed) {
return {
Icon: X,
color: 'hsl(var(--destructive-default))',
opacity: 1,
dashArray: '5 5',
shouldAnimate: false,
strokeWidth: 4,
}
}
if (isComingUp) {
return {
Icon: Loader2,
color: 'hsl(var(--foreground-light))',
opacity: 1,
dashArray: '5',
shouldAnimate: true,
shouldSpin: true,
}
}
if (isReplicating) {
return {
Icon: ArrowRight,
color: 'hsl(var(--brand-default))',
opacity: 1,
dashArray: '5',
shouldAnimate: true,
}
}
return {
Icon: Square,
color: 'hsl(var(--foreground-lighter))',
opacity: 0.5,
dashArray: '5 5',
shouldAnimate: false,
isFilled: true,
}
}
export const SmoothstepEdge = ({
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
style = {},
markerEnd,
data,
}: EdgeProps) => {
const { ref: projectRef = 'default' } = useParams()
const { type, identifier, shiftEdgeEnd } = (data || {}) as EdgeData
const isReplica = type === 'replica'
// Subscribe to the same live status the nodes use, so the line and the node update together.
const { data: databases = [] } = useReadReplicasQuery(
{ projectRef },
{ enabled: isReplica, refetchInterval: STATUS_REFRESH_FREQUENCY_MS }
)
const replica = databases.find((x) => x.identifier === identifier)
const { data: pipelinesData } = useReplicationPipelinesQuery(
{ projectRef },
{ enabled: !isReplica }
)
const pipeline = (pipelinesData?.pipelines ?? []).find(
(p) => p.destination_id.toString() === identifier
)
const { data: pipelineStatusData } = useReplicationPipelineStatusQuery(
{ projectRef, pipelineId: pipeline?.id },
{ enabled: !isReplica && !!pipeline?.id, refetchInterval: STATUS_REFRESH_FREQUENCY_MS }
)
const { getRequestStatus } = usePipelineRequestStatus()
const requestStatus = pipeline?.id
? getRequestStatus(pipeline.id)
: PipelineStatusRequestStatus.None
const replicationState = useMemo<ReplicationState>(() => {
if (isReplica) {
const status = replica?.status
return {
isReplicating: status === 'ACTIVE_HEALTHY',
isComingUp:
status !== undefined &&
[
REPLICA_STATUS.COMING_UP,
REPLICA_STATUS.INIT_READ_REPLICA,
REPLICA_STATUS.UNKNOWN,
].includes(status),
isFailed:
status !== undefined &&
[REPLICA_STATUS.ACTIVE_UNHEALTHY, REPLICA_STATUS.INIT_FAILED].includes(status),
}
}
const isTransitioning = requestStatus !== PipelineStatusRequestStatus.None
const statusName = getStatusName(pipelineStatusData?.status)
return {
isReplicating: statusName === 'started' && !isTransitioning,
isComingUp: isTransitioning || statusName === 'starting' || statusName === 'stopping',
isFailed: statusName === 'failed',
}
}, [isReplica, replica?.status, pipelineStatusData?.status, requestStatus])
const [edgePath, labelX, labelY] = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
})
const { Icon, color, opacity, dashArray, shouldAnimate, shouldSpin, isFilled, strokeWidth } =
getEdgeVisual(replicationState)
return (
<>
<BaseEdge
path={edgePath}
markerEnd={markerEnd}
style={{
...style,
stroke: color,
opacity,
strokeDasharray: dashArray,
animation: shouldAnimate ? 'dashdraw 0.5s linear infinite' : undefined,
}}
/>
<EdgeLabelRenderer>
<div
className="bg-surface-100 p-1 rounded-sm absolute nodrag nopan border"
style={{
transform: `translate(-50%, -50%) translate(${shiftEdgeEnd ? targetX - 30 : labelX}px,${shiftEdgeEnd ? targetY : labelY}px)`,
}}
>
<Icon
size={12}
strokeWidth={strokeWidth ?? 2}
fill={isFilled ? 'currentColor' : 'none'}
className={cn(shouldSpin && 'animate-spin')}
style={{ color }}
/>
</div>
</EdgeLabelRenderer>
</>
)
}