Skip to content

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

feat(studio): point replica deep links at Infrastructure and recommend compute (#48921)

Danny White6ac5bf6b86f4
diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.sections.tsx b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.sections.tsx
index c7ab026d82d..3270f2a78f0 100644
--- a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.sections.tsx
+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.sections.tsx
@@ -68,7 +68,7 @@ export function ComputeSection({
<DocsButton href={`${DOCS_URL}/guides/platform/compute-and-disk`} />
</PageSectionAside>
</PageSectionMeta>
- <PageSectionContent ref={settingsRef} className="scroll-mt-24">
+ <PageSectionContent ref={settingsRef} id="compute" className="scroll-mt-24">
<ComputeSizeField form={form} disabled={disabled} />
</PageSectionContent>
</PageSection>
diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx
index 8c8f885398f..e031adfa6f8 100644
--- a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx
+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx
@@ -35,6 +35,8 @@ import {
RESTRICTED_COMPUTE_FOR_THROUGHPUT_ON_GP3,
} from './ui/DiskManagement.constants'
import { NoticeBar } from './ui/NoticeBar'
+import type { RecommendedComputeForReadReplicas } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/recommendCompute'
+import { useMainScrollContainer } from '@/components/layouts/MainScrollContainerContext'
import { PADDING_CLASSES } from '@/components/layouts/Scaffold'
import { UpgradeToPro } from '@/components/ui/UpgradeToPro'
import {
@@ -66,12 +68,16 @@ export function DiskManagementForm({
chartsClassName,
overviewExtra,
beforeScaling,
+ recommendedCompute,
+ onRecommendedComputeApplied,
}: {
chartsClassName?: string
/** Rendered above usage charts in the overview block (for example topology). */
overviewExtra?: ReactNode
/** Rendered between overview and the Scaling section (for example read replicas). */
beforeScaling?: ReactNode
+ recommendedCompute?: RecommendedComputeForReadReplicas | null
+ onRecommendedComputeApplied?: () => void
} = {}) {
const { ref: projectRef } = useParams()
const { data: project, isPending: isProjectPending } = useSelectedProjectQuery()
@@ -82,6 +88,7 @@ export function DiskManagementForm({
const storageSettingsRef = useRef<HTMLDivElement>(null)
const computeSettingsRef = useRef<HTMLDivElement>(null)
const diskSizeSettingsRef = useRef<HTMLDivElement>(null)
+ const mainScrollContainer = useMainScrollContainer()
const isSpendCapEnabled = org?.plan.id !== 'free' && !org?.usage_billing_enabled
@@ -366,6 +373,61 @@ export function DiskManagementForm({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSuccess, isDiskAttributesSuccess])
+ // Apply the recommendation only after the sheet's close lifecycle has completed.
+ useEffect(() => {
+ // The compute add-on supplies the option. Keep the recommendation pending
+ // until disk attributes have initialised the form, so a later reset cannot
+ // overwrite it. Other infrastructure requests are unrelated to this handoff.
+ if (!recommendedCompute || !isAddonsSuccess) return
+
+ form.setValue('computeSize', recommendedCompute, {
+ shouldDirty: true,
+ shouldValidate: true,
+ })
+ void form.trigger(['provisionedIOPS', 'throughput'])
+ if (isDiskAttributesSuccess) onRecommendedComputeApplied?.()
+
+ const element = computeSettingsRef.current
+ if (!element) return
+
+ element
+ .querySelector<HTMLElement>(`[id="${recommendedCompute}"]`)
+ ?.focus({ preventScroll: true })
+
+ if (!mainScrollContainer) {
+ element.scrollIntoView({ behavior: 'smooth', block: 'start' })
+ return
+ }
+
+ const scrollMarginTop = Number.parseFloat(getComputedStyle(element).scrollMarginTop) || 0
+ const top =
+ mainScrollContainer.scrollTop +
+ element.getBoundingClientRect().top -
+ mainScrollContainer.getBoundingClientRect().top -
+ scrollMarginTop
+
+ mainScrollContainer.scrollTo({ top: Math.max(0, top), behavior: 'smooth' })
+ }, [
+ form,
+ isAddonsSuccess,
+ isDiskAttributesSuccess,
+ mainScrollContainer,
+ onRecommendedComputeApplied,
+ recommendedCompute,
+ ])
+
+ // Deep links from billing / UpgradePlanButton (e.g. #compute).
+ useEffect(() => {
+ if (typeof window === 'undefined') return
+ if (window.location.hash !== '#compute') return
+
+ const timeoutId = setTimeout(() => {
+ computeSettingsRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })
+ }, 100)
+
+ return () => clearTimeout(timeoutId)
+ }, [])
+
useEffect(() => {
const fieldErrors = Object.keys(errors)
if (fieldErrors.length === 0) return
@@ -401,9 +463,9 @@ export function DiskManagementForm({
<form id="disk-compute-form" onSubmit={form.handleSubmit(onSubmit)}>
<PageContainer size="default" className="pb-16">
<PageSection>
- <PageSectionContent className="flex flex-col gap-y-6">
+ <PageSectionContent>
{overviewExtra}
- <ComputeAndDiskUsageCharts className={chartsClassName} />
+ <ComputeAndDiskUsageCharts className={cn(overviewExtra && 'mt-6', chartsClassName)} />
</PageSectionContent>
</PageSection>
diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementPanelForm.tsx b/apps/studio/components/interfaces/DiskManagement/DiskManagementPanelForm.tsx
index 724da3d3ec6..0874546d7ac 100644
--- a/apps/studio/components/interfaces/DiskManagement/DiskManagementPanelForm.tsx
+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementPanelForm.tsx
@@ -30,8 +30,8 @@ export function DiskManagementPanelForm() {
<Admonition
type="default"
layout="responsive"
- title="Disk Management has moved"
- description="Disk configuration is now managed alongside Project Compute on the Infrastructure page."
+ title="Disk management has moved"
+ description="Disk configuration is now managed alongside project compute on the Infrastructure page."
actions={
<Button variant="default" asChild>
<Link href={getInfrastructurePath(projectRef)}>Go to Infrastructure</Link>
diff --git a/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsx b/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsx
index 2ca4c01d0e6..b7d48f020b1 100644
--- a/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsx
+++ b/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsx
@@ -113,7 +113,7 @@ export function ComputeSizeField({ form, disabled }: ComputeSizeFieldProps) {
render={({ field }) => (
<div className="@container">
<RadioGroupCard
- {...field}
+ value={field.value}
onValueChange={(value: ComputeInstanceAddonVariantId) => {
setValue('computeSize', value, {
shouldDirty: true,
@@ -122,7 +122,6 @@ export function ComputeSizeField({ form, disabled }: ComputeSizeFieldProps) {
trigger('provisionedIOPS')
trigger('throughput')
}}
- defaultValue={field.value}
disabled={disabled}
className={cn(
!addonsError && 'grid grid-cols-2 gap-4 @[680px]:grid-cols-3 @[900px]:grid-cols-4'
@@ -215,7 +214,7 @@ export function ComputeSizeField({ form, disabled }: ComputeSizeFieldProps) {
</HoverCard>
)}
<div className="w-full flex flex-col gap-3 justify-between">
- <div className="relative px-3 opacity-50 group-data-checked:opacity-100 flex justify-between">
+ <div className="relative px-3 opacity-50 group-data-[state=checked]:opacity-100 flex justify-between">
<ComputeBadge
className="inline-flex font-semibold"
infraComputeSize={compute.name as InfraInstanceSize}
diff --git a/apps/studio/components/interfaces/QuerySources/DatabaseParametersSubMenu.tsx b/apps/studio/components/interfaces/QuerySources/DatabaseParametersSubMenu.tsx
index f946f4e03f8..16490bf0156 100644
--- a/apps/studio/components/interfaces/QuerySources/DatabaseParametersSubMenu.tsx
+++ b/apps/studio/components/interfaces/QuerySources/DatabaseParametersSubMenu.tsx
@@ -9,6 +9,7 @@ import {
DropdownMenuSubTrigger,
} from 'ui'
+import { getAddReadReplicaPath } from '@/components/interfaces/Settings/Infrastructure/Infrastructure.utils'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { formatDatabaseID, formatDatabaseRegion } from '@/data/read-replicas/replicas.utils'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
@@ -38,7 +39,7 @@ export const DatabaseParametersSubMenu = ({
const selectedDatabaseId = identifier ?? projectRef
const selectedDatabase = databases.find((db) => db.identifier === selectedDatabaseId)
- const newReplicaURL = `/project/${projectRef}/database/replication?destinationType=Read+Replica`
+ const newReplicaURL = getAddReadReplicaPath(projectRef)
return (
<DropdownMenuSub>
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaSheet.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaSheet.tsx
index ce465862d2e..2fbf15f6c4e 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaSheet.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaSheet.tsx
@@ -3,6 +3,7 @@ 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'
@@ -10,23 +11,28 @@ import { DOCS_URL } from '@/lib/constants'
interface AddReadReplicaSheetProps {
onSuccess?: () => void
+ onRecommendCompute: (size: RecommendedComputeForReadReplicas) => void
}
-export const AddReadReplicaSheet = ({ onSuccess }: AddReadReplicaSheetProps) => {
- const [addReplica, setAddReplica] = useQueryState(
+export const AddReadReplicaSheet = ({
+ onSuccess,
+ onRecommendCompute,
+}: AddReadReplicaSheetProps) => {
+ const [visible, setVisible] = useQueryState(
'addReplica',
parseAsBoolean.withDefault(false).withOptions({
history: 'push',
clearOnDefault: true,
+ scroll: false,
})
)
- const visible = addReplica === true
const checkIsDirtyRef = useRef<() => boolean>(() => false)
+ const pendingRecommendationRef = useRef<RecommendedComputeForReadReplicas | null>(null)
const onClose = () => {
checkIsDirtyRef.current = () => false
- setAddReplica(false)
+ setVisible(false)
}
const { confirmOnClose, handleOpenChange, modalProps } = useConfirmOnClose({
@@ -34,10 +40,29 @@ export const AddReadReplicaSheet = ({ onSuccess }: AddReadReplicaSheetProps) =>
onClose,
})
+ const closeWithRecommendation = (size: RecommendedComputeForReadReplicas) => {
+ pendingRecommendationRef.current = size
+ onClose()
+ }
+
return (
<>
<Sheet open={visible} onOpenChange={handleOpenChange}>
- <SheetContent size="lg" showClose={false} className="max-w-3xl">
+ <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>
@@ -57,6 +82,7 @@ export const AddReadReplicaSheet = ({ onSuccess }: AddReadReplicaSheetProps) =>
onClose={onClose}
onCancel={confirmOnClose}
onSuccess={() => onSuccess?.()}
+ onRecommendCompute={closeWithRecommendation}
/>
</div>
</SheetContent>
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx
index e64bda607cf..043e37e1a8f 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaEligibilityWarnings.tsx
@@ -6,6 +6,10 @@ import { toast } from 'sonner'
import { Button } from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
+import {
+ RECOMMENDED_COMPUTE_FOR_READ_REPLICAS,
+ type RecommendedComputeForReadReplicas,
+} from '../recommendCompute'
import { useCheckEligibilityDeployReplica } from './useCheckEligibilityDeployReplica'
import { SupportLink } from '@/components/interfaces/Support/SupportLink'
import { DocsButton } from '@/components/ui/DocsButton'
@@ -17,10 +21,18 @@ import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganizati
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { DOCS_URL } from '@/lib/constants'
-export const ReadReplicaEligibilityWarnings = () => {
+interface ReadReplicaEligibilityWarningsProps {
+ onRecommendCompute: (size: RecommendedComputeForReadReplicas) => void
+}
+
+export const ReadReplicaEligibilityWarnings = ({
+ onRecommendCompute,
+}: ReadReplicaEligibilityWarningsProps) => {
const { ref: projectRef } = useParams()
const { data: org } = useSelectedOrganizationQuery()
const { data: project } = useSelectedProjectQuery()
+ const planId = org?.plan?.id
+ const isFreePlan = planId === undefined || planId === 'free'
const [refetchInterval, setRefetchInterval] = useState<number | false>(false)
@@ -129,16 +141,25 @@ export const ReadReplicaEligibilityWarnings = () => {
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 databases' activities.
+ 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">
- <UpgradePlanButton
- variant="default"
- plan="Pro"
- addon="computeSize"
- source="read-replicas"
- featureProposition="deploy Read Replicas"
- />
+ {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>
@@ -229,16 +250,15 @@ export const ReadReplicaEligibilityWarnings = () => {
<span className="text-foreground">{READ_REPLICAS_MAX_COUNT}</span> replicas if your
project is on an XL compute or higher.
</p>
- <UpgradePlanButton
+ <Button
variant="default"
- plan="Pro"
- addon="computeSize"
- source="read-replicas"
- featureProposition="deploy Read Replicas"
className="mt-2"
+ onClick={() =>
+ onRecommendCompute(RECOMMENDED_COMPUTE_FOR_READ_REPLICAS.unlockMaxReplicas)
+ }
>
- Change compute size
- </UpgradePlanButton>
+ Change to XL compute
+ </Button>
</>
)}
</Admonition>
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/index.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/index.tsx
index 394560a4621..69c9546a114 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/index.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/index.tsx
@@ -19,6 +19,7 @@ import { ReadReplicaEligibilityWarnings } from './ReadReplicaEligibilityWarnings
import { ReadReplicaPricingDialog } from './ReadReplicaPricingDialog'
import { useCheckEligibilityDeployReplica } from './useCheckEligibilityDeployReplica'
import { AVAILABLE_REPLICA_REGIONS } from '@/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.constants'
+import type { RecommendedComputeForReadReplicas } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/recommendCompute'
import { Region, useReadReplicaSetUpMutation } from '@/data/read-replicas/replica-setup-mutation'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { AWS_REGIONS_DEFAULT, BASE_PATH } from '@/lib/constants'
@@ -29,6 +30,7 @@ interface ReadReplicaFormProps {
onSuccess: () => void
onClose: () => void
onCancel?: () => void
+ onRecommendCompute: (size: RecommendedComputeForReadReplicas) => void
}
export const ReadReplicaForm = ({
@@ -37,6 +39,7 @@ export const ReadReplicaForm = ({
onSuccess,
onClose,
onCancel = onClose,
+ onRecommendCompute,
}: ReadReplicaFormProps) => {
const { ref: projectRef } = useParams()
const { data } = useReadReplicasQuery({ projectRef })
@@ -90,7 +93,7 @@ export const ReadReplicaForm = ({
{typeSelection}
{!canDeployReplica && (
<SheetSection>
- <ReadReplicaEligibilityWarnings />
+ <ReadReplicaEligibilityWarnings onRecommendCompute={onRecommendCompute} />
</SheetSection>
)}
<FormItemLayout
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicasSection.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicasSection.tsx
index 7e65bb2d4ca..c63e8f8d7c1 100644
--- a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicasSection.tsx
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicasSection.tsx
@@ -19,13 +19,18 @@ import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import { AddReadReplicaSheet } from './AddReadReplicaSheet'
import { ReadReplicaRow } from './ReadReplicaRow'
import { REPLICA_STATUS } from './ReadReplicas.constants'
+import type { RecommendedComputeForReadReplicas } from './recommendCompute'
import { AlertError } from '@/components/ui/AlertError'
import { DocsButton } from '@/components/ui/DocsButton'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import { DOCS_URL } from '@/lib/constants'
-export const ReadReplicasSection = () => {
+interface ReadReplicasSectionProps {
+ onRecommendCompute: (size: RecommendedComputeForReadReplicas) => void
+}
+
+export const ReadReplicasSection = ({ onRecommendCompute }: ReadReplicasSectionProps) => {
const { ref: projectRef } = useParams()
const { infrastructureReadReplicas } = useIsFeatureEnabled(['infrastructure:read_replicas'])
const [, setAddReplica] = useQueryState(
@@ -33,6 +38,7 @@ export const ReadReplicasSection = () => {
parseAsBoolean.withDefault(false).withOptions({
history: 'push',
clearOnDefault: true,
+ scroll: false,
})
)
@@ -147,7 +153,10 @@ export const ReadReplicasSection = () => {
</PageSectionContent>
</PageSection>
- <AddReadReplicaSheet onSuccess={() => setStatusRefetchInterval(5000)} />
+ <AddReadReplicaSheet
+ onSuccess={() => setStatusRefetchInterval(5000)}
+ onRecommendCompute={onRecommendCompute}
+ />
</>
)
}
diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/recommendCompute.ts b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/recommendCompute.ts
new file mode 100644
index 00000000000..40dc4123b23
--- /dev/null
+++ b/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/recommendCompute.ts
@@ -0,0 +1,10 @@
+/** Compute sizes recommended from the Add read replica sheet (close sheet → scroll + pre-select). */
+export const RECOMMENDED_COMPUTE_FOR_READ_REPLICAS = {
+ /** Minimum size that can deploy any read replicas. */
+ minimum: 'ci_small',
+ /** Size that unlocks the default max replica count (5). */
+ unlockMaxReplicas: 'ci_xlarge',
+} as const
+
+export type RecommendedComputeForReadReplicas =
+ (typeof RECOMMENDED_COMPUTE_FOR_READ_REPLICAS)[keyof typeof RECOMMENDED_COMPUTE_FOR_READ_REPLICAS]
diff --git a/apps/studio/components/layouts/ProjectLayout/ResizingState.tsx b/apps/studio/components/layouts/ProjectLayout/ResizingState.tsx
index cd5a2438779..94ac6662c50 100644
--- a/apps/studio/components/layouts/ProjectLayout/ResizingState.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/ResizingState.tsx
@@ -28,12 +28,10 @@ export const ResizingState = () => {
<Loader2 className="animate-spin text-foreground-light" size={18} />
</div>
<div className="flex flex-col gap-1">
- <p>Resizing Project Compute size</p>
+ <p>Resizing project</p>
<p className="text-sm text-foreground-light">
- Your project is being restarted to apply compute size changes.
- </p>
- <p className="text-sm text-foreground-light">
- This can take a few minutes. Project will be offline while it is being restarted.
+ Your project is being restarted to apply compute size changes. It will remain
+ offline until fully restarted. This can take a few minutes.
</p>
</div>
</div>
diff --git a/apps/studio/components/ui/DatabaseSelector.tsx b/apps/studio/components/ui/DatabaseSelector.tsx
index 212ffc77a96..2a65d8b21f5 100644
--- a/apps/studio/components/ui/DatabaseSelector.tsx
+++ b/apps/studio/components/ui/DatabaseSelector.tsx
@@ -23,7 +23,10 @@ import {
} from 'ui'
import { Markdown } from '@/components/interfaces/Markdown'
-import { getInfrastructurePath } from '@/components/interfaces/Settings/Infrastructure/Infrastructure.utils'
+import {
+ getAddReadReplicaPath,
+ getInfrastructurePath,
+} from '@/components/interfaces/Settings/Infrastructure/Infrastructure.utils'
import { REPLICA_STATUS } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicas.constants'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { formatDatabaseID, formatDatabaseRegion } from '@/data/read-replicas/replicas.utils'
@@ -74,7 +77,7 @@ export const DatabaseSelector = ({
const selectedAdditionalOption = additionalOptions.find((x) => x.id === selectedDatabaseId)
- const newReplicaURL = `/project/${projectRef}/database/replication?destinationType=Read+Replica`
+ const newReplicaURL = getAddReadReplicaPath(projectRef)
useEffect(() => {
if (_selectedDatabaseId && !isForm) state.setSelectedDatabaseId(_selectedDatabaseId)
diff --git a/apps/studio/components/ui/UpgradePlanButton.tsx b/apps/studio/components/ui/UpgradePlanButton.tsx
index 2967b1b0d7f..2fe24002eff 100644
--- a/apps/studio/components/ui/UpgradePlanButton.tsx
+++ b/apps/studio/components/ui/UpgradePlanButton.tsx
@@ -72,7 +72,7 @@ export const UpgradePlanButton = ({
? `/org/${slug ?? '_'}/billing?panel=costControl&source=${source}`
: isOnPaidPlanAndRequestingToPurchaseAddon
? addon === 'computeSize'
- ? getInfrastructurePath(ref)
+ ? `${getInfrastructurePath(ref)}#compute`
: `/project/${ref ?? '_'}/settings/addons?panel=${addon}&source=${source}`
: `/org/${slug ?? '_'}/billing?panel=subscriptionPlan&source=${source}`
diff --git a/apps/studio/pages/project/[ref]/settings/infrastructure.tsx b/apps/studio/pages/project/[ref]/settings/infrastructure.tsx
index 2ac51469887..2cf5757a5b6 100644
--- a/apps/studio/pages/project/[ref]/settings/infrastructure.tsx
+++ b/apps/studio/pages/project/[ref]/settings/infrastructure.tsx
@@ -1,3 +1,4 @@
+import { useState } from 'react'
import {
PageHeader,
PageHeaderDescription,
@@ -9,11 +10,15 @@ import {
import { DiskManagementForm } from '@/components/interfaces/DiskManagement/DiskManagementForm'
import { InfrastructureTopology } from '@/components/interfaces/Settings/Infrastructure/InfrastructureTopology'
import { ReadReplicasSection } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicasSection'
+import type { RecommendedComputeForReadReplicas } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/recommendCompute'
import { DefaultLayout } from '@/components/layouts/DefaultLayout'
import SettingsLayout from '@/components/layouts/ProjectSettingsLayout/SettingsLayout'
import type { NextPageWithLayout } from '@/types'
const InfrastructureSettings: NextPageWithLayout = () => {
+ const [recommendedCompute, setRecommendedCompute] =
+ useState<RecommendedComputeForReadReplicas | null>(null)
+
return (
<>
<PageHeader size="default">
@@ -28,7 +33,9 @@ const InfrastructureSettings: NextPageWithLayout = () => {
</PageHeader>
<DiskManagementForm
overviewExtra={<InfrastructureTopology />}
- beforeScaling={<ReadReplicasSection />}
+ beforeScaling={<ReadReplicasSection onRecommendCompute={setRecommendedCompute} />}
+ recommendedCompute={recommendedCompute}
+ onRecommendedComputeApplied={() => setRecommendedCompute(null)}
/>
</>
)
diff --git a/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaSheet.test.tsx b/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaSheet.test.tsx
new file mode 100644
index 00000000000..d441169f843
--- /dev/null
+++ b/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaSheet.test.tsx
@@ -0,0 +1,29 @@
+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.tsx
index c9471145d67..fe468736f15 100644
--- a/apps/studio/tests/components/Settings/Infrastructure/ReadReplicaEligibilityWarnings.test.tsx
+++ b/apps/studio/tests/components/Settings/Infrastructure/ReadReplicaEligibilityWarnings.test.tsx
@@ -1,4 +1,5 @@
import { screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
import { describe, expect, it, vi } from 'vitest'
import { ReadReplicaEligibilityWarnings } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm/ReadReplicaEligibilityWarnings'
@@ -16,7 +17,7 @@ vi.mock('@/data/database/enable-physical-backups-mutation', () => ({
useEnablePhysicalBackupsMutation: () => ({ mutate: vi.fn(), isPending: false }),
}))
vi.mock('@/hooks/misc/useSelectedOrganization', () => ({
- useSelectedOrganizationQuery: () => ({ data: { slug: 'test-org' } }),
+ useSelectedOrganizationQuery: () => ({ data: { slug: 'test-org', plan: { id: 'pro' } } }),
}))
vi.mock('@/hooks/misc/useSelectedProject', () => ({
useSelectedProjectQuery: () => ({ data: { dbVersion: 'supabase-postgres-15.1.0' } }),
@@ -37,21 +38,26 @@ const eligibility = (delta: Record<string, unknown>) => ({
})
describe('ReadReplicaEligibilityWarnings – below small compute', () => {
- it('shows upgrade CTA when project is on pico, nano, or micro 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 })
)
- customRender(<ReadReplicaEligibilityWarnings />)
+ customRender(<ReadReplicaEligibilityWarnings onRecommendCompute={onRecommendCompute} />)
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 databases' activities."
+ 'This is to ensure that read replicas can keep up with the primary database’s activities.'
)
).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(onRecommendCompute).toHaveBeenCalledWith('ci_small')
})
})
@@ -61,13 +67,13 @@ describe('ReadReplicaEligibilityWarnings – max replicas reached', () => {
eligibility({ isReachedMaxReplicas: true, maxNumberOfReplicas: 4 })
)
- customRender(<ReadReplicaEligibilityWarnings />)
+ customRender(<ReadReplicaEligibilityWarnings onRecommendCompute={vi.fn()} />)
expect(
screen.getByText('You can only deploy up to 4 read replicas at once')
).toBeInTheDocument()
expect(screen.getByText(/you may deploy up to/i)).toBeInTheDocument()
- expect(screen.getByRole('link', { name: /change compute size/i })).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: /change to xl compute/i })).toBeInTheDocument()
})
it('does NOT show the compute upsell when already at the default cap (XL+)', () => {
@@ -75,13 +81,13 @@ describe('ReadReplicaEligibilityWarnings – max replicas reached', () => {
eligibility({ isReachedMaxReplicas: true, maxNumberOfReplicas: READ_REPLICAS_MAX_COUNT })
)
- customRender(<ReadReplicaEligibilityWarnings />)
+ customRender(<ReadReplicaEligibilityWarnings onRecommendCompute={vi.fn()} />)
expect(
screen.getByText(`You can only deploy up to ${READ_REPLICAS_MAX_COUNT} read replicas at once`)
).toBeInTheDocument()
expect(screen.queryByText(/you may deploy up to/i)).not.toBeInTheDocument()
expect(screen.queryByText(/XL compute or higher/i)).not.toBeInTheDocument()
- expect(screen.queryByRole('link', { name: /change compute size/i })).not.toBeInTheDocument()
+ expect(screen.queryByRole('button', { name: /change to xl compute/i })).not.toBeInTheDocument()
})
})
diff --git a/apps/studio/tests/components/Settings/Infrastructure/ReadReplicasSection.test.tsx b/apps/studio/tests/components/Settings/Infrastructure/ReadReplicasSection.test.tsx
index 0850bc2b732..cf9a305968c 100644
--- a/apps/studio/tests/components/Settings/Infrastructure/ReadReplicasSection.test.tsx
+++ b/apps/studio/tests/components/Settings/Infrastructure/ReadReplicasSection.test.tsx
@@ -62,7 +62,7 @@ describe('ReadReplicasSection', () => {
mockUseIsFeatureEnabled.mockReturnValue({ infrastructureReadReplicas: true })
addReplicaListMocks()
- customRender(<ReadReplicasSection />)
+ customRender(<ReadReplicasSection onRecommendCompute={vi.fn()} />)
expect(await screen.findByText('Read replicas')).toBeInTheDocument()
expect(await screen.findByText('No read replicas')).toBeInTheDocument()
@@ -82,7 +82,7 @@ describe('ReadReplicasSection', () => {
},
})
- customRender(<ReadReplicasSection />)
+ customRender(<ReadReplicasSection onRecommendCompute={vi.fn()} />)
expect(screen.queryByText('Read replicas')).not.toBeInTheDocument()
await new Promise((resolve) => setTimeout(resolve, 50))
diff --git a/apps/studio/tests/pages/project/[ref]/settings/infrastructure.test.tsx b/apps/studio/tests/pages/project/[ref]/settings/infrastructure.test.tsx
index 4db3ac56f8c..2ab2fae51a3 100644
--- a/apps/studio/tests/pages/project/[ref]/settings/infrastructure.test.tsx
+++ b/apps/studio/tests/pages/project/[ref]/settings/infrastructure.test.tsx
@@ -44,6 +44,7 @@ const PROJECT: ProjectDetailResponse = {
cloud_provider: 'AWS',
connectionString: 'postgresql://postgres:[email protected]:5432/postgres',
db_host: 'db.project-ref.supabase.co',
+ dbVersion: 'supabase-postgres-15.1.0',
high_availability: false,
id: 1,
infra_compute_size: 'micro',
@@ -338,6 +339,18 @@ describe('/project/[ref]/settings/infrastructure', () => {
})
})
+ test('focuses the recommended compute option after closing the add replica sheet', 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' }))
+
+ const smallCompute = await screen.findByRole('radio', { name: /Small/ })
+ await waitFor(() => expect(smallCompute).toHaveFocus())
+ expect(smallCompute).toBeChecked()
+ })
+
test('reviews and confirms a compute resize through the add-on API', async () => {
const user = userEvent.setup()
let addonRequest: unknown