The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Small updates to restoration UI
Joshen Limf2f8f9850ef5
diff --git a/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts b/studio/components/interfaces/Database/Backups/PITR/PITR.utils.tsindex edd9bb07aba..c92db4e78ac 100644--- a/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts+++ b/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts@@ -1,7 +1,16 @@+import { StripeProduct } from 'components/interfaces/Billing'import dayjs from 'dayjs'import { ALL_TIMEZONES } from './PITR.constants'import { Time, Timezone } from './PITR.types'+export const getPITRRetentionDuration = (addons: StripeProduct[]) => {+ const pitrAddon = addons.find((addon) => addon.supabase_prod_id.startsWith('addon_pitr'))+ if (!pitrAddon) return 0++ const daysString = pitrAddon.supabase_prod_id.split('_')[2]+ return Number(daysString.split('days')[0])+}+export const getDatesBetweenRange = (start: Date, end: Date) => {const arr = []for (let i, dt = new Date(start); dt <= new Date(end); dt.setDate(dt.getDate() + 1)) {diff --git a/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx b/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsxindex 124e9957b75..ddc71a6f9ef 100644--- a/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx+++ b/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx@@ -2,23 +2,28 @@ import Link from 'next/link'import { useRouter } from 'next/router'import { Button, IconCalendar } from 'ui'import { FormPanel } from 'components/ui/Forms'+import { useProjectSubscription } from 'hooks'+import { getPITRRetentionDuration } from './PITR.utils'const PITRNotice = ({}) => {const router = useRouter()const { ref } = router.query+ const { subscription } = useProjectSubscription(ref as string)+ const retentionPeriod = getPITRRetentionDuration(subscription?.addons ?? [])+return (<FormPaneldisabled={true}footer={<div className="flex items-center justify-between p-6"><span className="text-scale-1000 text-sm">- Recovery retention period can be increased - reach out to us!+ You can also increase your recovery retention period updating your PITR add-on</span>- <Link href={`/support/new?ref=${ref}&category=sales`}>+ <Link href={`/project/${ref}/settings/billing/update/pro`}><a><Button as="span" type="default">- Contact support+ Increase retention period</Button></a></Link>@@ -33,7 +38,8 @@ const PITRNotice = ({}) => {<p className="text-sm">Recovery retention period</p><p className="text-sm text-scale-1100">Database changes are logged every <span className="text-scale-1200">2 minutes</span>,- with a total recovery period of up to <span className="text-scale-1200">7 days</span>.+ with a total recovery period of up to{' '}+ <span className="text-brand-900">{retentionPeriod} days</span>.</p></div></div>diff --git a/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx b/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsxindex bc29216feaa..e22ecd0cd36 100644--- a/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx+++ b/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx@@ -23,6 +23,7 @@ import {getDatesBetweenRange,} from './PITR.utils'import { useRouter } from 'next/router'+import BackupsEmpty from '../BackupsEmpty'const DEFAULT_TIME = { h: 0, m: 0, s: 0 }@@ -75,6 +76,7 @@ const PITRSelection = ({}) => {const { earliestPhysicalBackupDateUnix, latestPhysicalBackupDateUnix } =backups?.configuration?.physicalBackupData ?? {}+ const hasNoBackupsAvailable = !earliestPhysicalBackupDateUnix || !latestPhysicalBackupDateUnixconst earliestAvailableBackup = dayjs(earliestPhysicalBackupDateUnix * 1000).tz(selectedTimezone?.utc[0])@@ -142,7 +144,7 @@ const PITRSelection = ({}) => {ui.setNotification({error,category: 'error',- message: `Failed to being restoration: ${error.message}`,+ message: `Failed to start restoration: ${error.message}`,})setIsRestoring(false)} else {@@ -160,163 +162,173 @@ const PITRSelection = ({}) => {title="Restore your database from a backup"description="Database changes are watched and recorded, so that you can restore your database to any point in time"/>- {!showConfiguration ? (- <PITRStatus- selectedTimezone={selectedTimezone}- onUpdateTimezone={setSelectedTimezone}- onSetConfiguration={() => setShowConfiguration(true)}- />+ {hasNoBackupsAvailable ? (+ <BackupsEmpty />) : (- <FormPanel- disabled={true}- footer={- <div className="flex items-center justify-end gap-3 p-6">- <Button type="default" onClick={onCancel}>- Cancel- </Button>- <Tooltip.Root delayDuration={0}>- <Tooltip.Trigger>- <Button- as="span"- type="warning"- disabled={isSelectedOutOfRange}- onClick={() => setShowConfirmation(true)}- >- Review restore details+ <>+ {!showConfiguration ? (+ <PITRStatus+ selectedTimezone={selectedTimezone}+ onUpdateTimezone={setSelectedTimezone}+ onSetConfiguration={() => setShowConfiguration(true)}+ />+ ) : (+ <FormPanel+ disabled={true}+ footer={+ <div className="flex items-center justify-end gap-3 p-6">+ <Button type="default" onClick={onCancel}>+ Cancel</Button>- </Tooltip.Trigger>- {isSelectedOutOfRange && (- <Tooltip.Content side="bottom">- <Tooltip.Arrow className="radix-tooltip-arrow" />- <div- className={[- 'bg-scale-100 rounded py-1 px-2 leading-none shadow',- 'border-scale-200 border w-48 text-center',- ].join(' ')}- >- <span className="text-scale-1200 text-xs">- Selected date is out of range where backups are available- </span>- </div>- </Tooltip.Content>- )}- </Tooltip.Root>- </div>- }- >- <div className="flex justify-between px-10 py-6 space-x-10">- <div className="w-1/3 space-y-2">- <DatePicker- inline- selected={selectedDate}- onChange={onUpdateDate}- dayClassName={() => 'cursor-pointer'}- minDate={earliestAvailableBackupFormatted}- maxDate={latestAvailableBackupFormatted}- highlightDates={availableDates}- renderCustomHeader={({- date,- decreaseMonth,- increaseMonth,- prevMonthButtonDisabled,- nextMonthButtonDisabled,- }) => (- <div className="flex items-center justify-between px-2 py-2">- <div className="flex w-full items-center justify-between">- <button- onClick={decreaseMonth}- disabled={prevMonthButtonDisabled}- type="button"- className={`+ <Tooltip.Root delayDuration={0}>+ <Tooltip.Trigger>+ <Button+ as="span"+ type="warning"+ disabled={isSelectedOutOfRange}+ onClick={() => setShowConfirmation(true)}+ >+ Review restore details+ </Button>+ </Tooltip.Trigger>+ {isSelectedOutOfRange && (+ <Tooltip.Content side="bottom">+ <Tooltip.Arrow className="radix-tooltip-arrow" />+ <div+ className={[+ 'bg-scale-100 rounded py-1 px-2 leading-none shadow',+ 'border-scale-200 border w-48 text-center',+ ].join(' ')}+ >+ <span className="text-scale-1200 text-xs">+ Selected date is out of range where backups are available+ </span>+ </div>+ </Tooltip.Content>+ )}+ </Tooltip.Root>+ </div>+ }+ >+ <div className="flex justify-between px-10 py-6 space-x-10">+ <div className="w-1/3 space-y-2">+ <DatePicker+ inline+ selected={selectedDate}+ onChange={onUpdateDate}+ dayClassName={() => 'cursor-pointer'}+ minDate={earliestAvailableBackupFormatted}+ maxDate={latestAvailableBackupFormatted}+ highlightDates={availableDates}+ renderCustomHeader={({+ date,+ decreaseMonth,+ increaseMonth,+ prevMonthButtonDisabled,+ nextMonthButtonDisabled,+ }) => (+ <div className="flex items-center justify-between px-2 py-2">+ <div className="flex w-full items-center justify-between">+ <button+ onClick={decreaseMonth}+ disabled={prevMonthButtonDisabled}+ type="button"+ className={`${prevMonthButtonDisabled && 'cursor-not-allowed opacity-50'}text-scale-1100 hover:text-scale-1200 focus:outline-none`}- >- <IconChevronLeft size={16} strokeWidth={2} />- </button>- <span className="text-scale-1100 text-sm">{format(date, 'MMMM yyyy')}</span>- <button- onClick={increaseMonth}- disabled={nextMonthButtonDisabled}- type="button"- className={`+ >+ <IconChevronLeft size={16} strokeWidth={2} />+ </button>+ <span className="text-scale-1100 text-sm">+ {format(date, 'MMMM yyyy')}+ </span>+ <button+ onClick={increaseMonth}+ disabled={nextMonthButtonDisabled}+ type="button"+ className={`${nextMonthButtonDisabled && 'cursor-not-allowed opacity-50'}text-scale-1100 hover:text-scale-1200 focus:outline-none`}- >- <IconChevronRight size={16} strokeWidth={2} />- </button>- </div>- </div>- )}- />- <div className="flex items-center space-x-2">- <div className="border w-4 h-4 border-scale-800 bg-brand-600" />- <p className="text-xs text-scale-1000">Point in time back up available</p>- </div>- </div>-- <div className="w-2/3">- {!selectedDate ? (- <div className="h-full flex items-center justify-center">- <div className="mx-2">- <InformationBox- defaultVisibility- hideCollapse- icon={<IconHelpCircle strokeWidth={2} />}- title="Select a date which you'd like to restore your database to"- />+ >+ <IconChevronRight size={16} strokeWidth={2} />+ </button>+ </div>+ </div>+ )}+ />+ <div className="flex items-center space-x-2">+ <div className="border w-4 h-4 border-scale-800 bg-brand-600" />+ <p className="text-xs text-scale-1000">Point in time back up available</p></div></div>- ) : (- <div className="space-y-8 py-2">- <div className="space-y-1">- <p className="text-sm text-scale-1100">Restore database to</p>- <p className="text-3xl">- <span>{dayjs(selectedDate).format('DD MMM YYYY')}</span>- <span>- , {formatNumberToTwoDigits(selectedTime.h)}:- {formatNumberToTwoDigits(selectedTime.m)}:- {formatNumberToTwoDigits(selectedTime.s)}- </span>- </p>- </div>- <div className="space-y-2">- <p className="text-sm text-scale-1100">Time of recovery</p>- <div className="w-[350px]">- <TimezoneSelection- hideLabel- dropdownWidth="w-[400px]"- selectedTimezone={selectedTimezone}- onSelectTimezone={setSelectedTimezone}- />++ <div className="w-2/3">+ {!selectedDate ? (+ <div className="h-full flex items-center justify-center">+ <div className="mx-2">+ <InformationBox+ defaultVisibility+ hideCollapse+ icon={<IconHelpCircle strokeWidth={2} />}+ title="Select a date which you'd like to restore your database to"+ />+ </div></div>- <TimeInput- defaultTime={selectedTime}- minimumTime={isSelectedOnEarliest ? earliestAvailableBackupTime : undefined}- maximumTime={isSelectedOnLatest ? latestAvailableBackupTime : undefined}- onChange={setSelectedTime}- />- <div className="!mt-4 space-y-1">- {isSelectedOnEarliest && (- <p className="text-sm text-scale-1000">- Earliest available backup on this date is at{' '}- {earliestAvailableBackup.format('HH:mm:ss')}- </p>- )}- {isSelectedOnLatest && (- <p className="text-sm text-scale-1000">- Latest available backup on this date is at{' '}- {latestAvailableBackup.format('HH:mm:ss')}+ ) : (+ <div className="space-y-8 py-2">+ <div className="space-y-1">+ <p className="text-sm text-scale-1100">Restore database to</p>+ <p className="text-3xl">+ <span>{dayjs(selectedDate).format('DD MMM YYYY')}</span>+ <span>+ , {formatNumberToTwoDigits(selectedTime.h)}:+ {formatNumberToTwoDigits(selectedTime.m)}:+ {formatNumberToTwoDigits(selectedTime.s)}+ </span></p>- )}+ </div>+ <div className="space-y-2">+ <p className="text-sm text-scale-1100">Time of recovery</p>+ <div className="w-[350px]">+ <TimezoneSelection+ hideLabel+ dropdownWidth="w-[400px]"+ selectedTimezone={selectedTimezone}+ onSelectTimezone={setSelectedTimezone}+ />+ </div>+ <TimeInput+ defaultTime={selectedTime}+ minimumTime={+ isSelectedOnEarliest ? earliestAvailableBackupTime : undefined+ }+ maximumTime={isSelectedOnLatest ? latestAvailableBackupTime : undefined}+ onChange={setSelectedTime}+ />+ <div className="!mt-4 space-y-1">+ {isSelectedOnEarliest && (+ <p className="text-sm text-scale-1000">+ Earliest available backup on this date is at{' '}+ {earliestAvailableBackup.format('HH:mm:ss')}+ </p>+ )}+ {isSelectedOnLatest && (+ <p className="text-sm text-scale-1000">+ Latest available backup on this date is at{' '}+ {latestAvailableBackup.format('HH:mm:ss')}+ </p>+ )}+ </div>+ </div></div>- </div>+ )}</div>- )}- </div>- </div>- </FormPanel>+ </div>+ </FormPanel>+ )}+ </>)}<Modalclosable@@ -357,7 +369,11 @@ const PITRSelection = ({}) => {</Modal.Content><Modal.Separator /><Modal.Content>- <Alert withIcon variant="warning" title="Warning: This action cannot be undone">+ <Alert+ withIcon+ variant="warning"+ title="This action cannot be undone, not cancelled once started"+ ><div className="space-y-3"><p>Any changes made to your database after this point in time will be lost. This@@ -370,7 +386,8 @@ const PITRSelection = ({}) => {<Modal.Content><p className="text-sm">Restores may take from a few minutes up to several hours depending on the size of your- database. During this period, your project will not be available.+ database. During this period, your project will not be available, until the+ restoration is completed.</p></Modal.Content></div>