The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(studio): move read replica creation to a dialog (#49516)
Danny White34d6c2fbc5fd
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaDialog.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaDialog.tsxnew file mode 100644index 00000000000..3dc976d5c56--- /dev/null+++ b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaDialog.tsx@@ -0,0 +1,62 @@+import { useRef } from 'react'+import { Dialog, DialogContent, DialogHeader, DialogSectionSeparator, DialogTitle } from 'ui'++import { ReadReplicaForm } from './ReadReplicaForm'+import type { RecommendedComputeForReadReplicas } from './recommendCompute'++interface AddReadReplicaDialogProps {+ open: boolean+ onOpenChange: (open: boolean) => void+ onSuccess?: () => void+ onRecommendCompute: (size: RecommendedComputeForReadReplicas) => void+}++export const AddReadReplicaDialog = ({+ open,+ onOpenChange,+ onSuccess,+ onRecommendCompute,+}: AddReadReplicaDialogProps) => {+ const pendingRecommendationRef = useRef<RecommendedComputeForReadReplicas | null>(null)++ const onClose = () => {+ onOpenChange(false)+ }++ const closeWithRecommendation = (size: RecommendedComputeForReadReplicas) => {+ pendingRecommendationRef.current = size+ onClose()+ }++ return (+ <Dialog open={open} onOpenChange={onOpenChange}>+ <DialogContent+ size="small"+ aria-describedby={undefined}+ onCloseAutoFocus={(event) => {+ const recommendation = pendingRecommendationRef.current+ if (!recommendation) return++ // The recommendation replaces the trigger as the close destination.+ // Radix calls this after the close animation has completed.+ event.preventDefault()+ pendingRecommendationRef.current = null+ onRecommendCompute(recommendation)+ }}+ >+ <div className="flex min-h-0 flex-col" tabIndex={-1}>+ <DialogHeader>+ <DialogTitle>Add read replica</DialogTitle>+ </DialogHeader>+ <DialogSectionSeparator />++ <ReadReplicaForm+ onClose={onClose}+ onSuccess={() => onSuccess?.()}+ onRecommendCompute={closeWithRecommendation}+ />+ </div>+ </DialogContent>+ </Dialog>+ )+}diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaSheet.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaSheet.tsxdeleted file mode 100644index 2fbf15f6c4e..00000000000--- a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaSheet.tsx+++ /dev/null@@ -1,93 +0,0 @@-import { parseAsBoolean, useQueryState } from 'nuqs'-import { useRef } from 'react'-import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from 'ui'--import { ReadReplicaForm } from './ReadReplicaForm'-import type { RecommendedComputeForReadReplicas } from './recommendCompute'-import { DiscardChangesConfirmationDialog } from '@/components/ui-patterns/Dialogs/DiscardChangesConfirmationDialog'-import { DocsButton } from '@/components/ui/DocsButton'-import { useConfirmOnClose } from '@/hooks/ui/useConfirmOnClose'-import { DOCS_URL } from '@/lib/constants'--interface AddReadReplicaSheetProps {- onSuccess?: () => void- onRecommendCompute: (size: RecommendedComputeForReadReplicas) => void-}--export const AddReadReplicaSheet = ({- onSuccess,- onRecommendCompute,-}: AddReadReplicaSheetProps) => {- const [visible, setVisible] = useQueryState(- 'addReplica',- parseAsBoolean.withDefault(false).withOptions({- history: 'push',- clearOnDefault: true,- scroll: false,- })- )-- const checkIsDirtyRef = useRef<() => boolean>(() => false)- const pendingRecommendationRef = useRef<RecommendedComputeForReadReplicas | null>(null)-- const onClose = () => {- checkIsDirtyRef.current = () => false- setVisible(false)- }-- const { confirmOnClose, handleOpenChange, modalProps } = useConfirmOnClose({- checkIsDirty: () => checkIsDirtyRef.current(),- onClose,- })-- const closeWithRecommendation = (size: RecommendedComputeForReadReplicas) => {- pendingRecommendationRef.current = size- onClose()- }-- return (- <>- <Sheet open={visible} onOpenChange={handleOpenChange}>- <SheetContent- size="lg"- showClose={false}- className="max-w-3xl"- onCloseAutoFocus={(event) => {- const recommendation = pendingRecommendationRef.current- if (!recommendation) return-- // The recommendation replaces the trigger as the close destination.- // Radix calls this after the close animation has completed.- event.preventDefault()- pendingRecommendationRef.current = null- onRecommendCompute(recommendation)- }}- >- <div className="flex flex-col h-full min-h-0" tabIndex={-1}>- <SheetHeader className="flex items-center justify-between">- <div>- <SheetTitle>Add read replica</SheetTitle>- <SheetDescription>- Deploy a read-only copy of the complete Postgres database.- </SheetDescription>- </div>- <DocsButton- href={`${DOCS_URL}/guides/platform/read-replicas`}- topic="read replica settings"- />- </SheetHeader>-- <ReadReplicaForm- checkIsDirtyRef={checkIsDirtyRef}- onClose={onClose}- onCancel={confirmOnClose}- onSuccess={() => onSuccess?.()}- onRecommendCompute={closeWithRecommendation}- />- </div>- </SheetContent>- </Sheet>- <DiscardChangesConfirmationDialog {...modalProps} />- </>- )-}diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsxindex 043e37e1a8f..fd0f561a1c4 100644--- a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx+++ b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx@@ -13,6 +13,7 @@ import {import { useCheckEligibilityDeployReplica } from './useCheckEligibilityDeployReplica'import { SupportLink } from '@/components/interfaces/Support/SupportLink'import { DocsButton } from '@/components/ui/DocsButton'+import { InlineLink } from '@/components/ui/InlineLink'import { UpgradePlanButton } from '@/components/ui/UpgradePlanButton'import { useEnablePhysicalBackupsMutation } from '@/data/database/enable-physical-backups-mutation'import { useProjectDetailQuery } from '@/data/projects/project-detail-query'@@ -22,10 +23,12 @@ import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'import { DOCS_URL } from '@/lib/constants'interface ReadReplicaEligibilityWarningsProps {+ eligibility: ReturnType<typeof useCheckEligibilityDeployReplica>onRecommendCompute: (size: RecommendedComputeForReadReplicas) => void}export const ReadReplicaEligibilityWarnings = ({+ eligibility,onRecommendCompute,}: ReadReplicaEligibilityWarningsProps) => {const { ref: projectRef } = useParams()@@ -46,7 +49,7 @@ export const ReadReplicaEligibilityWarnings = ({isProWithSpendCapEnabled,isReachedMaxReplicas,maxNumberOfReplicas,- } = useCheckEligibilityDeployReplica()+ } = eligibilityconst { data: projectDetail, isSuccess: isProjectDetailSuccess } = useProjectDetailQuery({ ref: projectRef },@@ -139,29 +142,36 @@ export const ReadReplicaEligibilityWarnings = ({if (isBelowSmallCompute) {return (- <Admonition type="warning" title="Project required to at least be on a Small compute">- <p>- This is to ensure that read replicas can keep up with the primary database’s activities.- </p>- <div className="flex items-center gap-x-2 mt-2">- {isFreePlan ? (- <UpgradePlanButton- variant="default"- plan="Pro"- addon="computeSize"- source="read-replicas"- featureProposition="deploy Read Replicas"- />- ) : (- <Button- variant="default"- onClick={() => onRecommendCompute(RECOMMENDED_COMPUTE_FOR_READ_REPLICAS.minimum)}- >- Change to Small compute- </Button>- )}- <DocsButton href={`${DOCS_URL}/guides/platform/read-replicas#prerequisites`} />- </div>+ <Admonition+ type="warning"+ title="Small compute required"+ description={+ <p>+ Read replicas require at least Small compute to keep up with the primary database.{' '}+ <InlineLink href={`${DOCS_URL}/guides/platform/read-replicas#prerequisites`}>+ Learn more+ </InlineLink>+ </p>+ }+ >+ {isFreePlan ? (+ <UpgradePlanButton+ variant="default"+ plan="Pro"+ addon="computeSize"+ source="read-replicas"+ featureProposition="deploy Read Replicas"+ className="mt-2"+ />+ ) : (+ <Button+ variant="default"+ className="mt-2"+ onClick={() => onRecommendCompute(RECOMMENDED_COMPUTE_FOR_READ_REPLICAS.minimum)}+ >+ Change compute+ </Button>+ )}</Admonition>)}diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaPricingDialog.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaPricingDialog.tsxindex bfc10a6f656..564e244f84c 100644--- a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaPricingDialog.tsx+++ b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaPricingDialog.tsx@@ -1,9 +1,8 @@import {+ Button,Card,- cn,Dialog,DialogContent,- DialogFooter,DialogHeader,DialogSection,DialogSectionSeparator,@@ -12,85 +11,102 @@ import {Table,TableBody,TableCell,+ TableFooter,TableHead,TableHeader,TableRow,} from 'ui'+import { Admonition } from 'ui-patterns/Admonition'import { useGetReplicaCost } from './useGetReplicaCost'import { TaxDisclaimer } from '@/components/interfaces/Billing/TaxDisclaimer'-import { DocsButton } from '@/components/ui/DocsButton'-import { InlineLinkClassName } from '@/components/ui/InlineLink'import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'-import { DOCS_URL } from '@/lib/constants'-export const ReadReplicaPricingDialog = () => {+interface ReadReplicaPricingDialogProps {+ replicaCost: ReturnType<typeof useGetReplicaCost>+}++export const ReadReplicaPricingDialog = ({ replicaCost }: ReadReplicaPricingDialogProps) => {const { data: project } = useSelectedProjectQuery()- const { totalCost, compute, disk, iops, throughput } = useGetReplicaCost()+ const { isLoading, isError, retry, totalCost, compute, disk, iops, throughput } = replicaCost- const showNewDiskManagementUI = project?.cloud_provider === 'AWS'+ const isNewDiskManagementUI = project?.cloud_provider === 'AWS'++ let title = `Estimated additional cost of ${totalCost}/month`+ if (isLoading) title = 'Estimated additional cost'+ if (isError) title = 'Unable to estimate additional cost'return (<Dialog>- <p className="text-sm">- New replica will cost an additional <span translate="no">{totalCost}/month</span>.{' '}- <DialogTrigger asChild>- <button- type="button"- tabIndex={0}- className={cn(InlineLinkClassName, 'cursor-pointer text-foreground-light')}- >- Learn more- </button>- </DialogTrigger>- </p>- <DialogContent- size={showNewDiskManagementUI ? 'medium' : 'small'}- aria-describedby={undefined}- >+ <Admonition+ type={isError ? 'warning' : 'note'}+ layout="responsive"+ title={title}+ description={+ isError+ ? 'We couldn’t load the required pricing data.'+ : 'Based on your primary database configuration.'+ }+ className="mb-0 rounded-none border-x-0"+ actions={+ isError ? (+ <Button+ type="button"+ variant="default"+ size="tiny"+ disabled={isLoading}+ onClick={retry}+ >+ Retry+ </Button>+ ) : (+ <DialogTrigger asChild>+ <Button type="button" variant="default" size="tiny" disabled={isLoading}>+ View breakdown+ </Button>+ </DialogTrigger>+ )+ }+ />+ <DialogContent size="medium" aria-describedby={undefined}><DialogHeader>- <DialogTitle>Calculating costs for a new read replica</DialogTitle>+ <DialogTitle>Read replica cost breakdown</DialogTitle></DialogHeader><DialogSectionSeparator /><DialogSection>- {showNewDiskManagementUI ? (+ {isNewDiskManagementUI ? (<>- <p className="text-foreground-light text-sm mb-2">- Read replicas will match the compute size of your primary database and will include- 25% more disk size than the primary database to accommodate WAL files.+ <p className="mb-3 text-sm text-foreground-light">+ The replica matches your primary compute and includes 25% additional disk capacity+ for WAL files.</p>-- <p className="text-foreground-light text-sm">- The additional cost for the replica breaks down to:- </p>-- <Card className="mt-2">+ <Card><Table><TableHeader><TableRow><TableHead className="w-[140px]">Item</TableHead><TableHead>Description</TableHead>- <TableHead className="text-right">Cost (/month)</TableHead>+ <TableHead className="text-right">Monthly cost</TableHead></TableRow></TableHeader>- <TableBody className="[&_td]:py-0 [&_tr]:h-[50px] [&_tr]:border-dotted">+ <TableBody><TableRow><TableCell>Compute size</TableCell>- <TableCell>{compute.label}</TableCell>+ <TableCell className="text-foreground-lighter">{compute.label}</TableCell><TableCell className="text-right font-mono" translate="no">{compute.cost}</TableCell></TableRow><TableRow><TableCell>Disk size</TableCell>- <TableCell>{disk.label}</TableCell>+ <TableCell className="text-foreground-lighter">{disk.label}</TableCell><TableCell className="text-right font-mono" translate="no">{disk.cost}</TableCell></TableRow><TableRow><TableCell>IOPS</TableCell>- <TableCell>{iops.label}</TableCell>+ <TableCell className="text-foreground-lighter">{iops.label}</TableCell><TableCell className="text-right font-mono" translate="no">{iops.cost}</TableCell>@@ -98,13 +114,25 @@ export const ReadReplicaPricingDialog = () => {{disk.type === 'gp3' && (<TableRow><TableCell>Throughput</TableCell>- <TableCell>{throughput.label}</TableCell>+ <TableCell className="text-foreground-lighter">+ {throughput.label}+ </TableCell><TableCell className="text-right font-mono" translate="no">{throughput.cost}</TableCell></TableRow>)}</TableBody>+ <TableFooter>+ <TableRow>+ <TableCell colSpan={2} className="font-medium">+ Estimated total+ </TableCell>+ <TableCell className="text-right font-mono font-medium" translate="no">+ {totalCost}+ </TableCell>+ </TableRow>+ </TableFooter></Table></Card></>@@ -119,12 +147,8 @@ export const ReadReplicaPricingDialog = () => {.</p>)}- <TaxDisclaimer className="mt-3" />+ <TaxDisclaimer className="mt-3 text-sm text-foreground-light" /></DialogSection>-- <DialogFooter>- <DocsButton href={`${DOCS_URL}/guides/platform/manage-your-usage/read-replicas`} />- </DialogFooter></DialogContent></Dialog>)diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/index.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/index.tsxindex 87b114b7a63..7c0eb03f574 100644--- a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/index.tsx+++ b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/index.tsx@@ -1,23 +1,23 @@import { useParams } from 'common'-import { RefObject, useEffect, useState, type ReactNode } from 'react'+import { useState, type ReactNode } from 'react'import { AWS_REGIONS, AWS_REGIONS_KEYS } from 'shared-data'import { toast } from 'sonner'import {Button,- InfoIcon,+ DialogFooter,+ DialogSection,Select,SelectContent,SelectItem,SelectTrigger,SelectValue,- SheetFooter,- SheetSection,} from 'ui'import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'import { ReadReplicaEligibilityWarnings } from './ReadReplicaEligibilityWarnings'import { ReadReplicaPricingDialog } from './ReadReplicaPricingDialog'import { useCheckEligibilityDeployReplica } from './useCheckEligibilityDeployReplica'+import { useGetReplicaCost } from './useGetReplicaCost'import { AVAILABLE_REPLICA_REGIONS } from '@/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.constants'import type { RecommendedComputeForReadReplicas } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/recommendCompute'import { RegionFlag } from '@/components/ui/RegionFlag'@@ -27,40 +27,28 @@ import { AWS_REGIONS_DEFAULT } from '@/lib/constants'interface ReadReplicaFormProps {typeSelection?: ReactNode- checkIsDirtyRef?: RefObject<() => boolean>onSuccess: () => voidonClose: () => void- onCancel?: () => voidonRecommendCompute: (size: RecommendedComputeForReadReplicas) => void}export const ReadReplicaForm = ({typeSelection,- checkIsDirtyRef,onSuccess,onClose,- onCancel = onClose,onRecommendCompute,}: ReadReplicaFormProps) => {const { ref: projectRef } = useParams()const { data } = useReadReplicasQuery({ projectRef })+ const eligibility = useCheckEligibilityDeployReplica()+ const replicaCost = useGetReplicaCost()const [defaultRegion] = Object.entries(AWS_REGIONS).find(([_, name]) => name === AWS_REGIONS_DEFAULT) ?? ['SOUTHEAST_ASIA']- const { can: canDeployReplica } = useCheckEligibilityDeployReplica()+ const { can: canDeployReplica } = eligibilityconst [selectedRegion, setSelectedRegion] = useState<string>(defaultRegion)- const isDirty = selectedRegion !== defaultRegion-- useEffect(() => {- if (!checkIsDirtyRef) return-- checkIsDirtyRef.current = () => isDirty- return () => {- checkIsDirtyRef.current = () => false- }- }, [checkIsDirtyRef, isDirty])const { mutate: setUpReplica, isPending: isSettingUp } = useReadReplicaSetUpMutation({onSuccess: () => {@@ -77,6 +65,7 @@ export const ReadReplicaForm = ({['SOUTHEAST_ASIA', 'CENTRAL_EU', 'EAST_US'].includes(x.key)): AVAILABLE_REPLICA_REGIONS+ const selectedRegionDetails = availableRegions.find((region) => region.key === selectedRegion)const onSubmit = async () => {if (!projectRef) return console.error('Project is required')@@ -90,19 +79,21 @@ export const ReadReplicaForm = ({return (<>- <SheetSection className="grow overflow-auto px-0 py-0">+ <DialogSection className="flex flex-col p-0!">{typeSelection}- {!canDeployReplica && (- <SheetSection>- <ReadReplicaEligibilityWarnings onRecommendCompute={onRecommendCompute} />- </SheetSection>- )}<FormItemLayoutisReactForm={false}- layout="horizontal"+ layout="vertical"className="p-5 [&>div]:gap-y-1 [&>div>span]:text-foreground-lighter"label="Region"- labelOptional="Select a region to deploy your replica in"+ description={+ canDeployReplica ? (+ <span>+ This replica will be deployed in{' '}+ <span translate="no">{selectedRegionDetails?.region}</span>.+ </span>+ ) : undefined+ }><Selectvalue={selectedRegion}@@ -110,7 +101,14 @@ export const ReadReplicaForm = ({disabled={!canDeployReplica}><SelectTrigger>- <SelectValue placeholder="Select a region" />+ <SelectValue placeholder="Select a region">+ <span className="flex min-w-0 items-center gap-x-2">+ {selectedRegionDetails !== undefined && (+ <RegionFlag className="w-5 shrink-0" region={selectedRegionDetails.region} />+ )}+ <span className="truncate">{selectedRegionDetails?.name}</span>+ </span>+ </SelectValue></SelectTrigger><SelectContent>{availableRegions.map((region) => (@@ -129,22 +127,26 @@ export const ReadReplicaForm = ({</SelectContent></Select></FormItemLayout>- </SheetSection>- <SheetFooter className="justify-between! gap-x-6">- <div className="flex items-center gap-x-3">- <InfoIcon className="h-5 w-5" />- <ReadReplicaPricingDialog />+ </DialogSection>+ {canDeployReplica ? (+ <ReadReplicaPricingDialog replicaCost={replicaCost} />+ ) : (+ <div className="[&>[role=alert]]:mb-0 [&>[role=alert]]:rounded-none [&>[role=alert]]:border-x-0">+ <ReadReplicaEligibilityWarnings+ eligibility={eligibility}+ onRecommendCompute={onRecommendCompute}+ /></div>+ )}- <div className="flex items-center gap-x-2">- <Button disabled={isSettingUp} variant="default" onClick={onCancel}>- Cancel- </Button>- <Button disabled={!canDeployReplica} loading={isSettingUp} onClick={onSubmit}>- Deploy replica- </Button>- </div>- </SheetFooter>+ <DialogFooter className="border-t-0">+ <Button disabled={isSettingUp} variant="default" onClick={onClose}>+ Cancel+ </Button>+ <Button disabled={!canDeployReplica} loading={isSettingUp} onClick={onSubmit}>+ Add replica+ </Button>+ </DialogFooter></>)}diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/useGetReplicaCost.ts b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/useGetReplicaCost.tsindex 610b3b7c72f..d3ef34c148a 100644--- a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/useGetReplicaCost.ts+++ b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/useGetReplicaCost.ts@@ -14,8 +14,31 @@ import { formatCurrency } from '@/lib/helpers'export const useGetReplicaCost = () => {const { ref: projectRef } = useParams()- const { data: addons } = useProjectAddonsQuery({ projectRef })- const { data: diskConfiguration } = useDiskAttributesQuery({ projectRef })+ const {+ data: addons,+ isError: isAddonsError,+ isFetching: isAddonsFetching,+ isPending: isAddonsPending,+ refetch: refetchAddons,+ } = useProjectAddonsQuery({ projectRef })+ const {+ data: diskConfiguration,+ isError: isDiskConfigurationError,+ isFetching: isDiskConfigurationFetching,+ isPending: isDiskConfigurationPending,+ refetch: refetchDiskConfiguration,+ } = useDiskAttributesQuery({ projectRef })++ const isLoading =+ (addons === undefined && (isAddonsPending || isAddonsFetching)) ||+ (diskConfiguration === undefined && (isDiskConfigurationPending || isDiskConfigurationFetching))+ const isError =+ (addons === undefined && isAddonsError) ||+ (diskConfiguration === undefined && isDiskConfigurationError)++ const retry = async () => {+ await Promise.all([refetchAddons(), refetchDiskConfiguration()])+ }const currentComputeAddon = addons?.selected_addons.find((addon) => addon.type === 'compute_instance'@@ -57,6 +80,9 @@ export const useGetReplicaCost = () => {)return {+ isLoading,+ isError,+ retry,totalCost,compute: {label: selectedComputeMeta?.name,diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicasSection.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicasSection.tsxindex c63e8f8d7c1..32810ad8afc 100644--- a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicasSection.tsx+++ b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicasSection.tsx@@ -16,7 +16,7 @@ import {} from 'ui-patterns/PageSection'import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'-import { AddReadReplicaSheet } from './AddReadReplicaSheet'+import { AddReadReplicaDialog } from './AddReadReplicaDialog'import { ReadReplicaRow } from './ReadReplicaRow'import { REPLICA_STATUS } from './ReadReplicas.constants'import type { RecommendedComputeForReadReplicas } from './recommendCompute'@@ -33,7 +33,7 @@ interface ReadReplicasSectionProps {export const ReadReplicasSection = ({ onRecommendCompute }: ReadReplicasSectionProps) => {const { ref: projectRef } = useParams()const { infrastructureReadReplicas } = useIsFeatureEnabled(['infrastructure:read_replicas'])- const [, setAddReplica] = useQueryState(+ const [isAddReplicaOpen, setAddReplica] = useQueryState('addReplica',parseAsBoolean.withDefault(false).withOptions({history: 'push',@@ -153,7 +153,9 @@ export const ReadReplicasSection = ({ onRecommendCompute }: ReadReplicasSectionP</PageSectionContent></PageSection>- <AddReadReplicaSheet+ <AddReadReplicaDialog+ open={isAddReplicaOpen}+ onOpenChange={setAddReplica}onSuccess={() => setStatusRefetchInterval(5000)}onRecommendCompute={onRecommendCompute}/>diff --git a/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaDialog.test.tsx b/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaDialog.test.tsxnew file mode 100644index 00000000000..aa14ac6d74d--- /dev/null+++ b/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaDialog.test.tsx@@ -0,0 +1,99 @@+import { screen, waitFor } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { useState } from 'react'+import { describe, expect, test, vi } from 'vitest'++import { AddReadReplicaDialog } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaDialog'+import { customRender } from '@/tests/lib/custom-render'++const { mockReadReplicaForm } = vi.hoisted(() => ({ mockReadReplicaForm: vi.fn() }))++vi.mock('@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm', () => ({+ ReadReplicaForm: ({+ onClose,+ onRecommendCompute,+ }: {+ onClose: () => void+ onRecommendCompute: (size: 'ci_small') => void+ }) => {+ mockReadReplicaForm()++ return (+ <>+ <button type="button" tabIndex={0} onClick={() => onRecommendCompute('ci_small')}>+ Change compute+ </button>+ <button type="button" tabIndex={0}>+ Change region+ </button>+ <button type="button" tabIndex={0} onClick={onClose}>+ Cancel+ </button>+ </>+ )+ },+}))++const renderDialog = (onRecommendCompute = vi.fn()) => {+ const TestDialog = () => {+ const [open, setOpen] = useState(true)++ return (+ <AddReadReplicaDialog+ open={open}+ onOpenChange={setOpen}+ onRecommendCompute={onRecommendCompute}+ />+ )+ }++ return customRender(<TestDialog />)+}++describe('AddReadReplicaDialog', () => {+ test('does not load form data while closed', () => {+ customRender(+ <AddReadReplicaDialog open={false} onOpenChange={vi.fn()} onRecommendCompute={vi.fn()} />+ )++ expect(mockReadReplicaForm).not.toHaveBeenCalled()+ })++ test('closes an unchanged dialog without confirmation', async () => {+ const user = userEvent.setup()+ renderDialog()++ expect(screen.getByRole('dialog', { name: 'Add read replica' })).toBeInTheDocument()++ await user.click(screen.getByRole('button', { name: 'Close' }))++ await waitFor(() => {+ expect(screen.queryByRole('dialog', { name: 'Add read replica' })).not.toBeInTheDocument()+ })+ expect(screen.queryByText('Unsaved changes')).not.toBeInTheDocument()+ })++ test('closes after a transient region selection without confirmation', async () => {+ const user = userEvent.setup()+ renderDialog()++ await user.click(screen.getByRole('button', { name: 'Change region' }))+ await user.click(screen.getByRole('button', { name: 'Cancel' }))++ await waitFor(() => {+ expect(screen.queryByRole('dialog', { name: 'Add read replica' })).not.toBeInTheDocument()+ })+ expect(screen.queryByText('Unsaved changes')).not.toBeInTheDocument()+ })++ test('hands the recommendation off after closing the dialog', async () => {+ const user = userEvent.setup()+ const onRecommendCompute = vi.fn()++ renderDialog(onRecommendCompute)++ await user.click(screen.getByRole('button', { name: 'Change compute' }))++ await waitFor(() => expect(onRecommendCompute).toHaveBeenCalledWith('ci_small'))+ })+})diff --git a/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaSheet.test.tsx b/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaSheet.test.tsxdeleted file mode 100644index d441169f843..00000000000--- a/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaSheet.test.tsx+++ /dev/null@@ -1,29 +0,0 @@-import { screen, waitFor } from '@testing-library/react'-import userEvent from '@testing-library/user-event'-import { describe, expect, test, vi } from 'vitest'--import { AddReadReplicaSheet } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaSheet'-import { customRender } from '@/tests/lib/custom-render'--vi.mock('@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm', () => ({- ReadReplicaForm: ({ onRecommendCompute }: { onRecommendCompute: (size: 'ci_small') => void }) => (- <button type="button" tabIndex={0} onClick={() => onRecommendCompute('ci_small')}>- Change to Small compute- </button>- ),-}))--describe('AddReadReplicaSheet', () => {- test('hands the recommendation off after closing the sheet', async () => {- const user = userEvent.setup()- const onRecommendCompute = vi.fn()-- customRender(<AddReadReplicaSheet onRecommendCompute={onRecommendCompute} />, {- nuqs: { searchParams: { addReplica: 'true' } },- })-- await user.click(screen.getByRole('button', { name: 'Change to Small compute' }))-- await waitFor(() => expect(onRecommendCompute).toHaveBeenCalledWith('ci_small'))- })-})diff --git a/apps/studio/tests/components/Settings/Infrastructure/ReadReplicaEligibilityWarnings.test.tsx b/apps/studio/tests/components/Settings/Infrastructure/ReadReplicaEligibilityWarnings.test.tsxindex fe468736f15..5bd41bd2c31 100644--- a/apps/studio/tests/components/Settings/Infrastructure/ReadReplicaEligibilityWarnings.test.tsx+++ b/apps/studio/tests/components/Settings/Infrastructure/ReadReplicaEligibilityWarnings.test.tsx@@ -3,13 +3,9 @@ import userEvent from '@testing-library/user-event'import { describe, expect, it, vi } from 'vitest'import { ReadReplicaEligibilityWarnings } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaEligibilityWarnings'-import { useCheckEligibilityDeployReplica } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/useCheckEligibilityDeployReplica'import { READ_REPLICAS_MAX_COUNT } from '@/data/read-replicas/replicas-query'import { customRender } from '@/tests/lib/custom-render'-vi.mock(- '@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/useCheckEligibilityDeployReplica'-)vi.mock('@/data/projects/project-detail-query', () => ({useProjectDetailQuery: () => ({ data: undefined, isSuccess: false }),}))@@ -41,33 +37,36 @@ describe('ReadReplicaEligibilityWarnings – below small compute', () => {it('recommends Small compute when project is on pico, nano, or micro compute', async () => {const user = userEvent.setup()const onRecommendCompute = vi.fn()- vi.mocked(useCheckEligibilityDeployReplica).mockReturnValue(- eligibility({ isBelowSmallCompute: true })- )+ const warningEligibility = eligibility({ isBelowSmallCompute: true })- customRender(<ReadReplicaEligibilityWarnings onRecommendCompute={onRecommendCompute} />)+ customRender(+ <ReadReplicaEligibilityWarnings+ eligibility={warningEligibility}+ onRecommendCompute={onRecommendCompute}+ />+ )+ expect(screen.getByText('Small compute required')).toBeInTheDocument()expect(- screen.getByText('Project required to at least be on a Small compute')- ).toBeInTheDocument()- expect(- screen.getByText(- 'This is to ensure that read replicas can keep up with the primary database’s activities.'- )+ screen.getByText(/Read replicas require at least Small compute to keep up/)).toBeInTheDocument()- expect(screen.getByRole('button', { name: /change to small compute/i })).toBeInTheDocument()- await user.click(screen.getByRole('button', { name: /change to small compute/i }))+ expect(screen.getByRole('link', { name: 'Learn more' })).toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'Change compute' })).toBeInTheDocument()+ await user.click(screen.getByRole('button', { name: 'Change compute' }))expect(onRecommendCompute).toHaveBeenCalledWith('ci_small')})})describe('ReadReplicaEligibilityWarnings – max replicas reached', () => {it('shows upsell to upgrade compute when below the default cap (e.g. ci_small/medium/large → 4 replicas)', () => {- vi.mocked(useCheckEligibilityDeployReplica).mockReturnValue(- eligibility({ isReachedMaxReplicas: true, maxNumberOfReplicas: 4 })- )+ const warningEligibility = eligibility({ isReachedMaxReplicas: true, maxNumberOfReplicas: 4 })- customRender(<ReadReplicaEligibilityWarnings onRecommendCompute={vi.fn()} />)+ customRender(+ <ReadReplicaEligibilityWarnings+ eligibility={warningEligibility}+ onRecommendCompute={vi.fn()}+ />+ )expect(screen.getByText('You can only deploy up to 4 read replicas at once')@@ -77,11 +76,17 @@ describe('ReadReplicaEligibilityWarnings – max replicas reached', () => {})it('does NOT show the compute upsell when already at the default cap (XL+)', () => {- vi.mocked(useCheckEligibilityDeployReplica).mockReturnValue(- eligibility({ isReachedMaxReplicas: true, maxNumberOfReplicas: READ_REPLICAS_MAX_COUNT })- )+ const warningEligibility = eligibility({+ isReachedMaxReplicas: true,+ maxNumberOfReplicas: READ_REPLICAS_MAX_COUNT,+ })- customRender(<ReadReplicaEligibilityWarnings onRecommendCompute={vi.fn()} />)+ customRender(+ <ReadReplicaEligibilityWarnings+ eligibility={warningEligibility}+ onRecommendCompute={vi.fn()}+ />+ )expect(screen.getByText(`You can only deploy up to ${READ_REPLICAS_MAX_COUNT} read replicas at once`)diff --git a/apps/studio/tests/components/Settings/Infrastructure/ReadReplicaPricingDialog.test.tsx b/apps/studio/tests/components/Settings/Infrastructure/ReadReplicaPricingDialog.test.tsxnew file mode 100644index 00000000000..1387ddea447--- /dev/null+++ b/apps/studio/tests/components/Settings/Infrastructure/ReadReplicaPricingDialog.test.tsx@@ -0,0 +1,65 @@+import { screen } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { describe, expect, test, vi } from 'vitest'++import { ReadReplicaPricingDialog } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaPricingDialog'+import { customRender } from '@/tests/lib/custom-render'++vi.mock('@/hooks/misc/useSelectedProject', () => ({+ useSelectedProjectQuery: () => ({ data: { cloud_provider: 'AWS' } }),+}))++const replicaCost = {+ isLoading: false,+ isError: false,+ retry: vi.fn(),+ totalCost: '$85.94',+ compute: { label: 'Small', cost: '$15.00', priceDescription: '$15/month' },+ disk: { type: 'gp3', label: '125 GB (gp3)', cost: '$15.63' },+ iops: { label: '3,000 IOPS', cost: '$30.00' },+ throughput: { label: '125 MB/s', cost: '$25.31' },+} as const++describe('ReadReplicaPricingDialog', () => {+ test('does not show a partial estimate while pricing data loads', () => {+ customRender(<ReadReplicaPricingDialog replicaCost={{ ...replicaCost, isLoading: true }} />)++ expect(screen.getByText('Estimated additional cost')).toBeInTheDocument()+ expect(screen.queryByText(/Estimated additional cost of/)).not.toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'View breakdown' })).toBeDisabled()+ })++ test('shows the estimate once all pricing data is available', () => {+ customRender(<ReadReplicaPricingDialog replicaCost={replicaCost} />)++ expect(screen.getByText('Estimated additional cost of $85.94/month')).toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'View breakdown' })).toBeEnabled()+ })++ test('offers to retry when pricing data cannot be loaded', async () => {+ const user = userEvent.setup()+ const retry = vi.fn()++ customRender(+ <ReadReplicaPricingDialog replicaCost={{ ...replicaCost, isError: true, retry }} />+ )++ expect(screen.getByText('Unable to estimate additional cost')).toBeInTheDocument()+ expect(screen.getByText('We couldn’t load the required pricing data.')).toBeInTheDocument()++ await user.click(screen.getByRole('button', { name: 'Retry' }))++ expect(retry).toHaveBeenCalledOnce()+ })++ test('keeps the error state stable while retrying', () => {+ customRender(+ <ReadReplicaPricingDialog replicaCost={{ ...replicaCost, isError: true, isLoading: true }} />+ )++ expect(screen.getByText('Unable to estimate additional cost')).toBeInTheDocument()+ expect(screen.queryByText('Estimated additional cost')).not.toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'Retry' })).toBeDisabled()+ expect(screen.queryByRole('button', { name: 'View breakdown' })).not.toBeInTheDocument()+ })+})diff --git a/apps/studio/tests/components/Settings/Infrastructure/ReadReplicasSection.test.tsx b/apps/studio/tests/components/Settings/Infrastructure/ReadReplicasSection.test.tsxindex cf9a305968c..f8b1928b812 100644--- a/apps/studio/tests/components/Settings/Infrastructure/ReadReplicasSection.test.tsx+++ b/apps/studio/tests/components/Settings/Infrastructure/ReadReplicasSection.test.tsx@@ -18,6 +18,10 @@ const { mockUseIsFeatureEnabled } = vi.hoisted(() => ({vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({useIsFeatureEnabled: mockUseIsFeatureEnabled,}))+vi.mock(+ '@/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaDialog',+ () => ({ AddReadReplicaDialog: () => null })+)const addReplicaListMocks = () => {addAPIMock({diff --git a/apps/studio/tests/pages/project/[ref]/settings/infrastructure.test.tsx b/apps/studio/tests/pages/project/[ref]/settings/infrastructure.test.tsxindex babf74a4799..484e844616c 100644--- a/apps/studio/tests/pages/project/[ref]/settings/infrastructure.test.tsx+++ b/apps/studio/tests/pages/project/[ref]/settings/infrastructure.test.tsx@@ -339,12 +339,12 @@ describe('/project/[ref]/settings/infrastructure', () => {})})- test('focuses the recommended compute option after closing the add replica sheet', async () => {+ test('focuses the recommended compute option after closing the add replica dialog', async () => {const user = userEvent.setup()renderInfrastructurePage()await user.click(await screen.findByRole('button', { name: 'Add read replica' }))- await user.click(await screen.findByRole('button', { name: 'Change to Small compute' }))+ await user.click(await screen.findByRole('button', { name: 'Change compute' }))const smallCompute = await screen.findByRole('radio', { name: /Small/ })await waitFor(() => expect(smallCompute).toHaveFocus())