import { Handle, Node, NodeProps, Position } from '@xyflow/react' import { Database, DatabaseBackup, HelpCircle, Layers, Loader2, Network } from 'lucide-react' import { Badge, cn, Tooltip, TooltipContent, TooltipTrigger } from 'ui' import { ComputeMetricsFooter } from './ComputeMetricsFooter' import { HaPoolerNodeData, HaShardNodeData, MultigatewayNodeData, } from './HaInstanceConfiguration.utils' import { HA_POOLER_STATUS_LABELS, HaPoolerStatus } from './HaTopology.utils' import { NODE_CARD_WIDTH } from './InstanceConfiguration.constants' import { useHaPoolerCard } from './useHaPooler' import { BASE_PATH } from '@/lib/constants' const STATUS_BADGE_VARIANTS: Record = { healthy: 'success', coming_up: 'default', going_down: 'default', unhealthy: 'warning', } const PoolerStatusBadge = ({ status }: { status: HaPoolerStatus }) => ( {HA_POOLER_STATUS_LABELS[status]} ) const PoolerCardSubtitle = ({ availabilityZone, computeSize, }: { availabilityZone?: string computeSize?: string }) => (

{availabilityZone !== undefined && {availabilityZone}} {availabilityZone !== undefined && !!computeSize && ( · )} {!!computeSize && {computeSize}}

) export const MultigatewayNode = ({ data }: NodeProps>) => { const { numGateways } = data return ( <>

Multigateway

Load balancer {numGateways > 1 && ( <> · {numGateways} instances )}

) } export const HaPrimaryNode = ({ data }: NodeProps>) => { // [Joshen] Just FYI Handles cannot be conditionally rendered const { cell, name, hasGateway } = data const { status, availabilityZone, computeSize, primaryRegion } = useHaPoolerCard({ cell, name }) return ( <>

Primary Database

{/* Stable live region so polled status changes are announced */} {status !== undefined && }
{primaryRegion !== undefined && (

{primaryRegion.name}

)}
{primaryRegion !== undefined && ( // Decorative — the visible text next to it already names the region )}
{/* Whether connection metrics are meaningful through the multigateway is unconfirmed, so they're left off for HA projects. */}
) } export const HaReplicaNode = ({ data }: NodeProps>) => { const { cell, name } = data const { status, availabilityZone, computeSize } = useHaPoolerCard({ cell, name }) return ( <>
{status === 'coming_up' ? (

Read Replica

{/* Stable live region so polled status changes are announced */} {status !== undefined && }
) } export const HaShardNode = ({ data }: NodeProps>) => { const { name } = data return (
) }