Files
supabase/apps/studio/components/interfaces/DiskManagement/ui/DiskManagementReadReplicas.tsx
Jonathan Summers-MuirandJoshen Lim 9f420962e1 Feat/compute and disk (#30068)
* inited. added disk config to a new page

* add instances

* move moar

* moved things around. billing badges updated. compute added

* tidy

* new components

* form now dynamically updating itself

* updated compute form. moved warning panels. added collapsible for advanced options

* review dialog now only showing what is relevant

* Update DiskManagementForm.tsx

* compute sizes now a reccomendation

* fix old form

* started adding flags

* removed unused code. fixed issue with IOPS price showing on smaller compute

* moar clearning

* IOPS logic wrong way round

* type fixes

* start adding better error handling

* TIDY

* moved everything to own file

* tidy

* fix hydration issue

* moved some components around

* clean up

* inline errors

* update form message

* Update DiskManagementForm.tsx

* error fields fixed. some formatting issues. nano added as an option

* fix constants

* add some plan restrictions

* moar

* units updated. labels updated

* Update DiskManagement.schema.ts

* fix a ton of type issues

* text udpates

* add panel to suggest switching to io2

* more notice board stuff

* number formatting. moved a file

* Update DiskManagementForm.tsx

* remove console logs

* upgrade comms. more type fixes

* add empty states for the old areas

* more links

* updated some label issues

* hide labels when chart is active

* Update DiskManagement.utils.ts

* Delete next-env.d.ts

* Update DiskManagementForm.tsx

* Update DiskManagement.schema.ts

* text updates

* Update DiskManagement.constants.tsx

* Update next-env.d.ts

* Update next-env.d.ts

* Small clean uop

* Clean up empty files

* Clean up spelling

* Clean up more

* Fix typo in file name

* Clean up import statements

* Update DiskManagementForm.tsx

* fix issues

* Update ProjectLayout.tsx

* Remove unused import

* Fix

* Address nit

* Update database.tsx

* remove supress toast

* Update DiskManagement.schema.ts

* Update database.tsx

* change upgrade comms

* Update DiskManagementPanelForm.tsx

* fixes

* fix button size on old form

* Update DiskManagementForm.tsx

* Update StorageTypeField.tsx

* update labels on compute

* dont show banner when infra is FLY

* update comms. hide disk config for FLY

* Fix TS

* Last round of clean upo

* fix message state

* fix message

* Fix TS

* Update DiskManagement.utils.ts

* fix errors

* Update BillingChangeBadge.tsx

* fixed some label issues

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-11-04 09:05:37 +00:00

250 lines
8.8 KiB
TypeScript

import { AnimatePresence, motion } from 'framer-motion'
import { useParams } from 'common'
import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
import { formatDatabaseID } from 'data/read-replicas/replicas.utils'
import {
Alert_Shadcn_ as Alert,
AlertDescription_Shadcn_ as AlertDescription,
AlertTitle_Shadcn_ as AlertTitle,
InfoIcon,
} from 'ui'
import { BillingChangeBadge } from './BillingChangeBadge'
import { DISK_LIMITS, DISK_PRICING, DiskType } from './DiskManagement.constants'
interface DiskManagementDiskSizeReadReplicasProps {
isDirty: boolean
totalSize: number
usedSize: number
newTotalSize: number
oldStorageType: DiskType
newStorageType: DiskType
}
export const DiskManagementDiskSizeReadReplicas = ({
isDirty,
totalSize,
usedSize,
newTotalSize,
oldStorageType,
newStorageType,
}: DiskManagementDiskSizeReadReplicasProps) => {
const { ref: projectRef } = useParams()
const { data: databases } = useReadReplicasQuery({ projectRef })
const readReplicas = (databases ?? []).filter((db) => db.identifier !== projectRef)
const beforePrice = totalSize * DISK_PRICING[oldStorageType]?.storage ?? 0
const afterPrice = newTotalSize * DISK_PRICING[newStorageType]?.storage ?? 0
if (readReplicas.length === 0) return null
return (
<>
<AnimatePresence>
{isDirty && (
<motion.div
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: 1, height: 'auto' }}
exit={{ opacity: 0, height: 0 }}
transition={{ duration: 0.3 }}
>
<Alert variant="default" className="bg-transparent">
<InfoIcon />
<AlertTitle>
Read replicas are provisioned with extra 25% disk size to account for WAL files
</AlertTitle>
<AlertDescription>
Each replica will have a disk size of {newTotalSize}GB, and are billed separately
<ul className="list-disc pl-4 my-3 flex flex-col gap-2">
{readReplicas.map((replica, index) => (
<li key={index} className="marker:text-foreground-light">
<div className="flex items-center gap-2">
<span>
ID: {formatDatabaseID(replica.identifier)} ({replica.region}):
</span>
<BillingChangeBadge
show
beforePrice={beforePrice}
afterPrice={afterPrice}
/>
</div>
</li>
))}
</ul>
</AlertDescription>
</Alert>
</motion.div>
)}
</AnimatePresence>
{/* Hide for now until we have the utilization for each RR specifically */}
{/* <Collapsible open={isOpen} onOpenChange={setIsOpen}>
<CollapsibleTrigger asChild>
<div className="flex items-center cursor-pointer rounded gap-2 mt-3 text-foreground-light hover:text-foreground data-[state=open]:text-foreground group">
<h3 className="text-sm">Read replica disk size information</h3>
<ChevronDown
className={`h-4 w-4 transition-transform duration-200 group-data-[state=open]:transform group-data-[state=open]:rotate-180 group-data-[state=open]:text-foreground`}
/>
</div>
</CollapsibleTrigger>
<AnimatePresence initial={false}>
{isOpen && (
<motion.div
key="content"
initial="collapsed"
animate="open"
exit="collapsed"
variants={{
open: { opacity: 1, height: 'auto' },
collapsed: { opacity: 0, height: 0 },
}}
transition={{ duration: 0.3, ease: [0.04, 0.62, 0.23, 0.98] }}
>
<CollapsibleContent className="pt-3">
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.2 }}
>
<p className="flex flex-col gap-y-1 text-sm text-foreground-light mb-3">
<span className="text-foreground-lighter">
Read replicas have 25% more disk size than the primary database to account for
WAL files{' '}
</span>
</p>
<DiskSpaceBar
showNewBar={isDirty}
totalSize={totalSize}
usedSize={usedSize}
newTotalSize={newTotalSize}
/>
</motion.div>
</CollapsibleContent>
</motion.div>
)}
</AnimatePresence>
</Collapsible> */}
</>
)
}
export const DiskManagementIOPSReadReplicas = ({
isDirty,
oldIOPS,
newIOPS,
oldStorageType,
newStorageType,
}: {
isDirty: boolean
oldIOPS: number
newIOPS: number
oldStorageType: DiskType
newStorageType: DiskType
}) => {
const { ref: projectRef } = useParams()
const { data: databases } = useReadReplicasQuery({ projectRef })
const readReplicas = (databases ?? []).filter((db) => db.identifier !== projectRef)
const beforePrice =
(oldIOPS - DISK_LIMITS[oldStorageType]?.includedIops) * DISK_PRICING[oldStorageType]?.iops ?? 0
const afterPrice =
(newIOPS - DISK_LIMITS[newStorageType]?.includedIops) * DISK_PRICING[newStorageType]?.iops ?? 0
if (readReplicas.length === 0) return null
return (
<AnimatePresence initial={false}>
{isDirty && (
<motion.div
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: 1, height: 'auto' }}
exit={{ opacity: 0, height: 0 }}
transition={{ duration: 0.3 }}
>
<Alert variant="default" className="bg-transparent">
<InfoIcon />
<AlertTitle>Read replica IOPS will also be updated to the same value</AlertTitle>
<AlertDescription>
<ul className="list-disc pl-4 my-3 flex flex-col gap-2">
{readReplicas.map((replica, index) => (
<li key={index} className="marker:text-foreground-light">
<div className="flex items-center gap-2">
<span>
ID: {formatDatabaseID(replica.identifier)} ({replica.region}):
</span>
<BillingChangeBadge show beforePrice={beforePrice} afterPrice={afterPrice} />
</div>
</li>
))}
</ul>
</AlertDescription>
</Alert>
</motion.div>
)}
</AnimatePresence>
)
}
export const DiskManagementThroughputReadReplicas = ({
isDirty,
oldThroughput,
newThroughput,
oldStorageType,
newStorageType,
}: {
isDirty: boolean
oldThroughput: number
newThroughput: number
oldStorageType: DiskType
newStorageType: DiskType
}) => {
const { ref: projectRef } = useParams()
const { data: databases } = useReadReplicasQuery({ projectRef })
const readReplicas = (databases ?? []).filter((db) => db.identifier !== projectRef)
const beforePrice =
oldStorageType === DiskType.GP3
? (oldThroughput - DISK_LIMITS[oldStorageType].includedThroughput) *
DISK_PRICING[oldStorageType]?.throughput ?? 0
: 0
const afterPrice =
newStorageType === DiskType.GP3
? (newThroughput - DISK_LIMITS[newStorageType].includedThroughput) *
DISK_PRICING[newStorageType]?.throughput ?? 0
: 0
if (readReplicas.length === 0) return null
return (
<AnimatePresence initial={false}>
{isDirty && (
<motion.div
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: 1, height: 'auto' }}
exit={{ opacity: 0, height: 0 }}
transition={{ duration: 0.3 }}
>
<Alert variant="default" className="bg-transparent">
<InfoIcon />
<AlertTitle>Read replica throughput will also be updated to the same value</AlertTitle>
<AlertDescription>
<ul className="list-disc pl-4 my-3 flex flex-col gap-2">
{readReplicas.map((replica, index) => (
<li key={index} className="marker:text-foreground-light">
<div className="flex items-center gap-2">
<span>
ID: {formatDatabaseID(replica.identifier)} ({replica.region}):
</span>
<BillingChangeBadge show beforePrice={beforePrice} afterPrice={afterPrice} />
</div>
</li>
))}
</ul>
</AlertDescription>
</Alert>
</motion.div>
)}
</AnimatePresence>
)
}