mirror of
https://github.com/supabase/supabase.git
synced 2026-10-18 07:39:07 +03:00
* init * moar * moat * moar * add read replica bar * moar * Update DiskMangementPanelForm.tsx * added temp state mang to test * moar * Prepare react queries + data from API for disk mgt * moat * moat * moar * Update DiskMangementReviewAndSubmitDialog.tsx * badge updates * Hook up actual endpoints for E2E testing, but commented out for now for local dev * Hook up real data + clean up files and add tests * Update APi types * Hook up E2E and fix all validation logic * Only show new disk mgt UI for orb billing * Add note on RRs 25% more disk size * Add state to handle free plan for disk mgt * Update increase disk size CTA in reports/database * Fix file spelling errors * Address feedback * Fix missing framer motion package in ui * Address comments * Address feedabck * Minor fix * Use new disk util endpoint * Remove unused import * Address feedback * More addressing of feedback * Update pricing details for IO2 - no included disk size --------- Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
90 lines
2.9 KiB
TypeScript
90 lines
2.9 KiB
TypeScript
import { DISK_LIMITS, DISK_PRICING, DiskType, PLAN_DETAILS } from './DiskManagement.constants'
|
|
|
|
export const calculateDiskSizePrice = ({
|
|
planId,
|
|
oldSize,
|
|
oldStorageType,
|
|
newSize,
|
|
newStorageType,
|
|
}: {
|
|
planId: string
|
|
oldSize: number
|
|
oldStorageType: DiskType
|
|
newSize: number
|
|
newStorageType: DiskType
|
|
}) => {
|
|
const oldPricePerGiB = DISK_PRICING[oldStorageType]?.storage ?? 0
|
|
const newPricePerGiB = DISK_PRICING[newStorageType]?.storage ?? 0
|
|
const { includedDiskGB } = PLAN_DETAILS?.[planId as keyof typeof PLAN_DETAILS] ?? {}
|
|
|
|
const oldPrice = (Math.max(oldSize - includedDiskGB[oldStorageType], 0) * oldPricePerGiB).toFixed(
|
|
2
|
|
)
|
|
const newPrice = (Math.max(newSize - includedDiskGB[newStorageType], 0) * newPricePerGiB).toFixed(
|
|
2
|
|
)
|
|
|
|
return { oldPrice, newPrice }
|
|
}
|
|
|
|
export const calculateIOPSPrice = ({
|
|
oldStorageType,
|
|
oldProvisionedIOPS,
|
|
newStorageType,
|
|
newProvisionedIOPS,
|
|
}: {
|
|
oldStorageType: DiskType
|
|
oldProvisionedIOPS: number
|
|
newStorageType: DiskType
|
|
newProvisionedIOPS: number
|
|
}) => {
|
|
if (newStorageType === DiskType.GP3) {
|
|
const oldChargeableIOPS = Math.max(
|
|
0,
|
|
oldProvisionedIOPS - DISK_LIMITS[DiskType.GP3].includedIops
|
|
)
|
|
const newChargeableIOPS = Math.max(
|
|
0,
|
|
newProvisionedIOPS - DISK_LIMITS[DiskType.GP3].includedIops
|
|
)
|
|
const oldPrice = oldChargeableIOPS * DISK_PRICING[oldStorageType]?.iops ?? 0
|
|
const newPrice = newChargeableIOPS * DISK_PRICING[newStorageType]?.iops ?? 0
|
|
return { oldPrice: oldPrice.toFixed(2), newPrice: newPrice.toFixed(2) }
|
|
} else {
|
|
const oldPrice =
|
|
oldStorageType === 'gp3'
|
|
? (oldProvisionedIOPS - DISK_LIMITS[oldStorageType].includedIops) *
|
|
DISK_PRICING[oldStorageType].iops
|
|
: oldProvisionedIOPS * DISK_PRICING[oldStorageType]?.iops ?? 0
|
|
const newPrice = newProvisionedIOPS * DISK_PRICING[newStorageType]?.iops ?? 0
|
|
return { oldPrice: oldPrice.toFixed(2), newPrice: newPrice.toFixed(2) }
|
|
}
|
|
}
|
|
|
|
// This is only applicable for GP3 storage type, no need to consider IO2 at all
|
|
// Also assumes that disk size is > 400 GiB (separate requirement to update throughput)
|
|
export const calculateThroughputPrice = ({
|
|
storageType,
|
|
newThroughput,
|
|
oldThroughput,
|
|
}: {
|
|
storageType: DiskType
|
|
newThroughput: number
|
|
oldThroughput: number
|
|
}) => {
|
|
if (storageType === DiskType.GP3 && newThroughput) {
|
|
const oldChargeableThroughput = Math.max(
|
|
0,
|
|
oldThroughput - DISK_LIMITS[DiskType.GP3].includedThroughput
|
|
)
|
|
const newChargeableThroughput = Math.max(
|
|
0,
|
|
newThroughput - DISK_LIMITS[DiskType.GP3].includedThroughput
|
|
)
|
|
const oldPrice = (oldChargeableThroughput * DISK_PRICING[DiskType.GP3].throughput).toFixed(2)
|
|
const newPrice = (newChargeableThroughput * DISK_PRICING[DiskType.GP3].throughput).toFixed(2)
|
|
return { oldPrice, newPrice }
|
|
}
|
|
return { oldPrice: '0.00', newPrice: '0.00' }
|
|
}
|