The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(studio): revamp compute upgrade review dialog (#44639)
kemal.earth7d369571ce52
diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsxindex d9c268b58c0..156e48f8107 100644--- a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx@@ -23,7 +23,7 @@ import { CreateDiskStorageSchema, DiskStorageSchemaType } from './DiskManagementimport { DiskManagementMessage } from './DiskManagement.types'import { mapComputeSizeNameToAddonVariantId } from './DiskManagement.utils'import { DiskMangementRestartRequiredSection } from './DiskManagementRestartRequiredSection'-import { DiskManagementReviewAndSubmitDialog } from './DiskManagementReviewAndSubmitDialog'+import { DiskManagementReviewAndSubmitDialog } from './DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog'import { AutoScaleFields } from './fields/AutoScaleFields'import { ComputeSizeField } from './fields/ComputeSizeField'import { DiskSizeField } from './fields/DiskSizeField'diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog.tsx b/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog.tsxdeleted file mode 100644index 4478fced0ee..00000000000--- a/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog.tsx+++ /dev/null@@ -1,458 +0,0 @@-import { PermissionAction } from '@supabase/shared-types/out/constants'-import { ChevronRight } from 'lucide-react'-import { useMemo } from 'react'-import { UseFormReturn } from 'react-hook-form'-import {- Alert_Shadcn_,- AlertTitle_Shadcn_,- Badge,- Button,- ButtonProps,- Dialog,- DialogContent,- DialogDescription,- DialogFooter,- DialogHeader,- DialogSection,- DialogSectionSeparator,- DialogTitle,- DialogTrigger,- Table,- TableBody,- TableCell,- TableHead,- TableHeader,- TableRow,- WarningIcon,-} from 'ui'--import { DiskStorageSchemaType } from './DiskManagement.schema'-import { DiskManagementMessage } from './DiskManagement.types'-import {- calculateComputeSizePrice,- calculateDiskSizePrice,- calculateIOPSPrice,- calculateThroughputPrice,- getAvailableComputeOptions,- mapAddOnVariantIdToComputeSize,-} from './DiskManagement.utils'-import { DiskMangementRestartRequiredSection } from './DiskManagementRestartRequiredSection'-import { BillingChangeBadge } from './ui/BillingChangeBadge'-import { DISK_AUTOSCALE_CONFIG_DEFAULTS, DiskType } from './ui/DiskManagement.constants'-import { DiskMangementCoolDownSection } from './ui/DiskManagementCoolDownSection'-import { ButtonTooltip } from '@/components/ui/ButtonTooltip'-import { useProjectAddonsQuery } from '@/data/subscriptions/project-addons-query'-import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'-import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'-import {- useIsAwsNimbusCloudProvider,- useSelectedProjectQuery,-} from '@/hooks/misc/useSelectedProject'-import { formatCurrency } from '@/lib/helpers'--const TableHeaderRow = () => (- <TableRow>- <TableHead className="w-[140px] pl-5">Disk attribute</TableHead>- <TableHead className="text-right">-</TableHead>- <TableHead className="w-[100px]">Unit</TableHead>- <TableHead className="text-right pr-5">Price Change</TableHead>- </TableRow>-)--interface TableDataRowProps {- attribute: string- defaultValue: string | number- newValue: string | number- unit: string- beforePrice: number- afterPrice: number- hidePrice?: boolean- priceTooltip?: string- upgradeIncluded?: boolean-}--const TableDataRow = ({- attribute,- defaultValue,- newValue,- unit,- beforePrice,- afterPrice,- hidePrice = false,- priceTooltip,- upgradeIncluded = false,-}: TableDataRowProps) => (- <TableRow>- <TableCell className="pl-5">- <div className="flex flex-row gap-2 items-center">- <span>{attribute}</span>- </div>- </TableCell>- <TableCell className="text-right font-mono">- {defaultValue !== newValue ? (- <Badge variant="default" className="bg-alternative bg-opacity-100">- <div className="flex items-center gap-1">- <span className="text-xs font-mono text-foreground-muted">- {defaultValue.toString()}- </span>- <ChevronRight size={12} strokeWidth={2} className="text-foreground-muted" />- <span className="text-xs font-mono text-foreground">{newValue.toString()}</span>- </div>- </Badge>- ) : (- <span className="text-xs font-mono">- <span className="text-foreground-muted"></span>- {defaultValue}- </span>- )}- </TableCell>- <TableCell className="text-xs font-mono">{unit}</TableCell>- <TableCell className="text-right pr-5">- {!upgradeIncluded && hidePrice ? (- <span className="text-xs font-mono">-</span>- ) : beforePrice !== afterPrice || upgradeIncluded ? (- <BillingChangeBadge- show={true}- beforePrice={beforePrice}- afterPrice={afterPrice}- tooltip={priceTooltip}- free={upgradeIncluded}- />- ) : (- <span className="text-xs font-mono" translate="no">- {formatCurrency(beforePrice)}- </span>- )}- </TableCell>- </TableRow>-)--interface DiskSizeMeterProps {- loading: boolean- form: UseFormReturn<DiskStorageSchemaType>- numReplicas: number- isDialogOpen: boolean- disabled?: boolean- setIsDialogOpen: (isOpen: boolean) => void- onSubmit: (values: DiskStorageSchemaType) => Promise<void>-- buttonSize?: ButtonProps['size']- message?: DiskManagementMessage | null-}--export const DiskManagementReviewAndSubmitDialog = ({- isDialogOpen,- setIsDialogOpen,- disabled,- form,- numReplicas,- loading,- onSubmit,- message,- buttonSize = 'medium',-}: DiskSizeMeterProps) => {- const { data: project } = useSelectedProjectQuery()- const { data: org } = useSelectedOrganizationQuery()- const isAwsNimbus = useIsAwsNimbusCloudProvider()-- const isAwsK8sProject = project?.cloud_provider === 'AWS_K8S'-- const { formState, getValues } = form-- const { can: canUpdateDiskConfiguration } = useAsyncCheckPermissions(- PermissionAction.UPDATE,- 'projects',- {- resource: {- project_id: project?.id,- },- }- )-- /**- * Queries- * */- const {- data: addons,- // request deps in Form handle errors and loading- } = useProjectAddonsQuery({ projectRef: project?.ref })-- const planId = org?.plan.id ?? 'free'- const isDirty = !!Object.keys(form.formState.dirtyFields).length- const replicaTooltipText = `Price change includes primary database and ${numReplicas} replica${numReplicas > 1 ? 's' : ''}`-- const availableAddons = useMemo(() => {- return addons?.available_addons ?? []- }, [addons])- const availableOptions = useMemo(() => {- return getAvailableComputeOptions(availableAddons, project?.cloud_provider)- }, [availableAddons, project?.cloud_provider])-- const computeSizePrice = calculateComputeSizePrice({- availableOptions,- oldComputeSize: form.formState.defaultValues?.computeSize || 'ci_micro',- newComputeSize: form.getValues('computeSize'),- plan: org?.plan.id ?? 'free',- })- const diskSizePrice = calculateDiskSizePrice({- planId: planId,- oldSize: formState.defaultValues?.totalSize || 0,- oldStorageType: formState.defaultValues?.storageType as DiskType,- newSize: getValues('totalSize'),- newStorageType: getValues('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'),- numReplicas,- })- const throughputPrice = calculateThroughputPrice({- storageType: form.getValues('storageType') as DiskType,- newThroughput: form.getValues('throughput') || 0,- oldThroughput: form.formState.defaultValues?.throughput || 0,- numReplicas,- })-- const hasComputeChanges =- form.formState.defaultValues?.computeSize !== form.getValues('computeSize')- const hasTotalSizeChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.totalSize !== form.getValues('totalSize')- const hasStorageTypeChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.storageType !== form.getValues('storageType')- const hasThroughputChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.throughput !== form.getValues('throughput')- const hasIOPSChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.provisionedIOPS !== form.getValues('provisionedIOPS')-- const hasGrowthPercentChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.growthPercent !== form.getValues('growthPercent')- const hasMinIncrementChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.minIncrementGb !== form.getValues('minIncrementGb')- const hasMaxSizeChanges =- !isAwsK8sProject &&- !isAwsNimbus &&- form.formState.defaultValues?.maxSizeGb !== form.getValues('maxSizeGb')-- const hasDiskConfigChanges =- hasIOPSChanges ||- (hasThroughputChanges && form.getValues('storageType') === 'gp3') ||- hasTotalSizeChanges-- return (- <Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>- <DialogTrigger asChild>- <ButtonTooltip- size={buttonSize}- htmlType="submit"- type="primary"- onClick={async (e) => {- e.preventDefault()- const isValid = await form.trigger()- if (isValid) setIsDialogOpen(true)- }}- disabled={disabled || !isDirty}- tooltip={{- content: {- side: 'bottom',- text: !canUpdateDiskConfiguration- ? 'You need additional permissions to update disk configuration'- : disabled- ? 'Current form values are invalid'- : undefined,- },- }}- >- Review changes- </ButtonTooltip>- </DialogTrigger>- <DialogContent className="min-w-[620px]">- <DialogHeader>- <DialogTitle>Review changes</DialogTitle>- <DialogDescription>Changes will be applied shortly once confirmed.</DialogDescription>- </DialogHeader>- <DialogSectionSeparator />- {(hasComputeChanges || hasDiskConfigChanges) && (- <>- <div className="flex flex-col gap-2 p-5">- <DiskMangementRestartRequiredSection- visible={hasComputeChanges}- title="Resizing your Compute will trigger a project restart"- description="Project will restart automatically on confirmation."- />- <DiskMangementCoolDownSection visible={hasDiskConfigChanges} />- </div>- <DialogSectionSeparator />- </>- )}- <Table>- <TableHeader className="font-mono uppercase text-xs [&_th]:h-auto [&_th]:pb-2 [&_th]:pt-4">- <TableHeaderRow />- </TableHeader>- <TableBody className="[&_td]:py-0 [&_tr]:h-[50px] [&_tr]:border-dotted">- {hasComputeChanges && (- <TableDataRow- attribute="Compute size"- defaultValue={mapAddOnVariantIdToComputeSize(- form.formState.defaultValues?.computeSize ?? 'ci_nano'- )}- newValue={mapAddOnVariantIdToComputeSize(form.getValues('computeSize'))}- unit="-"- beforePrice={Number(computeSizePrice.oldPrice)}- afterPrice={Number(computeSizePrice.newPrice)}- upgradeIncluded={- org?.plan.id !== 'free' &&- project?.infra_compute_size === 'nano' &&- form.getValues('computeSize') === 'ci_micro'- }- />- )}- {hasStorageTypeChanges && (- <TableDataRow- hidePrice- attribute="Storage Type"- defaultValue={form.formState.defaultValues?.storageType ?? ''}- newValue={form.getValues('storageType')}- unit="-"- beforePrice={0}- afterPrice={0}- />- )}- {(hasIOPSChanges || hasStorageTypeChanges) && (- <TableDataRow- attribute="IOPS"- defaultValue={form.formState.defaultValues?.provisionedIOPS?.toLocaleString() ?? 0}- newValue={form.getValues('provisionedIOPS')?.toLocaleString()}- unit="IOPS"- beforePrice={Number(iopsPrice.oldPrice)}- afterPrice={Number(iopsPrice.newPrice)}- priceTooltip={numReplicas > 0 ? replicaTooltipText : undefined}- />- )}- {form.getValues('storageType') === 'gp3' && hasThroughputChanges && (- <TableDataRow- attribute="Throughput"- defaultValue={form.formState.defaultValues?.throughput?.toLocaleString() ?? 0}- newValue={form.getValues('throughput')?.toLocaleString() ?? 0}- unit="MB/s"- beforePrice={Number(throughputPrice.oldPrice)}- afterPrice={Number(throughputPrice.newPrice)}- priceTooltip={numReplicas > 0 ? replicaTooltipText : undefined}- />- )}- {(hasTotalSizeChanges || hasStorageTypeChanges) && (- <TableDataRow- attribute="Disk size"- defaultValue={form.formState.defaultValues?.totalSize?.toLocaleString() ?? 0}- newValue={form.getValues('totalSize')?.toLocaleString()}- unit="GB"- beforePrice={Number(diskSizePrice.oldPrice)}- afterPrice={Number(diskSizePrice.newPrice)}- priceTooltip={numReplicas > 0 ? replicaTooltipText : undefined}- />- )}- {hasGrowthPercentChanges && (- <TableDataRow- attribute="Growth percent"- defaultValue={- form.formState.defaultValues?.growthPercent ??- DISK_AUTOSCALE_CONFIG_DEFAULTS.growthPercent- }- newValue={- form.getValues('growthPercent') ?? DISK_AUTOSCALE_CONFIG_DEFAULTS.growthPercent- }- unit="%"- beforePrice={0}- afterPrice={0}- />- )}- {hasMinIncrementChanges && (- <TableDataRow- attribute="Min increment"- defaultValue={- form.formState.defaultValues?.minIncrementGb ??- DISK_AUTOSCALE_CONFIG_DEFAULTS.minIncrementSize- }- newValue={- form.getValues('minIncrementGb') ??- DISK_AUTOSCALE_CONFIG_DEFAULTS.minIncrementSize- }- unit="GB"- beforePrice={0}- afterPrice={0}- />- )}- {hasMaxSizeChanges && (- <TableDataRow- attribute="Max disk size"- defaultValue={- form.formState.defaultValues?.maxSizeGb?.toLocaleString() ??- DISK_AUTOSCALE_CONFIG_DEFAULTS.maxSizeGb- }- newValue={- form.getValues('maxSizeGb')?.toLocaleString() ??- DISK_AUTOSCALE_CONFIG_DEFAULTS.maxSizeGb- }- unit="GB"- beforePrice={0}- afterPrice={0}- />- )}- </TableBody>- </Table>-- {numReplicas > 0 && (- <div className="border-t px-4 py-2 text-sm text-foreground-lighter">- {replicaTooltipText}- </div>- )}-- <DialogFooter>- <Button block size="large" type="default" onClick={() => setIsDialogOpen(false)}>- Cancel- </Button>- <Button- block- type={'warning'}- size="large"- htmlType="submit"- loading={loading}- onClick={async () => {- await onSubmit(form.getValues())- }}- >- Confirm changes- </Button>- </DialogFooter>- {message && (- <>- <DialogSectionSeparator />- <DialogSection>- <Alert_Shadcn_- variant={message.type === 'error' ? 'destructive' : 'default'}- className=""- >- <WarningIcon />- <AlertTitle_Shadcn_>{message.message}</AlertTitle_Shadcn_>- </Alert_Shadcn_>- </DialogSection>- </>- )}- </DialogContent>- </Dialog>- )-}diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.components.tsx b/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.components.tsxnew file mode 100644index 00000000000..62a9f69a9ac--- /dev/null+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.components.tsx@@ -0,0 +1,34 @@+import { cn } from 'ui'++import { formatCurrency } from '@/lib/helpers'++export interface BreakdownRowProps {+ label: string+ description?: string+ children: React.ReactNode+}++export const BreakdownRow = ({ label, description, children }: BreakdownRowProps) => (+ <div className="flex items-start justify-between py-3 px-0 border-b border-dashed last:border-b-0">+ <div className="flex flex-col gap-0.5">+ <span className="text-sm text-foreground-light">{label}</span>+ {description && <span className="text-xs text-warning-600 max-w-72">{description}</span>}+ </div>+ {children}+ </div>+)++export const ValueChange = ({ from, to }: { from: string; to: string }) => (+ <span className="text-sm font-mono uppercase">+ <span className="text-foreground-lighter">{from}</span>+ <span className="text-foreground-lighter mx-2">→</span>+ <span className="text-foreground">{to}</span>+ </span>+)++export const PriceDelta = ({ delta }: { delta: number }) => (+ <span className={cn('text-xs', delta >= 0 ? 'text-brand' : 'text-destructive')}>+ {delta >= 0 ? `+${formatCurrency(delta)}` : `-${formatCurrency(Math.abs(delta))}`}{' '}+ <span className="text-foreground-lighter">per month</span>+ </span>+)diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.hooks.ts b/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.hooks.tsnew file mode 100644index 00000000000..9505d1d6cbb--- /dev/null+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.hooks.ts@@ -0,0 +1,186 @@+import { useMemo } from 'react'+import { UseFormReturn } from 'react-hook-form'++import { DiskStorageSchemaType } from '../DiskManagement.schema'+import {+ calculateComputeSizePrice,+ calculateDiskSizePrice,+ calculateIOPSPrice,+ calculateThroughputPrice,+ getAvailableComputeOptions,+ mapAddOnVariantIdToComputeSize,+} from '../DiskManagement.utils'+import { DiskType } from '../ui/DiskManagement.constants'+import { useProjectAddonsQuery } from '@/data/subscriptions/project-addons-query'+import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'+import {+ useIsAwsNimbusCloudProvider,+ useSelectedProjectQuery,+} from '@/hooks/misc/useSelectedProject'++export function useDiskManagementReviewChanges(+ form: UseFormReturn<DiskStorageSchemaType>,+ numReplicas: number+) {+ const { data: project } = useSelectedProjectQuery()+ const { data: org } = useSelectedOrganizationQuery()+ const isAwsNimbus = useIsAwsNimbusCloudProvider()+ const { data: addons } = useProjectAddonsQuery({ projectRef: project?.ref })++ const isAwsK8sProject = project?.cloud_provider === 'AWS_K8S'+ const planId = org?.plan.id ?? 'free'++ const availableAddons = useMemo(() => addons?.available_addons ?? [], [addons])+ const availableOptions = useMemo(+ () => getAvailableComputeOptions(availableAddons, project?.cloud_provider),+ [availableAddons, project?.cloud_provider]+ )++ // --- Prices ---++ const computeSizePrice = calculateComputeSizePrice({+ availableOptions,+ oldComputeSize: form.formState.defaultValues?.computeSize || 'ci_micro',+ newComputeSize: form.getValues('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,+ 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'),+ numReplicas,+ })+ const throughputPrice = calculateThroughputPrice({+ storageType: form.getValues('storageType') as DiskType,+ newThroughput: form.getValues('throughput') || 0,+ oldThroughput: form.formState.defaultValues?.throughput || 0,+ numReplicas,+ })++ const totalBeforePrice =+ Number(computeSizePrice.oldPrice) ++ Number(diskSizePrice.oldPrice) ++ Number(iopsPrice.oldPrice) ++ Number(throughputPrice.oldPrice)++ const totalAfterPrice =+ Number(computeSizePrice.newPrice) ++ Number(diskSizePrice.newPrice) ++ Number(iopsPrice.newPrice) ++ Number(throughputPrice.newPrice)++ // --- Change flags ---++ const hasComputeChanges =+ form.formState.defaultValues?.computeSize !== form.getValues('computeSize')++ const hasTotalSizeChanges =+ !isAwsK8sProject &&+ !isAwsNimbus &&+ form.formState.defaultValues?.totalSize !== form.getValues('totalSize')++ const hasStorageTypeChanges =+ !isAwsK8sProject &&+ !isAwsNimbus &&+ form.formState.defaultValues?.storageType !== form.getValues('storageType')++ const hasThroughputChanges =+ !isAwsK8sProject &&+ !isAwsNimbus &&+ form.formState.defaultValues?.throughput !== form.getValues('throughput')++ const hasIOPSChanges =+ !isAwsK8sProject &&+ !isAwsNimbus &&+ form.formState.defaultValues?.provisionedIOPS !== form.getValues('provisionedIOPS')++ const hasGrowthPercentChanges =+ !isAwsK8sProject &&+ !isAwsNimbus &&+ form.formState.defaultValues?.growthPercent !== form.getValues('growthPercent')++ const hasMinIncrementChanges =+ !isAwsK8sProject &&+ !isAwsNimbus &&+ form.formState.defaultValues?.minIncrementGb !== form.getValues('minIncrementGb')++ const hasMaxSizeChanges =+ !isAwsK8sProject &&+ !isAwsNimbus &&+ form.formState.defaultValues?.maxSizeGb !== form.getValues('maxSizeGb')++ // --- Derived predicates ---++ const storageTypeBefore = (form.formState.defaultValues?.storageType ?? '') as DiskType+ const storageTypeAfter = form.getValues('storageType') as DiskType++ // Show hero whenever any line-item price actually changes, not just compute+ const anyBillableDiskChange =+ Number(diskSizePrice.newPrice) !== Number(diskSizePrice.oldPrice) ||+ Number(iopsPrice.newPrice) !== Number(iopsPrice.oldPrice) ||+ Number(throughputPrice.newPrice) !== Number(throughputPrice.oldPrice)++ // Show cooldown warning whenever any disk attribute that enforces the 4-hour lock changes+ const anyDiskAttributeChange = hasIOPSChanges || hasStorageTypeChanges || hasTotalSizeChanges++ // Show throughput row whenever either the before or after storage type is GP3+ // (covers GP3→IO2 where the throughput charge drops to zero)+ const showThroughputRow =+ !isAwsK8sProject &&+ !isAwsNimbus &&+ (storageTypeBefore === 'gp3' || storageTypeAfter === 'gp3') &&+ (hasThroughputChanges || hasStorageTypeChanges)++ const hasAnyBreakdownRows =+ hasComputeChanges ||+ hasStorageTypeChanges ||+ hasIOPSChanges ||+ showThroughputRow ||+ hasTotalSizeChanges ||+ hasGrowthPercentChanges ||+ hasMinIncrementChanges ||+ hasMaxSizeChanges++ // --- Labels ---++ const oldComputeLabel = mapAddOnVariantIdToComputeSize(+ form.formState.defaultValues?.computeSize ?? 'ci_nano'+ )+ const newComputeLabel = mapAddOnVariantIdToComputeSize(form.getValues('computeSize'))++ return {+ // prices+ computeSizePrice,+ diskSizePrice,+ iopsPrice,+ throughputPrice,+ totalBeforePrice,+ totalAfterPrice,+ // change flags+ hasComputeChanges,+ hasTotalSizeChanges,+ hasStorageTypeChanges,+ hasThroughputChanges,+ hasIOPSChanges,+ hasGrowthPercentChanges,+ hasMinIncrementChanges,+ hasMaxSizeChanges,+ // derived predicates+ anyBillableDiskChange,+ anyDiskAttributeChange,+ showThroughputRow,+ hasAnyBreakdownRows,+ // labels+ oldComputeLabel,+ newComputeLabel,+ }+}diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.tsx b/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.tsxnew file mode 100644index 00000000000..dadd76bfd5a--- /dev/null+++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementReviewAndSubmitDialog/DiskManagementReviewAndSubmitDialog.tsx@@ -0,0 +1,299 @@+import { PermissionAction } from '@supabase/shared-types/out/constants'+import { ArrowRight } from 'lucide-react'+import { UseFormReturn } from 'react-hook-form'+import {+ Alert_Shadcn_,+ AlertTitle_Shadcn_,+ Button,+ ButtonProps,+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogSection,+ DialogSectionSeparator,+ DialogTitle,+ DialogTrigger,+ WarningIcon,+} from 'ui'++import { DiskStorageSchemaType } from '../DiskManagement.schema'+import { DiskManagementMessage } from '../DiskManagement.types'+import { DISK_AUTOSCALE_CONFIG_DEFAULTS } from '../ui/DiskManagement.constants'+import {+ BreakdownRow,+ PriceDelta,+ ValueChange,+} from './DiskManagementReviewAndSubmitDialog.components'+import { useDiskManagementReviewChanges } from './DiskManagementReviewAndSubmitDialog.hooks'+import { ButtonTooltip } from '@/components/ui/ButtonTooltip'+import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'+import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'+import { formatCurrency } from '@/lib/helpers'++interface DiskManagementReviewAndSubmitDialogProps {+ loading: boolean+ form: UseFormReturn<DiskStorageSchemaType>+ numReplicas: number+ isDialogOpen: boolean+ disabled?: boolean+ setIsDialogOpen: (isOpen: boolean) => void+ onSubmit: (values: DiskStorageSchemaType) => Promise<void>+ buttonSize?: ButtonProps['size']+ message?: DiskManagementMessage | null+}++export const DiskManagementReviewAndSubmitDialog = ({+ isDialogOpen,+ setIsDialogOpen,+ disabled,+ form,+ numReplicas,+ loading,+ onSubmit,+ message,+ buttonSize = 'medium',+}: DiskManagementReviewAndSubmitDialogProps) => {+ const { data: project } = useSelectedProjectQuery()++ const { can: canUpdateDiskConfiguration } = useAsyncCheckPermissions(+ PermissionAction.UPDATE,+ 'projects',+ { resource: { project_id: project?.id } }+ )++ const isDirty = !!Object.keys(form.formState.dirtyFields).length++ const {+ computeSizePrice,+ diskSizePrice,+ iopsPrice,+ throughputPrice,+ totalBeforePrice,+ totalAfterPrice,+ hasComputeChanges,+ hasTotalSizeChanges,+ hasStorageTypeChanges,+ hasIOPSChanges,+ hasGrowthPercentChanges,+ hasMinIncrementChanges,+ hasMaxSizeChanges,+ anyBillableDiskChange,+ anyDiskAttributeChange,+ showThroughputRow,+ hasAnyBreakdownRows,+ oldComputeLabel,+ newComputeLabel,+ } = useDiskManagementReviewChanges(form, numReplicas)++ return (+ <Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>+ <DialogTrigger asChild>+ <ButtonTooltip+ size={buttonSize}+ htmlType="submit"+ type="primary"+ onClick={async (e) => {+ e.preventDefault()+ const isValid = await form.trigger()+ if (isValid) setIsDialogOpen(true)+ }}+ disabled={disabled || !isDirty}+ tooltip={{+ content: {+ side: 'bottom',+ text: !canUpdateDiskConfiguration+ ? 'You need additional permissions to update disk configuration'+ : disabled+ ? 'Current form values are invalid'+ : undefined,+ },+ }}+ >+ Review changes+ </ButtonTooltip>+ </DialogTrigger>+ <DialogContent className="min-w-[560px] p-0 gap-0 overflow-hidden">+ <DialogHeader className="px-5 py-4">+ <DialogTitle>Review changes</DialogTitle>+ <DialogDescription>Changes will be applied shortly after confirmation.</DialogDescription>+ </DialogHeader>+ <DialogSectionSeparator />++ {(hasComputeChanges || anyBillableDiskChange) && (+ <>+ <div className="relative flex border-b">+ <div className="flex-1 flex flex-col items-center gap-2 py-6 px-4 border-r bg-gradient-to-t from-[hsl(var(--background-surface-100))] to-transparent">+ <span className="text-xs uppercase tracking-widest font-mono text-foreground-lighter">+ Before+ </span>+ <span className="text-3xl text-foreground-light tabular-nums" translate="no">+ {formatCurrency(totalBeforePrice)}+ </span>+ <span className="text-xs uppercase tracking-widest font-mono text-foreground-lighter">+ per month+ </span>+ </div>++ <div className="animate-badge-pulse absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-9 h-9 rounded-full bg-dash-sidebar border border-brand-500 flex items-center justify-center z-10 overflow-hidden">+ <span className="absolute inset-0 bg-brand bg-opacity-10 rounded-full" />+ <span className="animate-badge-shimmer pointer-events-none absolute inset-0 bg-gradient-to-br from-transparent via-brand/20 to-transparent blur-md" />+ <ArrowRight size={16} className="text-brand-600 relative z-10" strokeWidth={2.5} />+ </div>++ <div className="flex-1 flex flex-col items-center gap-2 py-6 px-4 bg-gradient-to-t from-[hsl(var(--background-surface-100))] to-transparent">+ <span className="text-xs uppercase tracking-widest font-mono text-foreground-lighter">+ After+ </span>+ <span className="text-3xl text-foreground tabular-nums" translate="no">+ {formatCurrency(totalAfterPrice)}+ </span>+ <span className="text-xs uppercase tracking-widest font-mono text-foreground-lighter">+ per month+ </span>+ </div>+ </div>+ </>+ )}++ {hasAnyBreakdownRows && (+ <div className="py-0.5 px-5">+ {hasComputeChanges && (+ <BreakdownRow+ label="Compute size"+ description="Project will restart automatically on confirmation."+ >+ <div className="flex flex-col items-end gap-0.5">+ <ValueChange from={oldComputeLabel} to={newComputeLabel} />+ <PriceDelta+ delta={Number(computeSizePrice.newPrice) - Number(computeSizePrice.oldPrice)}+ />+ </div>+ </BreakdownRow>+ )}+ {hasStorageTypeChanges && (+ <BreakdownRow label="Storage type">+ <ValueChange+ from={(form.formState.defaultValues?.storageType ?? '').toUpperCase()}+ to={form.getValues('storageType').toUpperCase()}+ />+ </BreakdownRow>+ )}+ {(hasIOPSChanges || hasStorageTypeChanges) && (+ <BreakdownRow+ label="IOPS"+ description={+ anyDiskAttributeChange && !hasTotalSizeChanges && !hasStorageTypeChanges+ ? 'For 4 hours after changes you will not be able to modify disk attributes.'+ : undefined+ }+ >+ <div className="flex flex-col items-end gap-0.5">+ <ValueChange+ from={(form.formState.defaultValues?.provisionedIOPS ?? 0).toLocaleString()}+ to={(form.getValues('provisionedIOPS') ?? 0).toLocaleString()}+ />+ <PriceDelta delta={Number(iopsPrice.newPrice) - Number(iopsPrice.oldPrice)} />+ </div>+ </BreakdownRow>+ )}+ {showThroughputRow && (+ <BreakdownRow label="Throughput">+ <div className="flex flex-col items-end gap-0.5">+ <ValueChange+ from={`${(form.formState.defaultValues?.throughput ?? 0).toLocaleString()} MB/s`}+ to={`${(form.getValues('throughput') ?? 0).toLocaleString()} MB/s`}+ />+ <PriceDelta+ delta={Number(throughputPrice.newPrice) - Number(throughputPrice.oldPrice)}+ />+ </div>+ </BreakdownRow>+ )}+ {(hasTotalSizeChanges || hasStorageTypeChanges) && (+ <BreakdownRow+ label="Disk size"+ description="For 4 hours after changes you will not be able to modify disk attributes."+ >+ <div className="flex flex-col items-end gap-0.5">+ <ValueChange+ from={`${(form.formState.defaultValues?.totalSize ?? 0).toLocaleString()} GB`}+ to={`${(form.getValues('totalSize') ?? 0).toLocaleString()} GB`}+ />+ <PriceDelta+ delta={Number(diskSizePrice.newPrice) - Number(diskSizePrice.oldPrice)}+ />+ </div>+ </BreakdownRow>+ )}+ {hasGrowthPercentChanges && (+ <BreakdownRow label="Growth percent">+ <ValueChange+ from={`${form.formState.defaultValues?.growthPercent ?? DISK_AUTOSCALE_CONFIG_DEFAULTS.growthPercent}%`}+ to={`${form.getValues('growthPercent') ?? DISK_AUTOSCALE_CONFIG_DEFAULTS.growthPercent}%`}+ />+ </BreakdownRow>+ )}+ {hasMinIncrementChanges && (+ <BreakdownRow label="Min increment">+ <ValueChange+ from={`${form.formState.defaultValues?.minIncrementGb ?? DISK_AUTOSCALE_CONFIG_DEFAULTS.minIncrementSize} GB`}+ to={`${form.getValues('minIncrementGb') ?? DISK_AUTOSCALE_CONFIG_DEFAULTS.minIncrementSize} GB`}+ />+ </BreakdownRow>+ )}+ {hasMaxSizeChanges && (+ <BreakdownRow label="Max disk size">+ <ValueChange+ from={(+ form.formState.defaultValues?.maxSizeGb ??+ DISK_AUTOSCALE_CONFIG_DEFAULTS.maxSizeGb+ ).toLocaleString()}+ to={(+ form.getValues('maxSizeGb') ?? DISK_AUTOSCALE_CONFIG_DEFAULTS.maxSizeGb+ ).toLocaleString()}+ />+ </BreakdownRow>+ )}+ {numReplicas > 0 && (+ <div className="py-2 text-xs text-foreground-muted">+ Price change includes primary database and {numReplicas} replica+ {numReplicas > 1 ? 's' : ''}+ </div>+ )}+ </div>+ )}++ <DialogFooter className="px-5 py-4">+ <Button block size="large" type="default" onClick={() => setIsDialogOpen(false)}>+ Cancel+ </Button>+ <Button+ block+ type="primary"+ size="large"+ htmlType="submit"+ loading={loading}+ onClick={async () => {+ await onSubmit(form.getValues())+ }}+ >+ Confirm changes+ </Button>+ </DialogFooter>+ {message && (+ <>+ <DialogSectionSeparator />+ <DialogSection>+ <Alert_Shadcn_ variant={message.type === 'error' ? 'destructive' : 'default'}>+ <WarningIcon />+ <AlertTitle_Shadcn_>{message.message}</AlertTitle_Shadcn_>+ </Alert_Shadcn_>+ </DialogSection>+ </>+ )}+ </DialogContent>+ </Dialog>+ )+}