mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 02:15:05 +03:00
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 -->
209 lines
7.3 KiB
TypeScript
209 lines
7.3 KiB
TypeScript
import { useParams } from 'common'
|
|
import { ArrowUpCircle, Edit, MoreVertical, Pause, Play, RotateCcw, Trash } from 'lucide-react'
|
|
import { parseAsInteger, useQueryState } from 'nuqs'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
WarningIcon,
|
|
} from 'ui'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import {
|
|
getStatusName,
|
|
PIPELINE_DISABLE_ALLOWED_FROM,
|
|
PIPELINE_ENABLE_ALLOWED_FROM,
|
|
} from './Pipeline.utils'
|
|
import { PipelineStatusName } from './Replication.constants'
|
|
import { ReplicationPipelineStatusData } from '@/data/replication/pipeline-status-query'
|
|
import { Pipeline } from '@/data/replication/pipelines-query'
|
|
import { useRestartPipelineHelper } from '@/data/replication/restart-pipeline-helper'
|
|
import { useStartPipelineMutation } from '@/data/replication/start-pipeline-mutation'
|
|
import { useStopPipelineMutation } from '@/data/replication/stop-pipeline-mutation'
|
|
import {
|
|
PipelineStatusRequestStatus,
|
|
usePipelineRequestStatus,
|
|
} from '@/state/replication-pipeline-request-status'
|
|
import type { ResponseError } from '@/types'
|
|
|
|
interface RowMenuProps {
|
|
destinationId: number
|
|
pipeline: Pipeline | undefined
|
|
pipelineStatus?: ReplicationPipelineStatusData['status']
|
|
error: ResponseError | null
|
|
isLoading: boolean
|
|
isError: boolean
|
|
hasUpdate?: boolean
|
|
onDeleteClick: () => void
|
|
onUpdateClick?: () => void
|
|
}
|
|
|
|
export const RowMenu = ({
|
|
destinationId,
|
|
pipeline,
|
|
pipelineStatus,
|
|
error,
|
|
isLoading,
|
|
isError,
|
|
hasUpdate = false,
|
|
onDeleteClick,
|
|
onUpdateClick,
|
|
}: RowMenuProps) => {
|
|
const { ref: projectRef } = useParams()
|
|
const statusName = getStatusName(pipelineStatus)
|
|
|
|
const [, setEdit] = useQueryState(
|
|
'edit',
|
|
parseAsInteger.withOptions({ history: 'push', clearOnDefault: true })
|
|
)
|
|
|
|
const { mutateAsync: startPipeline } = useStartPipelineMutation()
|
|
const { mutateAsync: stopPipeline } = useStopPipelineMutation()
|
|
const { restartPipeline } = useRestartPipelineHelper()
|
|
const { getRequestStatus, setRequestStatus: setGlobalRequestStatus } = usePipelineRequestStatus()
|
|
const requestStatus = pipeline?.id
|
|
? getRequestStatus(pipeline.id)
|
|
: PipelineStatusRequestStatus.None
|
|
|
|
// Show actions when not in a transitional state
|
|
const canPerformActions =
|
|
requestStatus === PipelineStatusRequestStatus.None &&
|
|
statusName !== PipelineStatusName.STARTING &&
|
|
[PipelineStatusName.STOPPED, PipelineStatusName.STARTED, PipelineStatusName.FAILED].includes(
|
|
statusName as PipelineStatusName
|
|
)
|
|
|
|
// Show both stop and restart for started/failed states
|
|
const showStopAndRestart =
|
|
canPerformActions &&
|
|
(statusName === PipelineStatusName.STARTED || statusName === PipelineStatusName.FAILED)
|
|
|
|
// Show only start for stopped state
|
|
const showStart = canPerformActions && statusName === PipelineStatusName.STOPPED
|
|
|
|
const onEnablePipeline = async () => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
if (!pipeline) return toast.error('No pipeline found')
|
|
|
|
try {
|
|
// Only show 'enabling' when transitioning from allowed states
|
|
if (PIPELINE_ENABLE_ALLOWED_FROM.includes(statusName as PipelineStatusName)) {
|
|
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.StartRequested, statusName)
|
|
}
|
|
await startPipeline({ projectRef, pipelineId: pipeline.id })
|
|
} catch (error) {
|
|
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.None)
|
|
toast.error(`Failed to start pipeline: ${(error as ResponseError).message}`)
|
|
}
|
|
}
|
|
|
|
const onDisablePipeline = async () => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
if (!pipeline) return toast.error('No pipeline found')
|
|
|
|
try {
|
|
// Only show 'disabling' when transitioning from allowed states
|
|
if (PIPELINE_DISABLE_ALLOWED_FROM.includes(statusName as PipelineStatusName)) {
|
|
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.StopRequested, statusName)
|
|
}
|
|
await stopPipeline({ projectRef, pipelineId: pipeline.id })
|
|
} catch (error) {
|
|
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.None)
|
|
toast.error(`Failed to stop pipeline: ${(error as ResponseError).message}`)
|
|
}
|
|
}
|
|
|
|
const onRestartPipeline = async () => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
if (!pipeline) return toast.error('No pipeline found')
|
|
|
|
try {
|
|
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.RestartRequested, statusName)
|
|
await restartPipeline({ projectRef, pipelineId: pipeline.id })
|
|
} catch (error) {
|
|
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.None)
|
|
toast.error(`Failed to restart pipeline: ${(error as ResponseError).message}`)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex justify-end items-center space-x-2">
|
|
{isLoading && <ShimmeringLoader />}
|
|
|
|
{isError && (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span className="flex items-center" tabIndex={0}>
|
|
<WarningIcon />
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom" className="max-w-xs">
|
|
Couldn't load status{error?.message ? `: ${error.message}` : '.'}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<div className="relative">
|
|
<Button type="default" className="px-1.5" icon={<MoreVertical />} />
|
|
{hasUpdate && (
|
|
<span className="absolute -top-0.5 -right-0.5 h-2 w-2 bg-brand rounded-full" />
|
|
)}
|
|
</div>
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent side="bottom" align="end" className="w-52">
|
|
{hasUpdate && (
|
|
<>
|
|
<DropdownMenuItem className="space-x-2" onClick={() => onUpdateClick?.()}>
|
|
<ArrowUpCircle size={14} />
|
|
<p>Update available</p>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
</>
|
|
)}
|
|
{showStart && (
|
|
<>
|
|
<DropdownMenuItem className="space-x-2" onClick={onEnablePipeline}>
|
|
<Play size={14} />
|
|
<p>Start pipeline</p>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
</>
|
|
)}
|
|
{showStopAndRestart && (
|
|
<>
|
|
<DropdownMenuItem className="space-x-2" onClick={onRestartPipeline}>
|
|
<RotateCcw size={14} />
|
|
<p>Restart pipeline</p>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem className="space-x-2" onClick={onDisablePipeline}>
|
|
<Pause size={14} />
|
|
<p>Stop pipeline</p>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
</>
|
|
)}
|
|
|
|
<DropdownMenuItem className="space-x-2" onClick={() => setEdit(destinationId)}>
|
|
<Edit size={14} />
|
|
<p>Edit destination</p>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem className="space-x-2" onClick={onDeleteClick}>
|
|
<Trash size={14} />
|
|
<p>Delete destination</p>
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
)
|
|
}
|