The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Modernize compute and disk configuration (#48368)
Saxon Fletcher618e0031369a
diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagement.test.ts b/apps/studio/components/interfaces/DiskManagement/DiskManagement.test.tsindex c7e44d07d1e..74a67404a06 100644--- a/apps/studio/components/interfaces/DiskManagement/DiskManagement.test.ts+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagement.test.ts@@ -1,5 +1,6 @@import { describe, expect, test } from 'vitest'+import { CreateDiskStorageSchema } from './DiskManagement.schema'import {calculateBaselineIopsForComputeSize,calculateComputeSizeRequiredForIops,@@ -147,6 +148,18 @@ describe('DiskManagement.utils.ts:calculateIOPSPrice', () => {expect(result.oldPrice).toBe('357.00')expect(result.newPrice).toBe('595.00')})+ test('includes IOPS charges for read replicas', () => {+ const result = calculateIOPSPrice({+ oldStorageType: DiskType.GP3,+ oldProvisionedIOPS: 3000,+ newStorageType: DiskType.GP3,+ newProvisionedIOPS: 5000,+ numReplicas: 2,+ })++ expect(result.oldPrice).toBe('0.00')+ expect(result.newPrice).toBe('144.00')+ })})describe('DiskManagement.utils.ts:calculateThroughputPrice', () => {@@ -168,4 +181,109 @@ describe('DiskManagement.utils.ts:calculateThroughputPrice', () => {expect(result.oldPrice).toBe('0.00')expect(result.newPrice).toBe('0.00')})+ test('includes throughput charges for read replicas', () => {+ const result = calculateThroughputPrice({+ storageType: DiskType.GP3,+ oldThroughput: 125,+ newThroughput: 150,+ numReplicas: 2,+ })++ expect(result.oldPrice).toBe('0.00')+ expect(result.newPrice).toBe('7.13')+ })+})++describe('CreateDiskStorageSchema', () => {+ const validGp3Config = {+ storageType: DiskType.GP3,+ totalSize: 8,+ provisionedIOPS: 3000,+ throughput: 125,+ computeSize: 'ci_large' as const,+ growthPercent: null,+ minIncrementGb: null,+ maxSizeGb: null,+ }++ test('enforces the GP3 500 IOPS per GB limit', () => {+ const schema = CreateDiskStorageSchema({+ defaultTotalSize: 8,+ cloudProvider: 'AWS',+ isSpendCapEnabled: false,+ })++ const result = schema.safeParse({+ ...validGp3Config,+ provisionedIOPS: 6000,+ })++ expect(result.success).toBe(false)+ if (result.success) return++ expect(result.error.issues).toContainEqual(+ expect.objectContaining({+ path: ['provisionedIOPS'],+ message: 'Larger Disk size of at least 12 GB required. Current max is 4,000 IOPS.',+ })+ )+ })++ test('allows a legacy disk below 8 GB when its size is unchanged', () => {+ const schema = CreateDiskStorageSchema({+ defaultTotalSize: 2,+ cloudProvider: 'AWS',+ isSpendCapEnabled: false,+ })++ expect(+ schema.safeParse({+ ...validGp3Config,+ totalSize: 2,+ }).success+ ).toBe(true)+ })++ test('prevents disk growth above 8 GB while spend cap is enabled', () => {+ const schema = CreateDiskStorageSchema({+ defaultTotalSize: 8,+ cloudProvider: 'AWS',+ isSpendCapEnabled: true,+ })++ const result = schema.safeParse({+ ...validGp3Config,+ totalSize: 10,+ })++ expect(result.success).toBe(false)+ if (result.success) return++ expect(result.error.issues).toContainEqual(+ expect.objectContaining({+ path: ['totalSize'],+ message: 'Disable spend cap to increase disk above 8 GB.',+ })+ )+ })++ test.each(['FLY', 'AWS_NIMBUS', 'AWS_K8S'] as const)(+ 'skips platform disk constraints for %s projects',+ (cloudProvider) => {+ const schema = CreateDiskStorageSchema({+ defaultTotalSize: 8,+ cloudProvider,+ isSpendCapEnabled: true,+ })++ expect(+ schema.safeParse({+ ...validGp3Config,+ totalSize: 1,+ provisionedIOPS: 100_000,+ throughput: 10_000,+ }).success+ ).toBe(true)+ }+ )})diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.sections.tsx b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.sections.tsxnew file mode 100644index 00000000000..8acdbfccf65--- /dev/null+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.sections.tsx@@ -0,0 +1,327 @@+import { type RefObject } from 'react'+import { type UseFormReturn } from 'react-hook-form'+import { Button, Card, CardContent } from 'ui'+import { Admonition } from 'ui-patterns/Admonition'+import {+ PageSection,+ PageSectionAside,+ PageSectionContent,+ PageSectionDescription,+ PageSectionMeta,+ PageSectionSummary,+ PageSectionTitle,+} from 'ui-patterns/PageSection'++import { DiskStorageSchemaType } from './DiskManagement.schema'+import { AutoScaleFields } from './fields/AutoScaleFields'+import {+ ComputeSectionBillingBadge,+ ComputeSizeField,+ ComputeSizeFieldMeta,+} from './fields/ComputeSizeField'+import { DiskSizeField } from './fields/DiskSizeField'+import { IOPSField } from './fields/IOPSField'+import { StorageTypeField } from './fields/StorageTypeField'+import { ThroughputField } from './fields/ThroughputField'+import { BillingChangeBadge } from './ui/BillingChangeBadge'+import { DiskCountdownRadial } from './ui/DiskCountdownRadial'+import { DiskSpaceBar } from './ui/DiskSpaceBar'+import { NoticeBar } from './ui/NoticeBar'+import { SpendCapDisabledSection } from './ui/SpendCapDisabledSection'+import { DocsButton } from '@/components/ui/DocsButton'+import { RequestUpgradeToBillingOwners } from '@/components/ui/RequestUpgradeToBillingOwners'+import { DOCS_URL } from '@/lib/constants'++interface ComputeSectionProps {+ form: UseFormReturn<DiskStorageSchemaType>+ settingsRef: RefObject<HTMLDivElement | null>+ showBillingBadge: boolean+ beforePrice: number+ afterPrice: number+ disabled: boolean+}++export function ComputeSection({+ form,+ settingsRef,+ showBillingBadge,+ beforePrice,+ afterPrice,+ disabled,+}: ComputeSectionProps) {+ return (+ <PageSection className="pt-0">+ <PageSectionMeta>+ <PageSectionSummary>+ <PageSectionTitle className="heading-default text-base">Compute size</PageSectionTitle>+ <PageSectionDescription>+ <ComputeSizeFieldMeta />+ </PageSectionDescription>+ </PageSectionSummary>+ <PageSectionAside>+ <ComputeSectionBillingBadge+ form={form}+ show={showBillingBadge}+ beforePrice={beforePrice}+ afterPrice={afterPrice}+ />+ <DocsButton href={`${DOCS_URL}/guides/platform/compute-and-disk`} />+ </PageSectionAside>+ </PageSectionMeta>+ <PageSectionContent ref={settingsRef} className="scroll-mt-24">+ <ComputeSizeField form={form} disabled={disabled} />+ </PageSectionContent>+ </PageSection>+ )+}++interface DiskSectionProps {+ form: UseFormReturn<DiskStorageSchemaType>+ settingsRef: RefObject<HTMLDivElement | null>+ showBillingBadge: boolean+ beforePrice: number+ afterPrice: number+ isAws: boolean+ isAwsK8s: boolean+ isBranch: boolean+ isNoticeVisible: boolean+ isReadOnlyMode: boolean+ usedPercentage: number+ isWithinCooldownWindow: boolean+ currentDiskSizeGb?: number+ disableDiskSizeInput: boolean+}++function getDiskNoticeDescription({+ isAwsK8s,+ isBranch,+}: Pick<DiskSectionProps, 'isAwsK8s' | 'isBranch'>) {+ if (isAwsK8s) {+ return 'Configuring your disk for AWS (Revamped) projects is unavailable for now.'+ }+ if (isBranch) {+ return 'Delete and recreate your Preview Branch to configure disk size. It was deployed on an older branching infrastructure.'+ }+ return 'The Fly Postgres offering is deprecated - please migrate your instance to the AWS cloud provider to configure your disk.'+}++export function DiskSection({+ form,+ settingsRef,+ showBillingBadge,+ beforePrice,+ afterPrice,+ isAws,+ isAwsK8s,+ isBranch,+ isNoticeVisible,+ isReadOnlyMode,+ usedPercentage,+ isWithinCooldownWindow,+ currentDiskSizeGb,+ disableDiskSizeInput,+}: DiskSectionProps) {+ const noticeDescription = getDiskNoticeDescription({ isAwsK8s, isBranch })++ return (+ <PageSection id="disk-size">+ <PageSectionMeta>+ <PageSectionSummary>+ <PageSectionTitle className="heading-default text-base">Disk</PageSectionTitle>+ <PageSectionDescription>+ Configure provisioned storage for your primary database.+ </PageSectionDescription>+ </PageSectionSummary>+ <PageSectionAside>+ <BillingChangeBadge+ show={showBillingBadge}+ beforePrice={beforePrice}+ afterPrice={afterPrice}+ />+ <DocsButton href={`${DOCS_URL}/guides/platform/database-size`} />+ </PageSectionAside>+ </PageSectionMeta>+ <PageSectionContent ref={settingsRef} className="flex flex-col gap-4 scroll-mt-24">+ {isAws && <DiskSpaceBar form={form} />}++ <SpendCapDisabledSection currentDiskSizeGb={currentDiskSizeGb} />++ <NoticeBar+ type="default"+ visible={isNoticeVisible}+ title="Disk configuration is only available for projects in the AWS cloud provider"+ description={noticeDescription}+ />++ {isAws && (+ <>+ <div className="flex flex-col gap-y-3">+ <DiskCountdownRadial />+ {!isReadOnlyMode && usedPercentage >= 90 && isWithinCooldownWindow && (+ <Admonition+ type="destructive"+ title="Database size is currently over 90% of disk size"+ description="Your project will enter read-only mode once you reach 95% of the disk space to prevent your database from exceeding the disk limitations"+ >+ <DocsButton+ abbrev={false}+ className="mt-2"+ href={`${DOCS_URL}/guides/platform/database-size#read-only-mode`}+ />+ </Admonition>+ )}+ {isReadOnlyMode && (+ <Admonition+ type="destructive"+ title="Project is currently in read-only mode"+ description="You will need to manually override read-only mode and reduce the database size to below 95% of the disk size"+ >+ <DocsButton+ abbrev={false}+ className="mt-2"+ href={`${DOCS_URL}/guides/platform/database-size#disabling-read-only-mode`}+ />+ </Admonition>+ )}+ </div>++ <Card>+ <CardContent>+ <DiskSizeField form={form} disableInput={disableDiskSizeInput} />+ </CardContent>+ </Card>+ </>+ )}+ </PageSectionContent>+ </PageSection>+ )+}++interface AdvancedSectionProps {+ form: UseFormReturn<DiskStorageSchemaType>+ autoscaleSettingsRef: RefObject<HTMLDivElement | null>+ storageSettingsRef: RefObject<HTMLDivElement | null>+ showBillingBadge: boolean+ beforePrice: number+ afterPrice: number+ disableIopsThroughputConfig?: boolean+ canUpdateDiskConfiguration: boolean+ isDiskTooSmallForCustomIops: boolean+ disableDiskInputs: boolean+ disableDiskSizeInput: boolean+ suggestedDiskSizeForCustomIops: number+}++export function AdvancedSection({+ form,+ autoscaleSettingsRef,+ storageSettingsRef,+ showBillingBadge,+ beforePrice,+ afterPrice,+ disableIopsThroughputConfig,+ canUpdateDiskConfiguration,+ isDiskTooSmallForCustomIops,+ disableDiskInputs,+ disableDiskSizeInput,+ suggestedDiskSizeForCustomIops,+}: AdvancedSectionProps) {+ return (+ <PageSection>+ <PageSectionMeta>+ <PageSectionSummary>+ <PageSectionTitle className="heading-default text-base">Advanced</PageSectionTitle>+ <PageSectionDescription>+ Configure autoscaling, storage type, IOPS, and throughput.+ </PageSectionDescription>+ </PageSectionSummary>+ <PageSectionAside>+ <BillingChangeBadge+ show={showBillingBadge}+ beforePrice={beforePrice}+ afterPrice={afterPrice}+ />+ </PageSectionAside>+ </PageSectionMeta>+ <PageSectionContent className="flex flex-col gap-4">+ <Card ref={autoscaleSettingsRef} className="scroll-mt-24">+ <CardContent className="flex flex-col gap-y-8">+ <AutoScaleFields form={form} />+ </CardContent>+ </Card>++ <Card ref={storageSettingsRef} className="scroll-mt-24">+ <CardContent className="flex flex-col gap-y-8">+ <NoticeBar+ type="default"+ visible={!!disableIopsThroughputConfig}+ title="Adjusting disk configuration requires LARGE Compute size or above"+ description={`Increase your compute size to adjust your disk's storage type, ${form.getValues('storageType') === 'gp3' ? 'IOPS, ' : ''} and throughput`}+ actions={+ canUpdateDiskConfiguration ? (+ <Button+ variant="default"+ onClick={() => {+ form.setValue('computeSize', 'ci_large', {+ shouldDirty: true,+ shouldValidate: true,+ })+ form.trigger('provisionedIOPS')+ form.trigger('throughput')+ }}+ >+ Change to LARGE Compute+ </Button>+ ) : (+ <RequestUpgradeToBillingOwners+ addon="computeSize"+ featureProposition="adjust disk configuration"+ />+ )+ }+ />+ <NoticeBar+ type="default"+ visible={+ isDiskTooSmallForCustomIops && !disableIopsThroughputConfig && !disableDiskInputs+ }+ title="Increase disk size to adjust IOPS or throughput"+ description={`This disk is too small to update IOPS or throughput, since gp3 volumes are capped at 500 IOPS per GB with a 3,000 IOPS minimum. Resizing to ${suggestedDiskSizeForCustomIops} GB unlocks custom IOPS and throughput, and leaves headroom for further adjustments (disk config changes are limited to 4 within a rolling 24-hour window).`}+ actions={+ !disableDiskSizeInput ? (+ <Button+ variant="default"+ onClick={() => {+ form.setValue('totalSize', suggestedDiskSizeForCustomIops, {+ shouldDirty: true,+ shouldValidate: true,+ })+ }}+ >+ Increase to {suggestedDiskSizeForCustomIops} GB+ </Button>+ ) : undefined+ }+ />+ <StorageTypeField+ form={form}+ disableInput={!!disableIopsThroughputConfig || disableDiskInputs}+ />+ <IOPSField+ form={form}+ disableInput={+ !!disableIopsThroughputConfig || disableDiskInputs || isDiskTooSmallForCustomIops+ }+ />+ <ThroughputField+ form={form}+ disableInput={+ !!disableIopsThroughputConfig || disableDiskInputs || isDiskTooSmallForCustomIops+ }+ />+ </CardContent>+ </Card>+ </PageSectionContent>+ </PageSection>+ )+}diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsxindex c78aab5d4e1..f3e54c03a10 100644--- a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx@@ -2,53 +2,39 @@ import { zodResolver } from '@hookform/resolvers/zod'import { PermissionAction } from '@supabase/shared-types/out/constants'import { useParams } from 'common'import { AnimatePresence, motion } from 'framer-motion'-import { ChevronRight } from 'lucide-react'import { useEffect, useRef, useState } from 'react'import { useForm } from 'react-hook-form'import { CloudProvider } from 'shared-data'import { toast } from 'sonner'+import { Button, cn, Form } from 'ui'+import { PageContainer } from 'ui-patterns/PageContainer'import {- Button,- cn,- Collapsible,- CollapsibleContent,- CollapsibleTrigger,- DialogSectionSeparator,- Form,- Separator,-} from 'ui'-import { Admonition } from 'ui-patterns/Admonition'--import { FormFooterChangeBadge } from '../DataWarehouse/FormFooterChangeBadge'+ PageSection,+ PageSectionContent,+ PageSectionMeta,+ PageSectionSummary,+ PageSectionTitle,+} from 'ui-patterns/PageSection'+import { CreateDiskStorageSchema, DiskStorageSchemaType } from './DiskManagement.schema'import { DiskManagementMessage } from './DiskManagement.types'import {calculateDiskSizeRequiredForIopsWithGp3,mapComputeSizeNameToAddonVariantId,} from './DiskManagement.utils'+import { AdvancedSection, ComputeSection, DiskSection } from './DiskManagementForm.sections'import { DiskMangementRestartRequiredSection } from './DiskManagementRestartRequiredSection'import { DiskManagementReviewAndSubmitDialog } from './DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog'-import { AutoScaleFields } from './fields/AutoScaleFields'-import { ComputeSizeField } from './fields/ComputeSizeField'-import { DiskSizeField } from './fields/DiskSizeField'-import { IOPSField } from './fields/IOPSField'-import { StorageTypeField } from './fields/StorageTypeField'-import { ThroughputField } from './fields/ThroughputField'-import { DiskCountdownRadial } from './ui/DiskCountdownRadial'+import { useDiskManagementReviewChanges } from './DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.hooks'+import { BillingChangeBadge } from './ui/BillingChangeBadge'import {DISK_LIMITS,DiskType,PLAN_DETAILS,RESTRICTED_COMPUTE_FOR_THROUGHPUT_ON_GP3,} from './ui/DiskManagement.constants'-import { SpendCapDisabledSection } from './ui/SpendCapDisabledSection'-import {- MAX_WIDTH_CLASSES,- PADDING_CLASSES,- ScaffoldContainer,-} from '@/components/layouts/Scaffold'-import { DocsButton } from '@/components/ui/DocsButton'-import { RequestUpgradeToBillingOwners } from '@/components/ui/RequestUpgradeToBillingOwners'+import { NoticeBar } from './ui/NoticeBar'+import { PADDING_CLASSES } from '@/components/layouts/Scaffold'import { UpgradeToPro } from '@/components/ui/UpgradeToPro'import {useDiskAttributesQuery,@@ -73,7 +59,7 @@ import {useIsAwsNimbusCloudProvider,useSelectedProjectQuery,} from '@/hooks/misc/useSelectedProject'-import { DOCS_URL, GB, PROJECT_STATUS } from '@/lib/constants'+import { GB, PROJECT_STATUS } from '@/lib/constants'export function DiskManagementForm() {const { ref: projectRef } = useParams()@@ -81,7 +67,10 @@ export function DiskManagementForm() {const { data: org } = useSelectedOrganizationQuery()const { setProjectStatus } = useSetProjectStatus()- const advancedSettingsRef = useRef<HTMLDivElement>(null)+ const autoscaleSettingsRef = useRef<HTMLDivElement>(null)+ const storageSettingsRef = useRef<HTMLDivElement>(null)+ const computeSettingsRef = useRef<HTMLDivElement>(null)+ const diskSizeSettingsRef = useRef<HTMLDivElement>(null)const isSpendCapEnabled =org?.plan.id !== 'free' && !org?.usage_billing_enabled && project?.cloud_provider !== 'FLY'@@ -110,7 +99,6 @@ export function DiskManagementForm() {const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false)const [refetchInterval, setRefetchInterval] = useState<number | false>(false)const [message, setMessageState] = useState<DiskManagementMessage | null>(null)- const [advancedSettingsOpen, setAdvancedSettingsOpenState] = useState(false)const { data: databases, isSuccess: isReadReplicasSuccess } = useReadReplicasQuery({ projectRef })const { data, isSuccess: isDiskAttributesSuccess } = useDiskAttributesQuery(@@ -183,6 +171,18 @@ export function DiskManagementForm() {const readReplicas = (databases ?? []).filter((db) => db.identifier !== projectRef)const isPlanUpgradeRequired = !hasAccess+ const {+ computeSizePrice,+ diskSizePrice,+ totalBeforePrice,+ totalAfterPrice,+ advancedBeforePrice,+ advancedAfterPrice,+ showComputeBillingBadge,+ showDiskBillingBadge,+ showAdvancedBillingBadge,+ } = useDiskManagementReviewChanges(form, readReplicas.length)+const { formState } = formconst errors = formState.errorsconst usedSize = Math.round(((diskUtil?.metrics.fs_used_bytes ?? 0) / GB) * 100) / 100@@ -346,7 +346,7 @@ export function DiskManagementForm() {form.setValue('provisionedIOPS', DISK_LIMITS['gp3'].minIops)}}- }, [modifiedComputeSize, isDialogOpen, project])+ }, [modifiedComputeSize, form, isDialogOpen, project])useEffect(() => {// Initialize field values properly when data has been loaded, preserving any user changes@@ -358,287 +358,166 @@ export function DiskManagementForm() {useEffect(() => {const fieldErrors = Object.keys(errors)- if (fieldErrors.length > 0) {- if (- fieldErrors.includes('throughput') ||- fieldErrors.includes('provisionedIOPS') ||- fieldErrors.includes('maxSizeGb')- ) {- setAdvancedSettingsOpenState(true)+ if (fieldErrors.length === 0) return++ const scrollTargets = [+ {+ hasError:+ fieldErrors.includes('maxSizeGb') ||+ fieldErrors.includes('growthPercent') ||+ fieldErrors.includes('minIncrementGb'),+ ref: autoscaleSettingsRef,+ },+ {+ hasError: fieldErrors.includes('throughput') || fieldErrors.includes('provisionedIOPS'),+ ref: storageSettingsRef,+ },+ { hasError: fieldErrors.includes('totalSize'), ref: diskSizeSettingsRef },+ { hasError: fieldErrors.includes('computeSize'), ref: computeSettingsRef },+ ]+ const scrollTarget = scrollTargets.find(({ hasError }) => hasError)?.ref ?? null- // [Joshen] The timeout is to let the collapsible open prior to scrolling- const timeoutId = setTimeout(() => {- advancedSettingsRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })- }, 100)+ if (!scrollTarget) return- return () => clearTimeout(timeoutId)- }- }+ const timeoutId = setTimeout(() => {+ scrollTarget.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })+ }, 100)++ return () => clearTimeout(timeoutId)}, [errors])return (- <>- <ScaffoldContainer className="relative flex flex-col gap-10" bottomPadding>- {isEntitlementsLoaded && isPlanUpgradeRequired && (- <UpgradeToPro- featureProposition="configure compute and disk"- primaryText="Only available on Pro Plan and above"- secondaryText="Upgrade to the Pro Plan to configure compute and disk settings."- />- )}-- {(isProjectResizing ||- isProjectRequestingDiskChanges ||- (isEntitlementsLoaded && !isPlanUpgradeRequired && noPermissions)) && (- <div className="relative flex flex-col gap-10">- <DiskMangementRestartRequiredSection- visible={isProjectResizing}- title="Your project will now automatically restart."- description="Your project will be unavailable for up to 2 mins."- />- {isProjectRequestingDiskChanges && (- <Admonition+ <Form {...form}>+ <form id="disk-compute-form" onSubmit={form.handleSubmit(onSubmit)}>+ <PageContainer size="default" className="pb-16">+ {(isProjectResizing ||+ isProjectRequestingDiskChanges ||+ (isEntitlementsLoaded && !isPlanUpgradeRequired && noPermissions)) && (+ <div className="relative flex flex-col gap-10">+ <DiskMangementRestartRequiredSection+ visible={isProjectResizing}+ title="Your project will now automatically restart."+ description="Your project will be unavailable for up to 2 mins."+ />+ <NoticeBartype="default"- layout="horizontal"+ visible={isProjectRequestingDiskChanges}title="Disk configuration changes have been requested"description="The requested changes will be applied to your disk shortly"/>- )}- {isEntitlementsLoaded && !isPlanUpgradeRequired && noPermissions && (- <Admonition+ <NoticeBartype="default"- layout="horizontal"+ visible={isEntitlementsLoaded && !isPlanUpgradeRequired && noPermissions}title="You do not have permission to update disk configuration"description="Please contact your organization administrator to update your disk configuration"/>- )}- </div>- )}-- <Separator />- </ScaffoldContainer>-- <Form {...form}>- <form- id="disk-compute-form"- onSubmit={form.handleSubmit(onSubmit)}- className="flex flex-col gap-8"- >- <ScaffoldContainer className="relative flex flex-col gap-10" bottomPadding>- <ComputeSizeField form={form} disabled={disableComputeInputs} />-- {isDiskNoticeVisible && <Separator />}-- <SpendCapDisabledSection currentDiskSizeGb={defaultValues.totalSize} />-- <div className="flex flex-col gap-y-4">- {isDiskNoticeVisible && (- <Admonition- type="default"- layout="horizontal"- title="Disk configuration is only available for projects in the AWS cloud provider"- description={- isAwsK8s- ? 'Configuring your disk for AWS (Revamped) projects is unavailable for now.'- : isBranch- ? 'Delete and recreate your Preview Branch to configure disk size. It was deployed on an older branching infrastructure.'- : 'The Fly Postgres offering is deprecated - please migrate your instance to the AWS cloud prov to configure your disk.'- }- />- )}- {isAws && (- <>- <div className="flex flex-col gap-y-3">- <DiskCountdownRadial />- {!isReadOnlyMode && usedPercentage >= 90 && isWithinCooldownWindow && (- <Admonition- type="destructive"- title="Database size is currently over 90% of disk size"- description="Your project will enter read-only mode once you reach 95% of the disk space to prevent your database from exceeding the disk limitations"- >- <DocsButton- abbrev={false}- className="mt-2"- href={`${DOCS_URL}/guides/platform/database-size#read-only-mode`}- />- </Admonition>- )}- {isReadOnlyMode && (- <Admonition- type="destructive"- title="Project is currently in read-only mode"- description="You will need to manually override read-only mode and reduce the database size to below 95% of the disk size"- >- <DocsButton- abbrev={false}- className="mt-2"- href={`${DOCS_URL}/guides/platform/database-size#disabling-read-only-mode`}- />- </Admonition>- )}- </div>-- <DiskSizeField- form={form}- disableInput={disableDiskSizeInput}- setAdvancedSettingsOpenState={setAdvancedSettingsOpenState}- />- </>- )}</div>+ )}++ <PageSection>+ <PageSectionMeta>+ <PageSectionSummary>+ <PageSectionTitle>Scaling</PageSectionTitle>+ </PageSectionSummary>+ </PageSectionMeta>+ {isEntitlementsLoaded && isPlanUpgradeRequired && (+ <UpgradeToPro+ featureProposition="configure compute and disk"+ primaryText="Only available on Pro Plan and above"+ secondaryText="Upgrade to the Pro Plan to configure compute and disk settings."+ />+ )}+ <PageSectionContent>+ <ComputeSection+ form={form}+ settingsRef={computeSettingsRef}+ showBillingBadge={showComputeBillingBadge}+ beforePrice={Number(computeSizePrice.oldPrice)}+ afterPrice={Number(computeSizePrice.newPrice)}+ disabled={disableComputeInputs}+ />- {isAws && (- <>- <Separator />+ <DiskSection+ form={form}+ settingsRef={diskSizeSettingsRef}+ showBillingBadge={showDiskBillingBadge}+ beforePrice={Number(diskSizePrice.oldPrice)}+ afterPrice={Number(diskSizePrice.newPrice)}+ isAws={isAws}+ isAwsK8s={isAwsK8s}+ isBranch={isBranch}+ isNoticeVisible={isDiskNoticeVisible}+ isReadOnlyMode={!!isReadOnlyMode}+ usedPercentage={usedPercentage}+ isWithinCooldownWindow={isWithinCooldownWindow}+ currentDiskSizeGb={defaultValues.totalSize}+ disableDiskSizeInput={disableDiskSizeInput}+ />- <Collapsible- open={advancedSettingsOpen}- onOpenChange={() => setAdvancedSettingsOpenState((prev) => !prev)}- >- <CollapsibleTrigger className="px-card py-3 w-full border flex items-center gap-6 rounded-t data-closed:rounded-b group justify-between">- <div className="flex flex-col items-start">- <span className="text-sm text-foreground">Advanced disk settings</span>- <span className="text-sm text-foreground-light text-left">- Specify additional settings for your disk, including autoscaling- configuration, IOPS, throughput, and disk type.- </span>- </div>- <ChevronRight- size={16}- className="text-foreground-light transition-all group-data-open:rotate-90"- strokeWidth={1}- />- </CollapsibleTrigger>- <CollapsibleContent- ref={advancedSettingsRef}- className={cn(- 'transition-all rounded-b',- 'border border-t-0 data-closed:animate-collapsible-up data-open:animate-collapsible-down'- )}- >- <div className="flex flex-col gap-y-8 py-8">- <div className="px-card flex flex-col gap-y-8">- <AutoScaleFields form={form} />- </div>- <DialogSectionSeparator />- <div className="px-card flex flex-col gap-y-8">- {!!disableIopsThroughputConfig && (- <Admonition- type="default"- title="Adjusting disk configuration requires LARGE Compute size or above"- description={`Increase your compute size to adjust your disk's storage type, ${form.getValues('storageType') === 'gp3' ? 'IOPS, ' : ''} and throughput`}- actions={- canUpdateDiskConfiguration ? (- <Button- variant="default"- onClick={() => {- form.setValue('computeSize', 'ci_large')- }}- >- Change to LARGE Compute- </Button>- ) : (- <RequestUpgradeToBillingOwners- addon="computeSize"- featureProposition="adjust disk configuration"- />- )- }- />- )}- {isDiskTooSmallForCustomIops &&- !disableIopsThroughputConfig &&- !disableDiskInputs && (- <Admonition- type="default"- title="Increase disk size to adjust IOPS or throughput"- description={`This disk is too small to update IOPS or throughput, since gp3 volumes are capped at 500 IOPS per GB with a 3,000 IOPS minimum. Resizing to ${suggestedDiskSizeForCustomIops} GB unlocks custom IOPS and throughput, and leaves headroom for further adjustments (disk config changes are limited to 4 within a rolling 24-hour window).`}- actions={- !disableDiskSizeInput ? (- <Button- variant="default"- onClick={() => {- form.setValue('totalSize', suggestedDiskSizeForCustomIops, {- shouldDirty: true,- shouldValidate: true,- })- }}- >- Increase to {suggestedDiskSizeForCustomIops} GB- </Button>- ) : undefined- }- />- )}- <StorageTypeField- form={form}- disableInput={disableIopsThroughputConfig || disableDiskInputs}- />- <IOPSField- form={form}- disableInput={- disableIopsThroughputConfig ||- disableDiskInputs ||- isDiskTooSmallForCustomIops- }- />- <ThroughputField- form={form}- disableInput={- disableIopsThroughputConfig ||- disableDiskInputs ||- isDiskTooSmallForCustomIops- }- />- </div>- </div>- </CollapsibleContent>- </Collapsible>- </>- )}- </ScaffoldContainer>-- <AnimatePresence>- {isDirty ? (- <motion.div- initial={{ opacity: 0, y: 20 }}- animate={{ opacity: 1, y: 0 }}- exit={{ opacity: 0, y: 20 }}- transition={{ duration: 0.1, delay: 0.2 }}- className="z-10 w-full left-0 right-0 sticky bottom-0 bg-surface-100 border-t h-16 items-center flex"+ {isAws && (+ <AdvancedSection+ form={form}+ autoscaleSettingsRef={autoscaleSettingsRef}+ storageSettingsRef={storageSettingsRef}+ showBillingBadge={showAdvancedBillingBadge}+ beforePrice={advancedBeforePrice}+ afterPrice={advancedAfterPrice}+ disableIopsThroughputConfig={disableIopsThroughputConfig}+ canUpdateDiskConfiguration={canUpdateDiskConfiguration}+ isDiskTooSmallForCustomIops={isDiskTooSmallForCustomIops}+ disableDiskInputs={disableDiskInputs}+ disableDiskSizeInput={disableDiskSizeInput}+ suggestedDiskSizeForCustomIops={suggestedDiskSizeForCustomIops}+ />+ )}+ </PageSectionContent>+ </PageSection>+ </PageContainer>++ <AnimatePresence>+ {isDirty ? (+ <motion.div+ initial={{ opacity: 0, y: 20 }}+ animate={{ opacity: 1, y: 0 }}+ exit={{ opacity: 0, y: 20 }}+ transition={{ duration: 0.1, delay: 0.2 }}+ className="z-10 w-full left-0 right-0 sticky bottom-0 bg-surface-100 border-t h-16 items-center flex"+ >+ <div+ className={cn(+ 'mx-auto w-full max-w-[1200px]',+ PADDING_CLASSES,+ 'flex items-center justify-end gap-3'+ )}>- <div- className={cn(- MAX_WIDTH_CLASSES,- PADDING_CLASSES,- 'flex items-center gap-3 justify-end'- )}+ <BillingChangeBadge+ show={isDirty}+ beforePrice={totalBeforePrice}+ afterPrice={totalAfterPrice}+ />+ <Button+ variant="default"+ onClick={() => form.reset()}+ disabled={!isDirty}+ size="medium">- <FormFooterChangeBadge formState={formState} />- <Button- variant="default"- onClick={() => form.reset()}- disabled={!isDirty}- size="medium"- >- Cancel- </Button>- <DiskManagementReviewAndSubmitDialog- loading={isUpdatingConfig}- disabled={noPermissions}- form={form}- numReplicas={readReplicas.length}- isDialogOpen={isDialogOpen}- onSubmit={onSubmit}- setIsDialogOpen={setIsDialogOpen}- message={message}- />- </div>- </motion.div>- ) : null}- </AnimatePresence>- </form>- </Form>- </>+ Cancel+ </Button>+ <DiskManagementReviewAndSubmitDialog+ loading={isUpdatingConfig}+ disabled={noPermissions}+ form={form}+ numReplicas={readReplicas.length}+ isDialogOpen={isDialogOpen}+ onSubmit={onSubmit}+ setIsDialogOpen={setIsDialogOpen}+ message={message}+ />+ </div>+ </motion.div>+ ) : null}+ </AnimatePresence>+ </form>+ </Form>)}diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.hooks.test.ts b/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.hooks.test.tsnew file mode 100644index 00000000000..9c9edcfbf1f--- /dev/null+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.hooks.test.ts@@ -0,0 +1,49 @@+import { describe, expect, test } from 'vitest'++import { shouldShowComputeBillingBadge } from './DiskManagementReviewAndSubmitDialog.hooks'++describe('shouldShowComputeBillingBadge', () => {+ test('shows for a dirty, valid compute price change', () => {+ expect(+ shouldShowComputeBillingBadge({+ isDirty: true,+ hasComputeSizeError: false,+ oldPrice: '10.00',+ newPrice: '20.00',+ })+ ).toBe(true)+ })++ test('hides when the selected compute size has the same price', () => {+ expect(+ shouldShowComputeBillingBadge({+ isDirty: true,+ hasComputeSizeError: false,+ oldPrice: '10.00',+ newPrice: '10',+ })+ ).toBe(false)+ })++ test('hides when the form is not dirty', () => {+ expect(+ shouldShowComputeBillingBadge({+ isDirty: false,+ hasComputeSizeError: false,+ oldPrice: '10.00',+ newPrice: '20.00',+ })+ ).toBe(false)+ })++ test('hides when compute size validation fails', () => {+ expect(+ shouldShowComputeBillingBadge({+ isDirty: true,+ hasComputeSizeError: true,+ oldPrice: '10.00',+ newPrice: '20.00',+ })+ ).toBe(false)+ })+})diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.hooks.ts b/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.hooks.tsindex a61cd844209..56db829918d 100644--- a/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.hooks.ts+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.hooks.ts@@ -1,5 +1,5 @@import { useMemo } from 'react'-import { UseFormReturn } from 'react-hook-form'+import { useFormState, useWatch, type UseFormReturn } from 'react-hook-form'import { DiskStorageSchemaType } from '../DiskManagement.schema'import { ComputeInstanceAddonVariantId } from '../DiskManagement.types'@@ -26,10 +26,48 @@ const COMPUTE_SIZES_BELOW_LARGE: Array<ComputeInstanceAddonVariantId> = ['ci_medium',]+export function shouldShowComputeBillingBadge({+ isDirty,+ hasComputeSizeError,+ oldPrice,+ newPrice,+}: {+ isDirty: boolean+ hasComputeSizeError: boolean+ oldPrice: string | number+ newPrice: string | number+}) {+ return isDirty && !hasComputeSizeError && Number(oldPrice) !== Number(newPrice)+}+export function useDiskManagementReviewChanges(form: UseFormReturn<DiskStorageSchemaType>,numReplicas: number) {+ const [+ computeSize,+ totalSize,+ storageType,+ provisionedIOPS,+ throughput,+ growthPercent,+ minIncrementGb,+ maxSizeGb,+ ] = useWatch({+ control: form.control,+ name: [+ 'computeSize',+ 'totalSize',+ 'storageType',+ 'provisionedIOPS',+ 'throughput',+ 'growthPercent',+ 'minIncrementGb',+ 'maxSizeGb',+ ],+ })+ const { isDirty, errors, defaultValues } = useFormState({ control: form.control })+const { data: project } = useSelectedProjectQuery()const { data: org } = useSelectedOrganizationQuery()const isAwsNimbus = useIsAwsNimbusCloudProvider()@@ -48,29 +86,29 @@ export function useDiskManagementReviewChanges(const computeSizePrice = calculateComputeSizePrice({availableOptions,- oldComputeSize: form.formState.defaultValues?.computeSize || 'ci_micro',- newComputeSize: form.getValues('computeSize'),+ oldComputeSize: defaultValues?.computeSize || 'ci_micro',+ newComputeSize: computeSize,plan: planId,})const diskSizePrice = calculateDiskSizePrice({planId,- oldSize: form.formState.defaultValues?.totalSize || 0,- oldStorageType: form.formState.defaultValues?.storageType as DiskType,- newSize: form.getValues('totalSize'),- newStorageType: form.getValues('storageType') as DiskType,+ oldSize: defaultValues?.totalSize || 0,+ oldStorageType: defaultValues?.storageType as DiskType,+ newSize: totalSize,+ newStorageType: storageType as DiskType,numReplicas,})const iopsPrice = calculateIOPSPrice({- oldStorageType: form.formState.defaultValues?.storageType as DiskType,- oldProvisionedIOPS: form.formState.defaultValues?.provisionedIOPS || 0,- newStorageType: form.getValues('storageType') as DiskType,- newProvisionedIOPS: form.getValues('provisionedIOPS'),+ oldStorageType: defaultValues?.storageType as DiskType,+ oldProvisionedIOPS: defaultValues?.provisionedIOPS || 0,+ newStorageType: storageType as DiskType,+ newProvisionedIOPS: provisionedIOPS,numReplicas,})const throughputPrice = calculateThroughputPrice({- storageType: form.getValues('storageType') as DiskType,- newThroughput: form.getValues('throughput') || 0,- oldThroughput: form.formState.defaultValues?.throughput || 0,+ storageType: storageType as DiskType,+ newThroughput: throughput || 0,+ oldThroughput: defaultValues?.throughput || 0,numReplicas,})@@ -86,49 +124,55 @@ export function useDiskManagementReviewChanges(Number(iopsPrice.newPrice) +Number(throughputPrice.newPrice)+ const advancedBeforePrice = Number(iopsPrice.oldPrice) + Number(throughputPrice.oldPrice)+ const advancedAfterPrice = Number(iopsPrice.newPrice) + Number(throughputPrice.newPrice)++ const showComputeBillingBadge = shouldShowComputeBillingBadge({+ isDirty,+ hasComputeSizeError: !!errors.computeSize,+ oldPrice: computeSizePrice.oldPrice,+ newPrice: computeSizePrice.newPrice,+ })++ const showDiskBillingBadge =+ isDirty &&+ !errors.totalSize &&+ Number(diskSizePrice.oldPrice) !== Number(diskSizePrice.newPrice)++ const showAdvancedBillingBadge =+ isDirty &&+ advancedBeforePrice !== advancedAfterPrice &&+ !errors.provisionedIOPS &&+ !errors.throughput+// --- Change flags ---- const hasComputeChanges =- form.formState.defaultValues?.computeSize !== form.getValues('computeSize')+ const hasComputeChanges = defaultValues?.computeSize !== computeSizeconst hasTotalSizeChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.totalSize !== form.getValues('totalSize')+ !isAwsK8sProject && !isAwsNimbus && defaultValues?.totalSize !== totalSizeconst hasStorageTypeChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.storageType !== form.getValues('storageType')+ !isAwsK8sProject && !isAwsNimbus && defaultValues?.storageType !== storageTypeconst hasThroughputChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.throughput !== form.getValues('throughput')+ !isAwsK8sProject && !isAwsNimbus && defaultValues?.throughput !== throughputconst hasIOPSChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.provisionedIOPS !== form.getValues('provisionedIOPS')+ !isAwsK8sProject && !isAwsNimbus && defaultValues?.provisionedIOPS !== provisionedIOPSconst hasGrowthPercentChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.growthPercent !== form.getValues('growthPercent')+ !isAwsK8sProject && !isAwsNimbus && defaultValues?.growthPercent !== growthPercentconst hasMinIncrementChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.minIncrementGb !== form.getValues('minIncrementGb')+ !isAwsK8sProject && !isAwsNimbus && defaultValues?.minIncrementGb !== minIncrementGbconst hasMaxSizeChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.maxSizeGb !== form.getValues('maxSizeGb')+ !isAwsK8sProject && !isAwsNimbus && defaultValues?.maxSizeGb !== maxSizeGb// --- Derived predicates ---- const storageTypeAfter = form.getValues('storageType') as DiskType+ const storageTypeAfter = storageType as DiskType// Show hero whenever any line-item price actually changes, not just computeconst anyBillableDiskChange =@@ -143,11 +187,9 @@ export function useDiskManagementReviewChanges(const hasExtendedDowntimeRisk =hasComputeChanges &&(COMPUTE_SIZES_BELOW_LARGE.includes(- (form.formState.defaultValues?.computeSize ?? 'ci_nano') as ComputeInstanceAddonVariantId+ (defaultValues?.computeSize ?? 'ci_nano') as ComputeInstanceAddonVariantId) ||- COMPUTE_SIZES_BELOW_LARGE.includes(- form.getValues('computeSize') as ComputeInstanceAddonVariantId- ))+ COMPUTE_SIZES_BELOW_LARGE.includes(computeSize as ComputeInstanceAddonVariantId))// Throughput is only a user-configurable, separately-billed attribute for GP3. For IO2 it is// derived from provisioned IOPS (0.256 MiB/s per IOPS) and isn't surfaced as its own value, so@@ -171,10 +213,8 @@ export function useDiskManagementReviewChanges(// --- Labels ---- const oldComputeLabel = mapAddOnVariantIdToComputeSize(- form.formState.defaultValues?.computeSize ?? 'ci_nano'- )- const newComputeLabel = mapAddOnVariantIdToComputeSize(form.getValues('computeSize'))+ const oldComputeLabel = mapAddOnVariantIdToComputeSize(defaultValues?.computeSize ?? 'ci_nano')+ const newComputeLabel = mapAddOnVariantIdToComputeSize(computeSize)return {// prices@@ -184,6 +224,11 @@ export function useDiskManagementReviewChanges(throughputPrice,totalBeforePrice,totalAfterPrice,+ advancedBeforePrice,+ advancedAfterPrice,+ showComputeBillingBadge,+ showDiskBillingBadge,+ showAdvancedBillingBadge,// change flagshasComputeChanges,hasTotalSizeChanges,diff --git a/apps/studio/components/interfaces/DiskManagement/fields/AutoScaleFields.tsx b/apps/studio/components/interfaces/DiskManagement/fields/AutoScaleFields.tsxindex e6a675e6dda..82bfd945a6d 100644--- a/apps/studio/components/interfaces/DiskManagement/fields/AutoScaleFields.tsx+++ b/apps/studio/components/interfaces/DiskManagement/fields/AutoScaleFields.tsx@@ -55,7 +55,7 @@ export const AutoScaleFields = ({ form }: AutoScaleFieldProps) => {render={({ field }) => {return (<FormItemLayout- layout="horizontal"+ layout="flex-row-reverse"label="Autoscale growth percent"id={field.name}labelOptional="Percentage of current disk size to grow"@@ -101,7 +101,7 @@ export const AutoScaleFields = ({ form }: AutoScaleFieldProps) => {render={({ field }) => {return (<FormItemLayout- layout="horizontal"+ layout="flex-row-reverse"label="Minimum increment"id={field.name}labelOptional="Minimum value to autoscale disk size by"@@ -147,7 +147,7 @@ export const AutoScaleFields = ({ form }: AutoScaleFieldProps) => {render={({ field }) => {return (<FormItemLayout- layout="horizontal"+ layout="flex-row-reverse"label="Maximum disk size"id={field.name}labelOptional="Maximum size that the disk can grow to"diff --git a/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsx b/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsxindex acd1cf8a1ae..8d96b14e7a1 100644--- a/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsx+++ b/apps/studio/components/interfaces/DiskManagement/fields/ComputeSizeField.tsx@@ -1,12 +1,14 @@import { SupportCategories } from '@supabase/shared-types/out/constants'import { useParams } from 'common'-import { ChevronRight, CpuIcon, Lock, Microchip } from 'lucide-react'-import { useEffect, useMemo, useState } from 'react'+import { CpuIcon, Lock, Microchip } from 'lucide-react'+import { useMemo } from 'react'import { UseFormReturn } from 'react-hook-form'import {- Button,cn,FormField,+ HoverCard,+ HoverCardContent,+ HoverCardTrigger,RadioGroupCard,RadioGroupCardItem,Skeleton,@@ -14,30 +16,21 @@ import {TooltipContent,TooltipTrigger,} from 'ui'-import { Admonition } from 'ui-patterns/Admonition'import { ComputeBadge } from 'ui-patterns/ComputeBadge'-import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'import { DiskStorageSchemaType } from '../DiskManagement.schema'import { ComputeInstanceAddonVariantId, InfraInstanceSize } from '../DiskManagement.types'-import {- calculateComputeSizePrice,- ComputeAddonVariant,- getAvailableComputeOptions,-} from '../DiskManagement.utils'+import { ComputeAddonVariant, getAvailableComputeOptions } from '../DiskManagement.utils'import { BillingChangeBadge } from '../ui/BillingChangeBadge'import FormMessage from '../ui/FormMessage'+import { useShowMicroUpgradeBadge } from './useShowMicroUpgradeBadge'import { SupportLink } from '@/components/interfaces/Support/SupportLink'-import { DocsButton } from '@/components/ui/DocsButton'import { InlineLink } from '@/components/ui/InlineLink'import { useProjectAddonsQuery } from '@/data/subscriptions/project-addons-query'-import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'-import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'-import { DOCS_URL } from '@/lib/constants'-const INITIALLY_VISIBLE_COUNT = 6+const SKELETON_PLACEHOLDER_COUNT = 6/*** to do: this could be a type from api-types@@ -47,18 +40,44 @@ type ComputeSizeFieldProps = {disabled?: boolean}+export function ComputeSizeFieldMeta() {+ return <p>Hardware resources allocated to your Postgres database</p>+}++type ComputeSectionBillingBadgeProps = {+ form: UseFormReturn<DiskStorageSchemaType>+ show: boolean+ beforePrice: number+ afterPrice: number+}++export function ComputeSectionBillingBadge({+ form,+ show,+ beforePrice,+ afterPrice,+}: ComputeSectionBillingBadgeProps) {+ const computeSize = form.watch('computeSize')+ const { showMicroUpgradeBadge } = useShowMicroUpgradeBadge()++ return (+ <BillingChangeBadge+ show={show}+ beforePrice={beforePrice}+ afterPrice={afterPrice}+ free={showMicroUpgradeBadge && computeSize === 'ci_micro'}+ />+ )+}+export function ComputeSizeField({ form, disabled }: ComputeSizeFieldProps) {const { ref } = useParams()const { data: org } = useSelectedOrganizationQuery()- const { data: project, isPending: isProjectLoading } = useSelectedProjectQuery()-- const { hasAccess: entitledUpdateCompute, isLoading: isEntitlementLoading } =- useCheckEntitlements('instances.compute_update_available_sizes')+ const { project, isProjectLoading, isEntitlementLoading, showMicroUpgradeBadge } =+ useShowMicroUpgradeBadge()const showComputePrice = useIsFeatureEnabled('project_addons:show_compute_price')- const { computeSize } = form.watch()-const {data: addons,isPending: isAddonsLoading,@@ -67,7 +86,7 @@ export function ComputeSizeField({ form, disabled }: ComputeSizeFieldProps) {const isLoading = isProjectLoading || isAddonsLoading || isEntitlementLoading- const { control, formState, setValue, trigger } = form+ const { control, setValue, trigger } = formconst availableAddons = useMemo(() => {return addons?.available_addons ?? []@@ -81,319 +100,239 @@ export function ComputeSizeField({ form, disabled }: ComputeSizeFieldProps) {return getAvailableComputeOptions(availableAddons, project?.cloud_provider)}, [availableAddons, project?.cloud_provider])- // Expand by default if the project's current compute size is beyond the initial visible set- const [showAllSizes, setShowAllSizes] = useState(() => {- const idx = availableOptions.findIndex((o) => o.identifier === computeSize)- return idx >= INITIALLY_VISIBLE_COUNT- })-- // Expand whenever the selected size falls outside the visible set — covers both initial data- // load (availableOptions starts empty) and computeSize changes after mount (e.g. form reset)- useEffect(() => {- const idx = availableOptions.findIndex((o) => o.identifier === computeSize)- if (idx >= INITIALLY_VISIBLE_COUNT) {- setShowAllSizes(true)- }- }, [computeSize, availableOptions])-const subscriptionPitr = addons?.selected_addons.find((addon) => addon.type === 'pitr')- const computeSizePrice = calculateComputeSizePrice({- availableOptions: availableOptions,- oldComputeSize: form.formState.defaultValues?.computeSize || 'ci_micro',- newComputeSize: form.getValues('computeSize'),- plan: org?.plan.id ?? 'free',- })-- const projectComputeSize = project?.infra_compute_size ?? 'nano'- const showUpgradeBadge = entitledUpdateCompute && projectComputeSize === 'nano'-- const selectedOptionIndex = availableOptions.findIndex((o) => o.identifier === computeSize)- const selectedOptionIsHidden = selectedOptionIndex >= INITIALLY_VISIBLE_COUNT-- // Always show all options if the selected one would be outside the visible slice,- // so the active card is never hidden from the user.- const visibleOptions =- showAllSizes || selectedOptionIsHidden- ? availableOptions- : availableOptions.slice(0, INITIALLY_VISIBLE_COUNT)- const hasHiddenOptions = availableOptions.length > INITIALLY_VISIBLE_COUNT+ const showSkeletons = isLoading+ const showLoadError = !isLoading && !!addonsError+ const showComputeOptions = !isLoading && !addonsErrorreturn (<FormFieldname="computeSize"control={control}render={({ field }) => (- <RadioGroupCard- {...field}- onValueChange={(value: ComputeInstanceAddonVariantId) => {- setValue('computeSize', value, {- shouldDirty: true,- shouldValidate: true,- })- trigger('provisionedIOPS')- trigger('throughput')- }}- defaultValue={field.value}- disabled={disabled}- >- <FormItemLayout- layout="horizontal"- isContainerResponsive- label="Compute size"- id={field.name}- className="gap-5"- labelOptional={+ <div className="@container">+ <RadioGroupCard+ {...field}+ onValueChange={(value: ComputeInstanceAddonVariantId) => {+ setValue('computeSize', value, {+ shouldDirty: true,+ shouldValidate: true,+ })+ 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'+ )}+ >+ {showSkeletons &&+ Array(SKELETON_PLACEHOLDER_COUNT)+ .fill(0)+ .map((_, i) => <Skeleton key={i} className="w-full h-[110px] rounded-md" />)}+ {showLoadError && (+ <FormMessage message={'Failed to load Compute size options'} type="error">+ <p>{addonsError?.message}</p>+ </FormMessage>+ )}+ {showComputeOptions && (<>- <BillingChangeBadge- className="mb-2"- show={- formState.isDirty &&- formState.dirtyFields.computeSize &&- !formState.errors.computeSize- }- beforePrice={Number(computeSizePrice.oldPrice)}- afterPrice={Number(computeSizePrice.newPrice)}- free={showUpgradeBadge && computeSize === 'ci_micro' ? true : false}- />- <p className="text-foreground-lighter">- Hardware resources allocated to your Postgres database- </p>+ {availableOptions.map((compute) => {+ const lockedMicroDueToPITR =+ compute.identifier === 'ci_micro' && !!subscriptionPitr+ const lockedNanoDueToPlan =+ org?.plan.id !== 'free' &&+ project?.infra_compute_size !== 'nano' &&+ compute.identifier === 'ci_nano'- <div className="mt-3">- <DocsButton- abbrev={false}- href={`${DOCS_URL}/guides/platform/compute-and-disk`}- />- </div>+ const lockedOption = lockedNanoDueToPlan || lockedMicroDueToPITR- {showUpgradeBadge && form.watch('computeSize') === 'ci_nano' && (- <Admonition- showIcon={false}- type="default"- className="mt-3 border-violet-900 bg-violet-200 [&_h5]:text-violet-1100"- title="Upgrade to Micro Compute"- description="This Project is already paying for Micro Compute. You can upgrade to Micro Compute at any time when convenient."- />- )}- </>- }- >- <div className="@container">- <div className={!addonsError ? 'grid gap-4 grid-cols-2 @[680px]:grid-cols-3' : ''}>- {isLoading ? (- Array(INITIALLY_VISIBLE_COUNT)- .fill(0)- .map((_, i) => <Skeleton key={i} className="w-full h-[110px] rounded-md" />)- ) : addonsError ? (- <FormMessage message={'Failed to load Compute size options'} type="error">- <p>{addonsError?.message}</p>- </FormMessage>- ) : (- <>- {visibleOptions.map((compute) => {- const lockedMicroDueToPITR =- compute.identifier === 'ci_micro' && !!subscriptionPitr- const lockedNanoDueToPlan =- org?.plan.id !== 'free' &&- project?.infra_compute_size !== 'nano' &&- compute.identifier === 'ci_nano'-- const lockedOption = lockedNanoDueToPlan || lockedMicroDueToPITR+ // Nano on a paid plan is billed at the Micro rate+ const isNanoBilledAsMicro =+ org?.plan.id !== 'free' &&+ project?.infra_compute_size === 'nano' &&+ compute.identifier === 'ci_nano'- const price =- org?.plan.id !== 'free' &&- project?.infra_compute_size === 'nano' &&- compute.identifier === 'ci_nano'- ? availableOptions.find(- (option: ComputeAddonVariant) => option.identifier === 'ci_micro'- )?.price- : compute.price+ const price = isNanoBilledAsMicro+ ? availableOptions.find(+ (option: ComputeAddonVariant) => option.identifier === 'ci_micro'+ )?.price+ : compute.price- const cpuLabel = (() => {- const cpuCores = compute.meta?.cpu_cores- if (typeof cpuCores === 'number') {- return `${cpuCores}-core CPU`- }- if (cpuCores) {- return `${cpuCores} CPU`- }- return 'CPU'- })()+ const cpuLabel = (() => {+ const cpuCores = compute.meta?.cpu_cores+ if (typeof cpuCores === 'number') {+ return `${cpuCores}-core CPU`+ }+ if (cpuCores) {+ return `${cpuCores} CPU`+ }+ return 'CPU'+ })()- return (- <RadioGroupCardItem- showIndicator={false}- id={compute.identifier}- key={compute.identifier}- value={compute.identifier}- className={cn(- 'relative text-sm text-left flex flex-col gap-0 px-0 py-3 [&_label]:w-full group w-full h-[110px]',- lockedOption && 'opacity-50'- )}- disabled={disabled || lockedOption}- label={- <Tooltip>- <TooltipTrigger asChild>- <div>- {showUpgradeBadge && compute.identifier === 'ci_micro' && (- <div className="absolute -top-4 -right-3 text-violet-1100 flex items-center gap-1 bg-surface-75 py-0.5 px-2 rounded-full border border-violet-900">- <span>No additional charge</span>+ return (+ <RadioGroupCardItem+ showIndicator={false}+ id={compute.identifier}+ key={compute.identifier}+ value={compute.identifier}+ className={cn(+ 'relative text-sm text-left flex flex-col gap-0 px-0 py-3 [&_label]:w-full group w-full h-[110px]',+ lockedOption && 'opacity-50'+ )}+ disabled={disabled || lockedOption}+ label={+ <Tooltip>+ <TooltipTrigger asChild>+ <div>+ {showMicroUpgradeBadge && compute.identifier === 'ci_micro' && (+ <HoverCard openDelay={200}>+ <HoverCardTrigger asChild>+ <div+ className="absolute -top-4 -right-3 text-violet-1100 flex items-center gap-1 bg-surface-75 py-0.5 px-2 rounded-full border border-violet-900 cursor-default"+ onClick={(e) => e.stopPropagation()}+ onPointerDown={(e) => e.stopPropagation()}+ >+ <span>Free Upgrade</span></div>- )}- <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">- <ComputeBadge- className="inline-flex font-semibold"- infraComputeSize={compute.name as InfraInstanceSize}- />- <div className="flex items-center space-x-1">- {lockedOption ? (- <div className="bg border rounded-lg h-7 w-7 flex items-center justify-center">- <Lock size={14} />- </div>- ) : (- showComputePrice && (- <>- <span- className="text-foreground text-sm font-semibold"- translate="no"- >- ${price}- </span>- <span className="text-foreground-light translate-y-px">- {' '}- /{' '}- {compute.price_interval === 'monthly'- ? 'month'- : 'hour'}- </span>- </>- )- )}- </div>- </div>-- <div className="w-full">- <div className="px-3 text-sm flex flex-col gap-1">- <div className="text-foreground-light flex gap-2 items-center">- <Microchip- strokeWidth={1}- size={14}- className="text-foreground-lighter"- />- <span>- {compute.identifier === 'ci_nano' && 'Up to '}- {compute.meta?.memory_gb ?? 0} GB memory- </span>- </div>- <div className="text-foreground-light flex gap-2 items-center">- <CpuIcon- strokeWidth={1}- size={14}- className="text-foreground-lighter"- />- <span>{cpuLabel}</span>- </div>+ </HoverCardTrigger>+ <HoverCardContent+ side="top"+ align="end"+ className="w-72"+ onClick={(e) => e.stopPropagation()}+ >+ <p className="text-sm font-medium text-foreground">+ Upgrade to Micro Compute+ </p>+ <p className="text-sm text-foreground-light">+ This Project is already paying for Micro Compute. You can+ upgrade to Micro Compute at any time when convenient.+ </p>+ </HoverCardContent>+ </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">+ <ComputeBadge+ className="inline-flex font-semibold"+ infraComputeSize={compute.name as InfraInstanceSize}+ />+ <div className="flex items-center space-x-1">+ {lockedOption && (+ <div className="bg border rounded-lg h-7 w-7 flex items-center justify-center">+ <Lock size={14} /></div>- </div>+ )}+ {!lockedOption && showComputePrice && (+ <>+ <span+ className="text-foreground text-sm font-semibold"+ translate="no"+ >+ ${price}+ </span>+ <span className="text-foreground-light translate-y-px">+ {' '}+ /{' '}+ {compute.price_interval === 'monthly' ? 'month' : 'hour'}+ </span>+ </>+ )}</div></div>- </TooltipTrigger>- {lockedMicroDueToPITR && (- <TooltipContent side="bottom" className="w-64 text-center">- Project has PITR enabled which requires a minimum of Small- compute. Please{' '}- <InlineLink href="/project/_/settings/addons?panel=pitr">- disable PITR- </InlineLink>{' '}- first before selecting Micro- </TooltipContent>- )}- </Tooltip>- }- />- )- })}- {showAllSizes && (- <RadioGroupCardItem- id="larger-compute"- key="larger-compute"- showIndicator={false}- value="larger-compute"- onClick={(e) => e.preventDefault()}- className={cn(- 'relative text-sm text-left flex flex-col gap-0 px-0 py-3 [&_label]:w-full group w-full h-[110px]'- )}- label={- <SupportLink- queryParams={{- projectRef: ref,- category: SupportCategories.SALES_ENQUIRY,- subject: 'Enquiry about larger instance sizes',- }}- >- <div className="w-full flex flex-col gap-3 justify-between">- <div className="relative px-3 flex justify-between">- <ComputeBadge infraComputeSize=">16XL" />-- <div className="flex items-center space-x-1 opacity-50 ">- <span className="text-foreground-light text-sm">Contact Us</span>- </div>- </div>- <div className="w-full">- <div className="px-3 text-sm flex flex-col gap-1">- <div className="text-foreground-light flex gap-2 items-center">- <Microchip- strokeWidth={1}- size={14}- className="text-foreground-lighter"- />- <span>Custom memory</span>- </div>- <div className="text-foreground-light flex gap-2 items-center">- <CpuIcon- strokeWidth={1}- size={14}- className="text-foreground-lighter"- />- <span>Custom CPU</span>+ <div className="w-full">+ <div className="px-3 text-sm flex flex-col gap-1">+ <div className="text-foreground-light flex gap-2 items-center">+ <Microchip+ strokeWidth={1}+ size={14}+ className="text-foreground-lighter"+ />+ <span>+ {compute.identifier === 'ci_nano' && 'Up to '}+ {compute.meta?.memory_gb ?? 0} GB memory+ </span>+ </div>+ <div className="text-foreground-light flex gap-2 items-center">+ <CpuIcon+ strokeWidth={1}+ size={14}+ className="text-foreground-lighter"+ />+ <span>{cpuLabel}</span>+ </div></div></div></div></div>- </SupportLink>- }- />- )}- </>- )}- </div>- </div>+ </TooltipTrigger>+ {lockedMicroDueToPITR && (+ <TooltipContent side="bottom" className="w-64 text-center">+ Project has PITR enabled which requires a minimum of Small compute.+ Please{' '}+ <InlineLink href="/project/_/settings/addons?panel=pitr">+ disable PITR+ </InlineLink>{' '}+ first before selecting Micro+ </TooltipContent>+ )}+ </Tooltip>+ }+ />+ )+ })}+ <div+ className={cn(+ 'relative text-sm text-left flex flex-col gap-0 px-0 py-3 w-full h-[110px]',+ 'bg-overlay rounded-md border p-2 hover:border-foreground-muted'+ )}+ >+ <SupportLink+ queryParams={{+ projectRef: ref,+ category: SupportCategories.SALES_ENQUIRY,+ subject: 'Enquiry about larger instance sizes',+ }}+ >+ <div className="w-full flex flex-col gap-3 justify-between">+ <div className="relative px-3 flex justify-between">+ <ComputeBadge infraComputeSize=">16XL" />- {!isLoading && !addonsError && hasHiddenOptions && (- <Button- variant="default"- size="tiny"- className="mt-4"- aria-expanded={showAllSizes}- // Prevent collapsing when the selected size would become hidden- disabled={showAllSizes && selectedOptionIsHidden}- onClick={() => setShowAllSizes((prev) => !prev)}- icon={- <ChevronRight- size={14}- strokeWidth={1.5}- className={cn('transition-transform', showAllSizes && '-rotate-90')}- />- }- >- {showAllSizes ? 'Show fewer sizes' : 'Show all sizes'}- </Button>+ <div className="flex items-center space-x-1 opacity-50 ">+ <span className="text-foreground-light text-sm">Contact Us</span>+ </div>+ </div>+ <div className="w-full">+ <div className="px-3 text-sm flex flex-col gap-1">+ <div className="text-foreground-light flex gap-2 items-center">+ <Microchip+ strokeWidth={1}+ size={14}+ className="text-foreground-lighter"+ />+ <span>Custom memory</span>+ </div>+ <div className="text-foreground-light flex gap-2 items-center">+ <CpuIcon+ strokeWidth={1}+ size={14}+ className="text-foreground-lighter"+ />+ <span>Custom CPU</span>+ </div>+ </div>+ </div>+ </div>+ </SupportLink>+ </div>+ </>)}- </FormItemLayout>- </RadioGroupCard>+ </RadioGroupCard>+ </div>)}/>)diff --git a/apps/studio/components/interfaces/DiskManagement/fields/DiskSizeField.tsx b/apps/studio/components/interfaces/DiskManagement/fields/DiskSizeField.tsxindex df65d74b239..8b4342b999f 100644--- a/apps/studio/components/interfaces/DiskManagement/fields/DiskSizeField.tsx+++ b/apps/studio/components/interfaces/DiskManagement/fields/DiskSizeField.tsx@@ -1,7 +1,7 @@import { useParams } from 'common'import dayjs from 'dayjs'import { RotateCcw } from 'lucide-react'-import { UseFormReturn } from 'react-hook-form'+import { useFormState, useWatch, type UseFormReturn } from 'react-hook-form'import {Button,FormControl,@@ -15,33 +15,24 @@ import {import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'import { DiskStorageSchemaType } from '../DiskManagement.schema'-import { calculateDiskSizePrice } from '../DiskManagement.utils'-import { BillingChangeBadge } from '../ui/BillingChangeBadge'import { DiskType, PLAN_DETAILS } from '../ui/DiskManagement.constants'import { DiskManagementDiskSizeReadReplicas } from '../ui/DiskManagementReadReplicas'-import { DiskSpaceBar } from '../ui/DiskSpaceBar'import { DiskTypeRecommendationSection } from '../ui/DiskTypeRecommendationSection'import FormMessage from '../ui/FormMessage'-import { DocsButton } from '@/components/ui/DocsButton'import { useDiskAttributesQuery } from '@/data/config/disk-attributes-query'import { useDiskUtilizationQuery } from '@/data/config/disk-utilization-query'import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'-import { DOCS_URL, GB } from '@/lib/constants'+import { GB } from '@/lib/constants'type DiskSizeFieldProps = {form: UseFormReturn<DiskStorageSchemaType>disableInput: boolean- setAdvancedSettingsOpenState: (state: boolean) => void}-export function DiskSizeField({- form,- disableInput,- setAdvancedSettingsOpenState,-}: DiskSizeFieldProps) {+export function DiskSizeField({ form, disableInput }: DiskSizeFieldProps) {const { ref: projectRef } = useParams()- const { control, formState, setValue, trigger, getValues, resetField, watch } = form+ const { control, setValue, trigger, resetField } = formconst { data: org } = useSelectedOrganizationQuery()const { data: project } = useSelectedProjectQuery()@@ -70,8 +61,8 @@ export function DiskSizeField({dayjs.utc().diff(dayjs.utc(project?.inserted_at), 'minute') < 10 ||project?.status === 'COMING_UP'- const watchedStorageType = watch('storageType')- const watchedTotalSize = watch('totalSize')+ const watchedStorageType = useWatch({ control, name: 'storageType' })+ const watchedTotalSize = useWatch({ control, name: 'totalSize' })const planId = org?.plan.id ?? 'free'@@ -79,125 +70,115 @@ export function DiskSizeField({PLAN_DETAILS?.[planId as keyof typeof PLAN_DETAILS] ?? {}const includedDiskGB = includedDiskGBMeta[watchedStorageType]- const { defaultValues, dirtyFields, isDirty, errors } = formState- const diskSizePrice = calculateDiskSizePrice({- planId,- oldSize: defaultValues?.totalSize || 0,- oldStorageType: defaultValues?.storageType as DiskType,- newSize: getValues('totalSize'),- newStorageType: getValues('storageType') as DiskType,- })+ const { defaultValues, dirtyFields } = useFormState({ control })const mainDiskUsed = Math.round(((diskUtil?.metrics.fs_used_bytes ?? 0) / GB) * 100) / 100return (- <div id="disk-size" className="grid @xl:grid-cols-12 gap-5">- <div className="col-span-4">- <FormField- name="totalSize"- control={control}- render={({ field, fieldState: { isDirty } }) => (- <FormItemLayout label="Disk Size" layout="vertical" id={field.name}>- <FormControl className="max-w-32">- <InputGroup>- <FormInputGroupInput- type="number"- id={field.name}- {...field}- disabled={disableInput || isError}- onWheel={(e) => e.currentTarget.blur()}- onChange={(e) => {- setValue('totalSize', e.target.valueAsNumber, {- shouldDirty: true,- shouldValidate: true,- })+ <FormField+ name="totalSize"+ control={control}+ render={({ field, fieldState: { isDirty } }) => (+ <FormItemLayout+ label="Disk size"+ layout="flex-row-reverse"+ id={field.name}+ description={+ <div className="flex flex-col gap-y-3">+ {includedDiskGB > 0 && org?.plan.id && (+ <p>+ Your plan includes up to {includedDiskGB} GB of {watchedStorageType} storage.+ </p>+ )}++ <DiskTypeRecommendationSection+ form={form}+ actions={+ <Button+ variant="default"+ onClick={() => {+ setValue('storageType', 'io2', { shouldDirty: true })trigger('provisionedIOPS')- trigger('throughput')+ trigger('totalSize')}}- min={includedDiskGB}- />- <InputGroupAddon align="inline-end">- <InputGroupText>GB</InputGroupText>- {isDirty ? (- <InputGroupButton- type="button"- variant="default"- size="tiny"- className="px-2 text-foreground-light"- onClick={() => {- resetField('totalSize')- trigger('provisionedIOPS')- }}- title="Reset"- >- <RotateCcw className="h-4 w-4" aria-hidden="true" />- </InputGroupButton>- ) : null}- </InputGroupAddon>- </InputGroup>- </FormControl>- </FormItemLayout>- )}- />- <div className="flex flex-col gap-1">- <BillingChangeBadge- className="mt-1"- beforePrice={Number(diskSizePrice.oldPrice)}- afterPrice={Number(diskSizePrice.newPrice)}- show={isDirty && !errors.totalSize && diskSizePrice.oldPrice !== diskSizePrice.newPrice}- />- <span className="text-foreground-lighter text-sm">- {includedDiskGB > 0 &&- org?.plan.id &&- `Your plan includes up to ${includedDiskGB} GB of ${watchedStorageType} storage.`}-- <div className="mt-3">- <DocsButton abbrev={false} href={`${DOCS_URL}/guides/platform/database-size`} />+ >+ Change to High Performance SSD+ </Button>+ }+ />++ {isProjectNew ? (+ <FormMessage+ message="Disk size data is not available for ~10 minutes after project creation"+ type="error"+ />+ ) : (+ error && (+ <FormMessage message="Failed to load disk size data" type="error">+ {error?.message}+ </FormMessage>+ )+ )}++ <DiskManagementDiskSizeReadReplicas+ isDirty={+ dirtyFields.totalSize !== undefined ||+ watchedStorageType !== defaultValues?.storageType+ }+ totalSize={(defaultValues?.totalSize || 0) * 1.25}+ usedSize={mainDiskUsed}+ newTotalSize={watchedTotalSize * 1.25}+ oldStorageType={defaultValues?.storageType as DiskType}+ newStorageType={watchedStorageType as DiskType}+ /></div>- </span>- <DiskTypeRecommendationSection- form={form}- actions={- <Button- variant="default"- onClick={() => {- setValue('storageType', 'io2')+ }+ >+ <FormControl className="max-w-32">+ <InputGroup>+ <FormInputGroupInput+ type="number"+ id={field.name}+ {...field}+ disabled={disableInput || isError}+ onWheel={(e) => e.currentTarget.blur()}+ onChange={(e) => {+ // valueAsNumber is NaN while the input is empty, which would otherwise+ // propagate into the price calculations and the read replica sizing+ const value = e.target.valueAsNumber+ setValue('totalSize', Number.isNaN(value) ? 0 : value, {+ shouldDirty: true,+ shouldValidate: true,+ })trigger('provisionedIOPS')- trigger('totalSize')- setAdvancedSettingsOpenState(true)+ trigger('throughput')}}- >- Change to High Performance SSD- </Button>- }- />- </div>- </div>- <div className="col-span-8">- <DiskSpaceBar form={form} />-- {isProjectNew ? (- <FormMessage- message="Disk size data is not available for ~10 minutes after project creation"- type="error"- />- ) : (- error && (- <FormMessage message="Failed to load disk size data" type="error">- {error?.message}- </FormMessage>- )- )}-- <DiskManagementDiskSizeReadReplicas- isDirty={dirtyFields.totalSize !== undefined}- totalSize={(defaultValues?.totalSize || 0) * 1.25}- usedSize={mainDiskUsed}- newTotalSize={watchedTotalSize * 1.25}- oldStorageType={defaultValues?.storageType as DiskType}- newStorageType={getValues('storageType') as DiskType}- />- </div>- </div>+ min={includedDiskGB}+ />+ <InputGroupAddon align="inline-end">+ <InputGroupText>GB</InputGroupText>+ {isDirty ? (+ <InputGroupButton+ type="button"+ variant="default"+ size="tiny"+ className="px-2 text-foreground-light"+ aria-label="Reset disk size"+ onClick={() => {+ resetField('totalSize')+ trigger('provisionedIOPS')+ trigger('throughput')+ }}+ title="Reset"+ >+ <RotateCcw className="h-4 w-4" aria-hidden="true" />+ </InputGroupButton>+ ) : null}+ </InputGroupAddon>+ </InputGroup>+ </FormControl>+ </FormItemLayout>+ )}+ />)}diff --git a/apps/studio/components/interfaces/DiskManagement/fields/IOPSField.tsx b/apps/studio/components/interfaces/DiskManagement/fields/IOPSField.tsxindex 45453392660..71f0a40bed5 100644--- a/apps/studio/components/interfaces/DiskManagement/fields/IOPSField.tsx+++ b/apps/studio/components/interfaces/DiskManagement/fields/IOPSField.tsx@@ -13,10 +13,8 @@ import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'import { DiskStorageSchemaType } from '../DiskManagement.schema'import {calculateComputeSizeRequiredForIops,- calculateIOPSPrice,mapAddOnVariantIdToComputeSize,} from '../DiskManagement.utils'-import { BillingChangeBadge } from '../ui/BillingChangeBadge'import { ComputeSizeRecommendationSection } from '../ui/ComputeSizeRecommendationSection'import { DiskType, RESTRICTED_COMPUTE_FOR_IOPS_ON_GP3 } from '../ui/DiskManagement.constants'import { DiskManagementIOPSReadReplicas } from '../ui/DiskManagementReadReplicas'@@ -37,13 +35,6 @@ export function IOPSField({ form, disableInput }: IOPSFieldProps) {const { isError } = useDiskAttributesQuery({ projectRef })- const iopsPrice = calculateIOPSPrice({- oldStorageType: formState.defaultValues?.storageType as DiskType,- oldProvisionedIOPS: formState.defaultValues?.provisionedIOPS || 0,- newStorageType: getValues('storageType') as DiskType,- newProvisionedIOPS: getValues('provisionedIOPS'),- })-const disableIopsInput =RESTRICTED_COMPUTE_FOR_IOPS_ON_GP3.includes(watchedComputeSize) && watchedStorageType === 'gp3'@@ -55,7 +46,7 @@ export function IOPSField({ form, disableInput }: IOPSFieldProps) {const reccomendedComputeSize = calculateComputeSizeRequiredForIops(watchedIOPS)return (<FormItemLayout- layout="horizontal"+ layout="flex-row-reverse"label="IOPS"id={field.name}description={@@ -87,21 +78,7 @@ export function IOPSField({ form, disableInput }: IOPSFieldProps) {</span>}labelOptional={- <>- <BillingChangeBadge- show={- (watchedStorageType !== formState.defaultValues?.storageType ||- (watchedStorageType === 'gp3' &&- field.value !== formState.defaultValues?.provisionedIOPS)) &&- !formState.errors.provisionedIOPS &&- !disableIopsInput- }- beforePrice={Number(iopsPrice.oldPrice)}- afterPrice={Number(iopsPrice.newPrice)}- className="mb-2"- />- <p className="text-foreground-lighter">Input/output operations per second.</p>- </>+ <p className="text-foreground-lighter">Input/output operations per second.</p>}><FormControl className="max-w-32">diff --git a/apps/studio/components/interfaces/DiskManagement/fields/StorageTypeField.tsx b/apps/studio/components/interfaces/DiskManagement/fields/StorageTypeField.tsxindex dbd30360c2b..0c235d4f313 100644--- a/apps/studio/components/interfaces/DiskManagement/fields/StorageTypeField.tsx+++ b/apps/studio/components/interfaces/DiskManagement/fields/StorageTypeField.tsx@@ -45,7 +45,7 @@ export function StorageTypeField({ form, disableInput }: StorageTypeFieldProps)name="storageType"control={control}render={({ field }) => (- <FormItemLayout layout="horizontal" label="Storage type">+ <FormItemLayout layout="flex-row-reverse" label="Storage type" id={field.name}><Select{...field}onValueChange={async (e: DiskType) => {diff --git a/apps/studio/components/interfaces/DiskManagement/fields/ThroughputField.tsx b/apps/studio/components/interfaces/DiskManagement/fields/ThroughputField.tsxindex 518d86d7604..eb854c5872e 100644--- a/apps/studio/components/interfaces/DiskManagement/fields/ThroughputField.tsx+++ b/apps/studio/components/interfaces/DiskManagement/fields/ThroughputField.tsx@@ -13,8 +13,6 @@ import {import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'import { DiskStorageSchemaType } from '../DiskManagement.schema'-import { calculateThroughputPrice } from '../DiskManagement.utils'-import { BillingChangeBadge } from '../ui/BillingChangeBadge'import {DISK_LIMITS,DiskType,@@ -40,12 +38,6 @@ export function ThroughputField({ form, disableInput }: ThroughputFieldProps) {useDiskAttributesQuery({ projectRef })- const throughputPrice = calculateThroughputPrice({- storageType: form.getValues('storageType') as DiskType,- newThroughput: form.getValues('throughput') || 0,- oldThroughput: form.formState.defaultValues?.throughput || 0,- })-const disableIopsInput =RESTRICTED_COMPUTE_FOR_IOPS_ON_GP3.includes(watchedComputeSize) && watchedStorageType === 'gp3'@@ -84,7 +76,7 @@ export function ThroughputField({ form, disableInput }: ThroughputFieldProps) {render={({ field }) => (<FormItemLayoutlabel="Throughput"- layout="horizontal"+ layout="flex-row-reverse"description={<span className="flex flex-col gap-y-2"><p>Higher throughput suits applications with high data transfer needs.</p>@@ -100,21 +92,7 @@ export function ThroughputField({ form, disableInput }: ThroughputFieldProps) {</span>}labelOptional={- <>- <BillingChangeBadge- show={- formState.isDirty &&- formState.dirtyFields.throughput &&- !formState.errors.throughput- }- beforePrice={Number(throughputPrice.oldPrice)}- afterPrice={Number(throughputPrice.newPrice)}- className="mb-2"- />- <p className="text-foreground-lighter">- Amount of data read/written per second.- </p>- </>+ <p className="text-foreground-lighter">Amount of data read/written per second.</p>}><FormControl className="max-w-32">diff --git a/apps/studio/components/interfaces/DiskManagement/fields/useShowMicroUpgradeBadge.ts b/apps/studio/components/interfaces/DiskManagement/fields/useShowMicroUpgradeBadge.tsnew file mode 100644index 00000000000..62a066f533e--- /dev/null+++ b/apps/studio/components/interfaces/DiskManagement/fields/useShowMicroUpgradeBadge.ts@@ -0,0 +1,19 @@+import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'+import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'++export function useShowMicroUpgradeBadge() {+ const { data: project, isPending: isProjectLoading } = useSelectedProjectQuery()+ const { hasAccess: canUpdateCompute, isLoading: isEntitlementLoading } = useCheckEntitlements(+ 'instances.compute_update_available_sizes'+ )++ const projectComputeSize = project?.infra_compute_size ?? 'nano'+ const showMicroUpgradeBadge = canUpdateCompute && projectComputeSize === 'nano'++ return {+ project,+ isProjectLoading,+ isEntitlementLoading,+ showMicroUpgradeBadge,+ }+}diff --git a/apps/studio/components/interfaces/DiskManagement/ui/NoticeBar.tsx b/apps/studio/components/interfaces/DiskManagement/ui/NoticeBar.tsxnew file mode 100644index 00000000000..0ce27960ff8--- /dev/null+++ b/apps/studio/components/interfaces/DiskManagement/ui/NoticeBar.tsx@@ -0,0 +1,31 @@+import { AnimatePresence, motion } from 'framer-motion'+import { cn } from 'ui'+import { Admonition } from 'ui-patterns/Admonition'+import { type AdmonitionProps } from 'ui-patterns/Admonition/Admonition.types'++// Temporary animation shim while callers migrate to Admonition from ui-patterns.+interface NoticeBarProps extends AdmonitionProps {+ visible: boolean+}++export function NoticeBar({ visible, description, actions, ...props }: NoticeBarProps) {+ return (+ <AnimatePresence>+ {visible && (+ <motion.div+ initial={{ opacity: 0, height: 0, y: 4 }}+ animate={{ opacity: 1, height: 'auto', y: 0 }}+ exit={{ opacity: 0, height: 0, y: 4 }}+ transition={{ duration: 0.15 }}+ >+ <Admonition+ {...props}+ description={description}+ actions={actions}+ className={cn(props.className, 'mb-0')}+ />+ </motion.div>+ )}+ </AnimatePresence>+ )+}diff --git a/apps/studio/pages/project/[ref]/settings/compute-and-disk.tsx b/apps/studio/pages/project/[ref]/settings/compute-and-disk.tsxindex f87ba5397fe..34fca6e71da 100644--- a/apps/studio/pages/project/[ref]/settings/compute-and-disk.tsx+++ b/apps/studio/pages/project/[ref]/settings/compute-and-disk.tsx@@ -1,33 +1,37 @@+import {+ PageHeader,+ PageHeaderDescription,+ PageHeaderMeta,+ PageHeaderSummary,+ PageHeaderTitle,+} from 'ui-patterns/PageHeader'+import { DiskManagementForm } from '@/components/interfaces/DiskManagement/DiskManagementForm'import { DefaultLayout } from '@/components/layouts/DefaultLayout'import SettingsLayout from '@/components/layouts/ProjectSettingsLayout/SettingsLayout'-import {- ScaffoldContainer,- ScaffoldDescription,- ScaffoldHeader,- ScaffoldTitle,-} from '@/components/layouts/Scaffold'import type { NextPageWithLayout } from '@/types'-const AuthSettings: NextPageWithLayout = () => {+const ComputeAndDiskSettings: NextPageWithLayout = () => {return (<>- <ScaffoldContainer>- <ScaffoldHeader>- <ScaffoldTitle>Compute and Disk</ScaffoldTitle>- <ScaffoldDescription>- Configure the compute and disk settings for your project.- </ScaffoldDescription>- </ScaffoldHeader>- </ScaffoldContainer>+ <PageHeader size="default">+ <PageHeaderMeta>+ <PageHeaderSummary>+ <PageHeaderTitle>Compute and Disk</PageHeaderTitle>+ <PageHeaderDescription>+ Configure the compute and disk settings for your project.+ </PageHeaderDescription>+ </PageHeaderSummary>+ </PageHeaderMeta>+ </PageHeader><DiskManagementForm /></>)}-AuthSettings.getLayout = (page) => (+ComputeAndDiskSettings.getLayout = (page) => (<DefaultLayout><SettingsLayout title="Compute and Disk">{page}</SettingsLayout></DefaultLayout>)-export default AuthSettings+export default ComputeAndDiskSettings