mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
## What kind of change does this PR introduce? Feature. Stack 1 of 5 for [PIPE-1007](https://linear.app/supabase/issue/PIPE-1007/move-read-replicas-out-of-replication-into-infrastructure). ## What is the current behavior? Read replica UI lives under Database / Replication. ## What is the new behavior? Moves replica form, row, and modals into Settings/Infrastructure and extracts `REPLICA_STATUS` plus path helpers. URLs and user-facing behaviour are unchanged. ## Additional context Keep `infrastructure:read_replicas` off in prod until the full stack lands. Stack: this PR → [#49044](https://github.com/supabase/supabase/pull/49044) → [#49045](https://github.com/supabase/supabase/pull/49045) → [#49046](https://github.com/supabase/supabase/pull/49046) → [#48921](https://github.com/supabase/supabase/pull/48921) ## To test Open [Database / Replication](https://studio-staging-git-danny-pipe-1007-01-relocate-701014-supabase.vercel.app/dashboard/project/_/database/replication?destinationType=Read+Replica). Confirm add replica still works as today. No new Infrastructure section yet. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added navigation for viewing a specific read replica and starting the add-replica setup flow. - Improved read-replica setup validation, including unsupported regions and invalid PostgreSQL versions. - **Bug Fixes** - Corrected default region and success messaging behavior. - Prevented incomplete pricing labels and clarified eligibility warnings. - Improved display handling for localized pricing values. - **Tests** - Added coverage for read-replica navigation paths and fallback behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
import { BaseEdge, Edge, EdgeLabelRenderer, getSmoothStepPath, type EdgeProps } from '@xyflow/react'
|
|
import { useParams } from 'common'
|
|
import { Loader2 } from 'lucide-react'
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
|
|
import { EdgeData } from './InstanceConfiguration.constants'
|
|
import { REPLICA_STATUS } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicas.constants'
|
|
import { useReplicationLagQuery } from '@/data/read-replicas/replica-lag-query'
|
|
import { formatDatabaseID } from '@/data/read-replicas/replicas.utils'
|
|
|
|
export const SmoothstepEdge = ({
|
|
sourceX,
|
|
sourceY,
|
|
targetX,
|
|
targetY,
|
|
sourcePosition,
|
|
targetPosition,
|
|
style = {},
|
|
markerEnd,
|
|
data,
|
|
}: EdgeProps<Edge<EdgeData>>) => {
|
|
const { ref } = useParams()
|
|
// [Joshen] Only applicable for replicas
|
|
const { status, identifier, connectionString } = data || {}
|
|
const formattedId = formatDatabaseID(identifier ?? '')
|
|
|
|
const [edgePath, labelX, labelY] = getSmoothStepPath({
|
|
sourceX,
|
|
sourceY,
|
|
sourcePosition,
|
|
targetX,
|
|
targetY,
|
|
targetPosition,
|
|
})
|
|
|
|
const {
|
|
data: lagDuration,
|
|
isPending: isLoading,
|
|
isError,
|
|
} = useReplicationLagQuery(
|
|
{
|
|
// Safe cast as the query isn't enable if identifier is null/undefined
|
|
id: identifier as string,
|
|
projectRef: ref,
|
|
connectionString,
|
|
},
|
|
{ enabled: identifier != null && status === REPLICA_STATUS.ACTIVE_HEALTHY }
|
|
)
|
|
const lagValue = Number(lagDuration?.toFixed(2) ?? 0).toLocaleString()
|
|
|
|
return (
|
|
<>
|
|
<BaseEdge path={edgePath} markerEnd={markerEnd} style={style} />
|
|
{data !== undefined && !isError && status === REPLICA_STATUS.ACTIVE_HEALTHY && (
|
|
<EdgeLabelRenderer>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<div
|
|
className="bg-surface-100 px-1.5 py-0.5 rounded-sm absolute nodrag nopan"
|
|
style={{
|
|
transform: `translate(-50%, -50%) translate(${labelX}px,${labelY}px)`,
|
|
pointerEvents: 'all',
|
|
}}
|
|
>
|
|
{isLoading ? (
|
|
<Loader2 size={12} className="animate-spin" />
|
|
) : (
|
|
<p className="font-mono text-xs">{lagValue}s</p>
|
|
)}
|
|
</div>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom" align="center">
|
|
{isLoading
|
|
? `Checking replication lag for replica ID: ${formattedId}`
|
|
: `Replication lag (seconds) for replica ID: ${formattedId}`}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</EdgeLabelRenderer>
|
|
)}
|
|
</>
|
|
)
|
|
}
|