Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Chore/remove optimistic rendering for spinning up replicas (#26331)

Joshen Limb638f53ce03f
diff --git a/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/QueryError.tsx b/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/QueryError.tsx
index c75de7dde2d..b650ca3cead 100644
--- a/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/QueryError.tsx
+++ b/apps/studio/components/interfaces/Auth/Policies/AIPolicyEditorPanel/QueryError.tsx
@@ -52,9 +52,9 @@ const QueryError = ({
className="w-5 h-5"
>
<path
- fill-rule="evenodd"
+ fillRule="evenodd"
+ clipRule="evenodd"
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z"
- clip-rule="evenodd"
/>
</svg>
<div className="flex flex-col gap-3">
diff --git a/apps/studio/components/interfaces/Settings/Database/UsePoolerCheckbox.tsx b/apps/studio/components/interfaces/Settings/Database/UsePoolerCheckbox.tsx
index a7e4f9680af..fb09d4dfad0 100644
--- a/apps/studio/components/interfaces/Settings/Database/UsePoolerCheckbox.tsx
+++ b/apps/studio/components/interfaces/Settings/Database/UsePoolerCheckbox.tsx
@@ -64,7 +64,7 @@ export const UsePoolerCheckbox = ({
return (
<>
<div className="flex flex-col gap-y-1">
- <div className="flex gap-x-3">
+ <div className="flex gap-x-3 items-center">
<Checkbox_Shadcn_
id={`use-pooler-${id}`}
checked={checked}
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/Edge.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/Edge.tsx
index 90b751e2468..63259d94e7b 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/Edge.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/Edge.tsx
@@ -1,10 +1,12 @@
-import { useParams } from 'common'
-import { useReplicationLagQuery } from 'data/read-replicas/replica-lag-query'
-import { formatDatabaseID } from 'data/read-replicas/replicas.utils'
import { Loader2 } from 'lucide-react'
import type { EdgeProps } from 'reactflow'
import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath } from 'reactflow'
+
+import { useParams } from 'common'
+import { useReplicationLagQuery } from 'data/read-replicas/replica-lag-query'
+import { formatDatabaseID } from 'data/read-replicas/replicas.utils'
import { TooltipContent_Shadcn_, TooltipTrigger_Shadcn_, Tooltip_Shadcn_ } from 'ui'
+import { REPLICA_STATUS } from './InstanceConfiguration.constants'
export const SmoothstepEdge = ({
id,
@@ -20,7 +22,7 @@ export const SmoothstepEdge = ({
}: EdgeProps) => {
const { ref } = useParams()
// [Joshen] Only applicable for replicas
- const { identifier, connectionString } = data || {}
+ const { status, identifier, connectionString } = data || {}
const formattedId = formatDatabaseID(identifier ?? '')
const [edgePath, labelX, labelY] = getSmoothStepPath({
@@ -36,17 +38,20 @@ export const SmoothstepEdge = ({
data: lagDuration,
isLoading,
isError,
- } = useReplicationLagQuery({
- id: identifier,
- projectRef: ref,
- connectionString,
- })
+ } = useReplicationLagQuery(
+ {
+ id: identifier,
+ projectRef: ref,
+ connectionString,
+ },
+ { enabled: status === REPLICA_STATUS.ACTIVE_HEALTHY }
+ )
const lagValue = Number(lagDuration?.toFixed(2) ?? 0).toLocaleString()
return (
<>
<BaseEdge path={edgePath} markerEnd={markerEnd} style={style} />
- {data !== undefined && !isError && (
+ {data !== undefined && !isError && status === REPLICA_STATUS.ACTIVE_HEALTHY && (
<EdgeLabelRenderer>
<Tooltip_Shadcn_>
<TooltipTrigger_Shadcn_ asChild>
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsx
index 5a7db3ee91d..aa8f15f94a4 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.tsx
@@ -32,10 +32,6 @@ import MapView from './MapView'
import { RestartReplicaConfirmationModal } from './RestartReplicaConfirmationModal'
import { SmoothstepEdge } from './Edge'
-// [Joshen] Just FYI, UI assumes single provider for primary + replicas
-// [Joshen] Idea to visualize grouping based on region: https://reactflow.dev/examples/layout/sub-flows
-// [Joshen] Show flags for regions
-
const InstanceConfigurationUI = () => {
const reactFlow = useReactFlow()
const { resolvedTheme } = useTheme()
@@ -144,6 +140,7 @@ const InstanceConfigurationUI = () => {
animated: true,
className: '!cursor-default',
data: {
+ status: database.status,
identifier: database.identifier,
connectionString: database.connectionString,
},
@@ -164,9 +161,12 @@ const InstanceConfigurationUI = () => {
[]
)
- const edgeTypes = {
- smoothstep: SmoothstepEdge,
- }
+ const edgeTypes = useMemo(
+ () => ({
+ smoothstep: SmoothstepEdge,
+ }),
+ []
+ )
const setReactFlow = async () => {
const graph = getDagreGraphLayout(nodes, edges)
@@ -182,8 +182,9 @@ const InstanceConfigurationUI = () => {
// [Joshen] Just FYI this block is oddly triggering whenever we refocus on the viewport
// even if I change the dependency array to just data. Not blocker, just an area to optimize
useEffect(() => {
- if (isSuccessReplicas && isSuccessLoadBalancers && nodes.length > 0 && view === 'flow')
+ if (isSuccessReplicas && isSuccessLoadBalancers && nodes.length > 0 && view === 'flow') {
setReactFlow()
+ }
}, [isSuccessReplicas, isSuccessLoadBalancers, nodes, edges, view])
return (
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsx
index bfb96cd8d50..e5eddad62f9 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsx
@@ -1,8 +1,11 @@
-import { useParams } from 'common'
import dayjs from 'dayjs'
-import { Database, DatabaseBackup, HelpCircle, Loader2 } from 'lucide-react'
+import { Database, DatabaseBackup, HelpCircle, Loader2, MoreVertical } from 'lucide-react'
import Link from 'next/link'
import { Handle, NodeProps, Position } from 'reactflow'
+
+import { useParams } from 'common'
+import { formatDatabaseID } from 'data/read-replicas/replicas.utils'
+import { BASE_PATH, PROJECT_STATUS } from 'lib/constants'
import {
Badge,
Button,
@@ -11,15 +14,11 @@ import {
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
- IconMoreVertical,
TooltipContent_Shadcn_,
TooltipTrigger_Shadcn_,
Tooltip_Shadcn_,
cn,
} from 'ui'
-
-import { formatDatabaseID } from 'data/read-replicas/replicas.utils'
-import { BASE_PATH, PROJECT_STATUS } from 'lib/constants'
import { NODE_SEP, NODE_WIDTH, REPLICA_STATUS, Region } from './InstanceConfiguration.constants'
interface NodeData {
@@ -72,7 +71,7 @@ export const LoadBalancerNode = ({ data }: NodeProps<LoadBalancerData>) => {
</div>
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
- <Button type="text" icon={<IconMoreVertical />} className="px-1" />
+ <Button type="text" icon={<MoreVertical />} className="px-1" />
</DropdownMenuTrigger>
<DropdownMenuContent className="w-40" side="bottom" align="end">
<DropdownMenuItem asChild className="gap-x-2">
@@ -82,29 +81,23 @@ export const LoadBalancerNode = ({ data }: NodeProps<LoadBalancerData>) => {
</DropdownMenu>
</div>
</div>
- <Handle
- type="source"
- id="handle-b"
- position={Position.Bottom}
- style={{ background: 'transparent' }}
- />
+ <Handle type="source" position={Position.Bottom} style={{ background: 'transparent' }} />
</>
)
}
export const PrimaryNode = ({ data }: NodeProps<PrimaryNodeData>) => {
+ // [Joshen] Just FYI Handles cannot be conditionally rendered
const { provider, region, computeSize, numReplicas, numRegions, hasLoadBalancer } = data
return (
<>
- {hasLoadBalancer && (
- <Handle
- type="target"
- id="handle-t"
- position={Position.Top}
- style={{ background: 'transparent' }}
- />
- )}
+ <Handle
+ type="target"
+ position={Position.Top}
+ className={!hasLoadBalancer ? 'opacity-0' : ''}
+ style={{ background: 'transparent' }}
+ />
<div className="flex flex-col rounded bg-surface-100 border border-default">
<div
className="flex items-start justify-between p-3"
@@ -146,14 +139,12 @@ export const PrimaryNode = ({ data }: NodeProps<PrimaryNodeData>) => {
</div>
)}
</div>
- {numReplicas > 0 && (
- <Handle
- type="source"
- id="handle-b"
- position={Position.Bottom}
- style={{ background: 'transparent' }}
- />
- )}
+ <Handle
+ type="source"
+ position={Position.Bottom}
+ className={numReplicas === 0 ? 'opacity-0' : ''}
+ style={{ background: 'transparent' }}
+ />
</>
)
}
@@ -184,12 +175,7 @@ export const ReplicaNode = ({ data }: NodeProps<ReplicaNodeData>) => {
return (
<>
- <Handle
- type="target"
- id="handle-t"
- position={Position.Top}
- style={{ background: 'transparent' }}
- />
+ <Handle type="target" position={Position.Top} style={{ background: 'transparent' }} />
<div
className="flex justify-between items-start rounded bg-surface-100 border border-default p-3"
style={{ width: NODE_WIDTH / 2 - 10 }}
@@ -235,7 +221,7 @@ export const ReplicaNode = ({ data }: NodeProps<ReplicaNodeData>) => {
</TooltipContent_Shadcn_>
</Tooltip_Shadcn_>
</>
- ) : status === REPLICA_STATUS.COMING_UP ? (
+ ) : status === REPLICA_STATUS.COMING_UP || status === REPLICA_STATUS.UNKNOWN ? (
<Badge>Coming up</Badge>
) : status === REPLICA_STATUS.GOING_DOWN ? (
<Badge>Going down</Badge>
@@ -258,7 +244,7 @@ export const ReplicaNode = ({ data }: NodeProps<ReplicaNodeData>) => {
</div>
<DropdownMenu modal={false}>
<DropdownMenuTrigger asChild>
- <Button type="text" icon={<IconMoreVertical />} className="px-1" />
+ <Button type="text" icon={<MoreVertical />} className="px-1" />
</DropdownMenuTrigger>
<DropdownMenuContent className="w-40" side="bottom" align="end">
<DropdownMenuItem
diff --git a/apps/studio/data/read-replicas/replica-setup-mutation.ts b/apps/studio/data/read-replicas/replica-setup-mutation.ts
index 6fc0f28cc0b..1047e8414ab 100644
--- a/apps/studio/data/read-replicas/replica-setup-mutation.ts
+++ b/apps/studio/data/read-replicas/replica-setup-mutation.ts
@@ -4,7 +4,6 @@ import { toast } from 'react-hot-toast'
import { post } from 'data/fetchers'
import type { ResponseError } from 'types'
import { replicaKeys } from './keys'
-import type { Database } from './replicas-query'
export type Region =
| 'us-east-1'
@@ -56,32 +55,8 @@ export const useReadReplicaSetUpMutation = ({
(vars) => setUpReadReplica(vars),
{
async onSuccess(data, variables, context) {
- const { projectRef, region, size } = variables
-
- // [Joshen] Just FYI, will remove this once API changes to remove the need for optimistic rendering
- queryClient.setQueriesData<any>(replicaKeys.list(projectRef), (old: any) => {
- const scaffoldNewDatabase: Database = {
- db_port: 5432,
- db_name: 'postgres',
- db_user: 'postgres',
- restUrl: '',
- db_host: '',
- connectionString: '',
- identifier: `${projectRef}-rr-${region}-None`,
- size,
- region,
- inserted_at: new Date().toISOString(),
- status: 'COMING_UP',
- cloud_provider: 'AWS',
- }
- return [...old, scaffoldNewDatabase]
- })
-
- // [Joshen] Wait 30 seconds before checking if the replica actually is coming up
- setTimeout(async () => {
- await queryClient.invalidateQueries(replicaKeys.list(projectRef))
- }, 30000)
-
+ const { projectRef } = variables
+ await queryClient.invalidateQueries(replicaKeys.list(projectRef))
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
diff --git a/packages/ui/src/components/Admonition/index.tsx b/packages/ui/src/components/Admonition/index.tsx
index adc75be451b..158f272de21 100644
--- a/packages/ui/src/components/Admonition/index.tsx
+++ b/packages/ui/src/components/Admonition/index.tsx
@@ -40,8 +40,8 @@ const InfoIcon = () => (
fill="currentColor"
>
<path
- fill-rule="evenodd"
- clip-rule="evenodd"
+ fillRule="evenodd"
+ clipRule="evenodd"
d="M0.625 9.8252C0.625 4.44043 4.99023 0.0751953 10.375 0.0751953C15.7598 0.0751953 20.125 4.44043 20.125 9.8252C20.125 15.21 15.7598 19.5752 10.375 19.5752C4.99023 19.5752 0.625 15.21 0.625 9.8252ZM9.3584 4.38135C9.45117 4.28857 9.55518 4.20996 9.66699 4.14648C9.88086 4.02539 10.1245 3.96045 10.375 3.96045C10.5845 3.96045 10.7896 4.00586 10.9766 4.09229C11.1294 4.1626 11.2705 4.26025 11.3916 4.38135C11.6611 4.65088 11.8125 5.0166 11.8125 5.39795C11.8125 5.5249 11.7959 5.6499 11.7637 5.77002C11.6987 6.01172 11.5718 6.23438 11.3916 6.41455C11.1221 6.68408 10.7563 6.83545 10.375 6.83545C9.99365 6.83545 9.62793 6.68408 9.3584 6.41455C9.08887 6.14502 8.9375 5.7793 8.9375 5.39795C8.9375 5.29492 8.94873 5.19287 8.97021 5.09375C9.02783 4.82568 9.16162 4.57812 9.3584 4.38135ZM10.375 15.6899C10.0933 15.6899 9.82275 15.5781 9.62354 15.3789C9.42432 15.1797 9.3125 14.9092 9.3125 14.6274V9.31494C9.3125 9.0332 9.42432 8.7627 9.62354 8.56348C9.82275 8.36426 10.0933 8.25244 10.375 8.25244C10.6567 8.25244 10.9272 8.36426 11.1265 8.56348C11.3257 8.7627 11.4375 9.0332 11.4375 9.31494V14.6274C11.4375 14.7944 11.3979 14.9575 11.3242 15.104C11.2739 15.2046 11.2075 15.2979 11.1265 15.3789C10.9272 15.5781 10.6567 15.6899 10.375 15.6899Z"
/>
</svg>
@@ -55,8 +55,8 @@ const WarningIcon = () => (
fill="currentColor"
>
<path
- fill-rule="evenodd"
- clip-rule="evenodd"
+ fillRule="evenodd"
+ clipRule="evenodd"
d="M8.15137 1.95117C9.30615 -0.0488281 12.1943 -0.0488281 13.3481 1.95117L20.7031 14.6992C21.8574 16.6992 20.4131 19.1992 18.104 19.1992H3.39502C1.08594 19.1992 -0.356933 16.6992 0.797364 14.6992L8.15137 1.95117ZM11.7666 16.0083C11.4971 16.2778 11.1313 16.4292 10.75 16.4292C10.3687 16.4292 10.0029 16.2778 9.7334 16.0083C9.46387 15.7388 9.3125 15.373 9.3125 14.9917C9.3125 14.9307 9.31641 14.8706 9.32373 14.811C9.33545 14.7197 9.35547 14.6304 9.38379 14.5439L9.41406 14.4609C9.48584 14.2803 9.59375 14.1147 9.7334 13.9751C10.0029 13.7056 10.3687 13.5542 10.75 13.5542C11.1313 13.5542 11.4971 13.7056 11.7666 13.9751C12.0361 14.2446 12.1875 14.6104 12.1875 14.9917C12.1875 15.373 12.0361 15.7388 11.7666 16.0083ZM10.75 4.69971C11.0317 4.69971 11.3022 4.81152 11.5015 5.01074C11.7007 5.20996 11.8125 5.48047 11.8125 5.76221V11.0747C11.8125 11.3564 11.7007 11.627 11.5015 11.8262C11.3022 12.0254 11.0317 12.1372 10.75 12.1372C10.4683 12.1372 10.1978 12.0254 9.99854 11.8262C9.79932 11.627 9.6875 11.3564 9.6875 11.0747V5.76221C9.6875 5.48047 9.79932 5.20996 9.99854 5.01074C10.1978 4.81152 10.4683 4.69971 10.75 4.69971Z"
/>
</svg>