Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Rework UI for PITR backups

Joshen Lim24c810fe94cd
diff --git a/studio/components/interfaces/Database/Backups/PITR/PITR.types.ts b/studio/components/interfaces/Database/Backups/PITR/PITR.types.ts
index 7b7d4955df9..7787003f9b4 100644
--- a/studio/components/interfaces/Database/Backups/PITR/PITR.types.ts
+++ b/studio/components/interfaces/Database/Backups/PITR/PITR.types.ts
@@ -8,7 +8,7 @@ export interface Timezone {
}
export interface Time {
- h: string
- m: string
- s: string
+ h: number
+ m: number
+ s: number
}
diff --git a/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts b/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts
index 57477369ac8..e61b19f861b 100644
--- a/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts
+++ b/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts
@@ -1,14 +1,23 @@
import dayjs from 'dayjs'
import { ALL_TIMEZONES } from './PITR.constants'
-import { Timezone } from './PITR.types'
+import { Time, Timezone } from './PITR.types'
+
+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)) {
+ arr.push(new Date(dt))
+ }
+ return arr
+}
export const getClientTimezone = () => {
const defaultTz = dayjs.tz.guess()
+ const utcTz = ALL_TIMEZONES.find((option) => option.value === 'UTC')
const timezone = ALL_TIMEZONES.find((option) => {
if (option.utc.includes(defaultTz)) return option
else return undefined
})
- return timezone ?? ALL_TIMEZONES[0]
+ return timezone ?? (utcTz || ALL_TIMEZONES[0])
}
export const checkMatchingDates = (selectedDate: Date | undefined, targetDate: Date) => {
@@ -29,3 +38,26 @@ export const formatNumberToTwoDigits = (number: Number) => {
useGrouping: false,
})
}
+
+// Formats Time object to hh:mm:ss
+export const formatTimeToTimeString = (time: Time) => {
+ return `${formatNumberToTwoDigits(time.h)}:${formatNumberToTwoDigits(
+ time.m
+ )}:${formatNumberToTwoDigits(time.s)}`
+}
+
+export const getTimezoneOffsetText = (timezone: Timezone) => {
+ return timezone.text.split(')')[0].slice(1)
+}
+
+export const getTimezoneOffset = (timezone: Timezone) => {
+ return timezone.text.split(')')[0].slice(4)
+}
+
+export const convertDatetimetoUnixS = (date: Date, time: Time, timezone: Timezone) => {
+ const dateString = dayjs(date).format('YYYY-MM-DD')
+ const timeString = formatTimeToTimeString(time)
+ const timezoneOffset = getTimezoneOffset(timezone)
+ const datetimestringWithTimezone = `${dateString}T${timeString}${timezoneOffset}`
+ return dayjs(datetimestringWithTimezone).unix()
+}
diff --git a/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx b/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx
index 0cc70ce4940..66a91621104 100644
--- a/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx
+++ b/studio/components/interfaces/Database/Backups/PITR/PITRNotice.tsx
@@ -1,18 +1,27 @@
-import { Button, IconCalendar, IconClock } from '@supabase/ui'
+import Link from 'next/link'
+import { useRouter } from 'next/router'
+import { Button, IconCalendar } from '@supabase/ui'
import { FormPanel } from 'components/ui/Forms'
const PITRNotice = ({}) => {
+ const router = useRouter()
+ const { ref } = router.query
+
return (
<FormPanel
disabled={true}
footer={
<div className="flex items-center justify-between p-6">
<span className="text-scale-1000 text-sm">
- Recovery retention period can be increase by upgrading
+ Recovery retention period can be increased - reach out to us!
</span>
- <Button type="default" icon={<IconClock strokeWidth={2} />}>
- Increase backup retention
- </Button>
+ <Link href={`/support/new?ref=${ref}&category=sales`}>
+ <a>
+ <Button as="span" type="default">
+ Contact support
+ </Button>
+ </a>
+ </Link>
</div>
}
>
diff --git a/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx b/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
index 276c6521117..e8f28fa937e 100644
--- a/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
+++ b/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
@@ -1,126 +1,163 @@
import dayjs from 'dayjs'
-import DatePicker from 'react-datepicker'
-import { useState } from 'react'
import { format } from 'date-fns'
-import { observer } from 'mobx-react-lite'
-import {
- Button,
- Modal,
- IconChevronLeft,
- IconChevronRight,
- IconHelpCircle,
- IconDatabase,
-} from '@supabase/ui'
+import { useEffect, useState } from 'react'
+import DatePicker from 'react-datepicker'
+import { Button, Modal, IconChevronLeft, IconChevronRight, IconHelpCircle } from '@supabase/ui'
+import * as Tooltip from '@radix-ui/react-tooltip'
import { useStore } from 'hooks'
-
-import { Time } from './PITR.types'
-import { getClientTimezone, checkMatchingDates, formatNumberToTwoDigits } from './PITR.utils'
-import PITRStatus from './PITRStatus'
-import TimeInput from './TimeInput'
-import TimezoneSelection from './TimezoneSelection'
+import { post } from 'lib/common/fetch'
+import { API_URL, PROJECT_STATUS } from 'lib/constants'
import { FormHeader, FormPanel } from 'components/ui/Forms'
import InformationBox from 'components/ui/InformationBox'
+import TimeInput from './TimeInput'
+import TimezoneSelection from './TimezoneSelection'
+import { Time, Timezone } from './PITR.types'
+import PITRStatus from './PITRStatus'
+import {
+ checkMatchingDates,
+ convertDatetimetoUnixS,
+ formatNumberToTwoDigits,
+ formatTimeToTimeString,
+ getClientTimezone,
+ getDatesBetweenRange,
+ getTimezoneOffsetText,
+} from './PITR.utils'
+import { useRouter } from 'next/router'
-// [Joshen TODO] Remaining todos:
-// - Need to validate the selectedDate against earliest and latest here to disable the review restore details button
-// - Refine messaging in confirmation modal
-// - Actually hook up the BE API, please ensure that the unix timestamp getting sent is correct
-// - Highlight available dates in the calendar and add a legend
-// - Just need to check in thereafter with Jonny if the changes are okay
-// - Deprecate old PITR components
-// - Be sure to go through any other [Joshen TODO] mentions
+const DEFAULT_TIME = { h: 0, m: 0, s: 0 }
const PITRSelection = ({}) => {
- const { backups } = useStore()
- const { earliestPhysicalBackupDateUnix, latestPhysicalBackupDateUnix } =
- backups?.configuration?.physicalBackupData ?? {}
+ const router = useRouter()
+ const { ref } = router.query
+
+ const { app, ui, backups } = useStore()
+ const projectId = ui.selectedProject?.id ?? -1
const [selectedDate, setSelectedDate] = useState<Date>()
- const [selectedTimezone, setSelectedTimezone] = useState(getClientTimezone())
+ const [selectedTime, setSelectedTime] = useState<Time>({ h: 0, m: 0, s: 0 })
+ const [selectedTimezone, setSelectedTimezone] = useState<Timezone>(getClientTimezone())
+
const [showConfiguration, setShowConfiguration] = useState(false)
const [showConfirmation, setShowConfirmation] = useState(false)
+ const [isRestoring, setIsRestoring] = useState(false)
- const formattedSelectedDate = dayjs.unix(Number(selectedDate) / 1000)
- // Should only convert to timezone at when confirming
- // const formattedSelectedDate = dayjs.unix(Number(selectedDate) / 1000).tz(selectedTimezone?.utc[0])
+ useEffect(() => {
+ if (selectedDate) {
+ if (selectedDate < earliestAvailableBackupFormatted) {
+ setSelectedDate(earliestAvailableBackupFormatted)
+ } else if (selectedDate > latestAvailableBackupFormatted) {
+ setSelectedDate(latestAvailableBackupFormatted)
+ }
+ }
+ }, [selectedTimezone])
- const earliestAvailableBackup = new Date(earliestPhysicalBackupDateUnix * 1000)
- const earliestAvailableTiming = dayjs(earliestAvailableBackup).tz(selectedTimezone?.utc[0])
+ useEffect(() => {
+ const formattedSelectedTime = dayjs(formatTimeToTimeString(selectedTime), 'HH:mm:ss', true)
+ const formattedEarliestTime = dayjs(
+ formatTimeToTimeString(earliestAvailableBackupTime),
+ 'HH:mm:ss',
+ true
+ )
+ const formattedLatestTime = dayjs(
+ formatTimeToTimeString(latestAvailableBackupTime),
+ 'HH:mm:ss',
+ true
+ )
- const latestAvailableBackup = new Date(latestPhysicalBackupDateUnix * 1000)
- const latestAvailableTiming = dayjs(latestAvailableBackup).tz(selectedTimezone?.utc[0])
+ if (isSelectedOnEarliest && formattedSelectedTime.isBefore(formattedEarliestTime)) {
+ return setSelectedTime(earliestAvailableBackupTime)
+ }
- const isSelectedOnEarliest = checkMatchingDates(selectedDate, earliestAvailableBackup)
- const isSelectedOnLatest = checkMatchingDates(selectedDate, latestAvailableBackup)
+ if (isSelectedOnLatest && formattedSelectedTime.isAfter(formattedLatestTime)) {
+ return setSelectedTime(latestAvailableBackupTime)
+ }
+ }, [selectedDate, selectedTimezone])
- const formattedSelectedTiming =
- selectedDate !== undefined
- ? {
- h: formatNumberToTwoDigits(selectedDate.getHours()),
- m: formatNumberToTwoDigits(selectedDate.getMinutes()),
- s: formatNumberToTwoDigits(selectedDate.getSeconds()),
- }
- : undefined
+ const { earliestPhysicalBackupDateUnix, latestPhysicalBackupDateUnix } =
+ backups?.configuration?.physicalBackupData ?? {}
+ const earliestAvailableBackup = dayjs(earliestPhysicalBackupDateUnix * 1000).tz(
+ selectedTimezone?.utc[0]
+ )
+ const latestAvailableBackup = dayjs(latestPhysicalBackupDateUnix * 1000).tz(
+ selectedTimezone?.utc[0]
+ )
- const formattedEarliestTiming = isSelectedOnEarliest
- ? {
- h: formatNumberToTwoDigits(earliestAvailableTiming.hour()),
- m: formatNumberToTwoDigits(earliestAvailableTiming.minute()),
- s: formatNumberToTwoDigits(earliestAvailableTiming.second()),
- }
- : undefined
+ // Start: Variables specifically for date picker component
+ // Required as it only works with vanilla Date object which is not timezone localized
+ const earliestAvailableBackupFormatted = new Date(earliestAvailableBackup.format('DD-MMM-YYYY'))
+ const latestAvailableBackupFormatted = new Date(latestAvailableBackup.format('DD-MMM-YYYY'))
+ const isSelectedOnEarliest = checkMatchingDates(selectedDate, earliestAvailableBackupFormatted)
+ const isSelectedOnLatest = checkMatchingDates(selectedDate, latestAvailableBackupFormatted)
+ const availableDates = getDatesBetweenRange(
+ earliestAvailableBackupFormatted,
+ latestAvailableBackupFormatted
+ )
+ // End: Variables specifically for date picker component
- const formattedLatestTiming = isSelectedOnLatest
- ? {
- h: formatNumberToTwoDigits(latestAvailableTiming.hour()),
- m: formatNumberToTwoDigits(latestAvailableTiming.minute()),
- s: formatNumberToTwoDigits(latestAvailableTiming.second()),
- }
- : undefined
+ const earliestAvailableBackupTime = {
+ h: earliestAvailableBackup.hour(),
+ m: earliestAvailableBackup.minute(),
+ s: earliestAvailableBackup.second(),
+ }
+
+ const latestAvailableBackupTime = {
+ h: latestAvailableBackup.hour(),
+ m: latestAvailableBackup.minute(),
+ s: latestAvailableBackup.second(),
+ }
+
+ // This will be the actual unix timestamp for the backup
+ const recoveryTimeTargetUnix = selectedDate
+ ? convertDatetimetoUnixS(selectedDate, selectedTime, selectedTimezone)
+ : 0
+ // Formatting from the unix again just to double check correctness
+ const recoveryTimeString = dayjs(recoveryTimeTargetUnix * 1000)
+ .tz(selectedTimezone?.utc[0])
+ .format('DD MMM YYYY HH:mm:ss')
+ const isSelectedOutOfRange =
+ selectedDate &&
+ (recoveryTimeTargetUnix < earliestPhysicalBackupDateUnix ||
+ recoveryTimeTargetUnix > latestPhysicalBackupDateUnix)
+
+ const onUpdateDate = (date: Date) => setSelectedDate(date)
const onCancel = () => {
+ setShowConfiguration(false)
setSelectedDate(undefined)
+ setSelectedTime(DEFAULT_TIME)
setSelectedTimezone(getClientTimezone())
- setShowConfiguration(false)
}
- const onUpdateDate = (date: Date) => {
- const isSelectedOnEarliest = checkMatchingDates(date, earliestAvailableBackup)
- const isSelectedOnLatest = checkMatchingDates(selectedDate, latestAvailableBackup)
+ const onConfirmRestore = async () => {
+ if (!recoveryTimeTargetUnix) return
+
+ setIsRestoring(true)
+ const projectRef = ref as string
+ const { error } = await post(`${API_URL}/database/${projectRef}/backups/pitr`, {
+ recovery_time_target_unix: recoveryTimeTargetUnix,
+ })
- if (isSelectedOnEarliest) {
- date.setHours(
- earliestAvailableTiming.hour(),
- earliestAvailableTiming.minute(),
- earliestAvailableTiming.second(),
- 0
- )
- } else if (isSelectedOnLatest) {
- date.setHours(
- latestAvailableTiming.hour(),
- latestAvailableTiming.minute(),
- latestAvailableTiming.second(),
- 0
- )
+ if (error) {
+ ui.setNotification({
+ error,
+ category: 'error',
+ message: `Point in time recovery for project failed`,
+ })
+ setIsRestoring(false)
} else {
- date.setHours(0, 0, 0, 0)
+ setTimeout(() => {
+ setShowConfirmation(false)
+ app.onProjectStatusUpdated(projectId, PROJECT_STATUS.RESTORING)
+ ui.setNotification({
+ category: 'success',
+ message: `Restoring database back to ${recoveryTimeString} (${getTimezoneOffsetText(
+ selectedTimezone
+ )})`,
+ })
+ router.push(`/project/${projectRef}`)
+ }, 3000)
}
-
- setSelectedDate(date)
- }
-
- const onUpdateTime = (time: Time) => {
- if (!selectedDate) return
- const updatedDate = new Date(Number(selectedDate))
- updatedDate.setHours(Number(time.h))
- updatedDate.setMinutes(Number(time.m))
- updatedDate.setSeconds(Number(time.s))
- setSelectedDate(updatedDate)
- }
-
- const onConfirmRestore = async () => {
- // Refer to PITRBackupSelection.tsx for logic here
}
return (
@@ -139,23 +176,46 @@ const PITRSelection = ({}) => {
<Button type="default" onClick={onCancel}>
Cancel
</Button>
- <Button type="warning" onClick={() => setShowConfirmation(true)}>
- Review restore details
- </Button>
+ <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">
- {/* Highlight the available dates better */}
<DatePicker
inline
selected={selectedDate}
onChange={onUpdateDate}
dayClassName={() => 'cursor-pointer'}
- minDate={earliestAvailableBackup}
- maxDate={latestAvailableBackup}
- // highlightDates={[new Date()]}
+ minDate={earliestAvailableBackupFormatted}
+ maxDate={latestAvailableBackupFormatted}
+ highlightDates={availableDates}
renderCustomHeader={({
date,
decreaseMonth,
@@ -192,7 +252,18 @@ const PITRSelection = ({}) => {
</div>
)}
/>
+ {/* Legend */}
+ <div className="flex items-center space-x-2">
+ <div
+ className="border w-4 h-4 border-scale-800"
+ style={{
+ background: 'linear-gradient(135deg, #34B27B 0% 30%, transparent 30%)',
+ }}
+ />
+ <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">
@@ -210,7 +281,12 @@ const PITRSelection = ({}) => {
<div className="space-y-1">
<p className="text-sm text-scale-1100">Restore database to</p>
<p className="text-3xl">
- {formattedSelectedDate.format('DD MMM YYYY, HH:mm:ss')}
+ <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">
@@ -223,25 +299,23 @@ const PITRSelection = ({}) => {
onSelectTimezone={setSelectedTimezone}
/>
</div>
-
<TimeInput
- defaultTime={formattedSelectedTiming}
- minimumTime={formattedEarliestTiming}
- maximumTime={formattedLatestTiming}
- onChange={onUpdateTime}
+ defaultTime={selectedTime}
+ minimumTime={earliestAvailableBackupTime}
+ maximumTime={latestAvailableBackupTime}
+ 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{' '}
- {earliestAvailableTiming.format('HH:mm:ss')}
+ {earliestAvailableBackup.format('HH:mm:ss')}
</p>
)}
{isSelectedOnLatest && (
<p className="text-sm text-scale-1000">
Latest available backup on this date is at{' '}
- {latestAvailableTiming.format('HH:mm:ss')}
+ {latestAvailableBackup.format('HH:mm:ss')}
</p>
)}
</div>
@@ -262,7 +336,12 @@ const PITRSelection = ({}) => {
<Button type="default" onClick={() => setShowConfirmation(false)}>
Cancel
</Button>
- <Button type="warning" onClick={onConfirmRestore}>
+ <Button
+ type="warning"
+ disabled={isRestoring}
+ loading={isRestoring}
+ onClick={onConfirmRestore}
+ >
I understand, begin restore
</Button>
</div>
@@ -276,7 +355,7 @@ const PITRSelection = ({}) => {
<Modal.Content>
<div className="py-2 space-y-1">
<p className="text-sm text-scale-1100"> Your database will be restored to</p>
- <p className="text-2xl">{formattedSelectedDate.format('DD MMM YYYY, HH:mm:ss')}</p>
+ <p className="text-2xl">{recoveryTimeString}</p>
<p className="text-lg">{selectedTimezone?.text}</p>
</div>
</Modal.Content>
@@ -291,35 +370,6 @@ const PITRSelection = ({}) => {
The restoration process will incur some downtime to your project and cannot be
undone.
</p>
- {/* <div className="flex space-x-5">
- <div className="w-10 h-10 rounded bg-scale-1200">
- <IconDatabase strokeWidth={2} />
- </div>
- <div>
- <p className="text-sm">Potential loss of recent data</p>
- <p className="text-sm text-scale-1100">
- Any database changes being made currently could be lost.
- </p>
- </div>
- </div>
- <div className="flex space-x-5">
- <div className="w-10 h-10 rounded bg-scale-1200" />
- <div>
- <p className="text-sm">Potential loss of new users</p>
- <p className="text-sm text-scale-1100">
- Users that recently signed up to your project could be lost.
- </p>
- </div>
- </div>
- <div className="flex space-x-5">
- <div className="w-10 h-10 rounded bg-scale-1200" />
- <div>
- <p className="text-sm">Potential loss of storage files</p>
- <p className="text-sm text-scale-1100">
- Any files recently uploaded to your storage could be lost.
- </p>
- </div>
- </div> */}
</div>
</Modal.Content>
</div>
@@ -328,4 +378,4 @@ const PITRSelection = ({}) => {
)
}
-export default observer(PITRSelection)
+export default PITRSelection
diff --git a/studio/components/interfaces/Database/Backups/PITR/TimeInput.tsx b/studio/components/interfaces/Database/Backups/PITR/TimeInput.tsx
index 236d4fbb354..c417426e940 100644
--- a/studio/components/interfaces/Database/Backups/PITR/TimeInput.tsx
+++ b/studio/components/interfaces/Database/Backups/PITR/TimeInput.tsx
@@ -5,7 +5,7 @@ import * as Tooltip from '@radix-ui/react-tooltip'
import { IconClock } from '@supabase/ui'
import { Time } from './PITR.types'
-import { formatNumberToTwoDigits } from './PITR.utils'
+import { formatNumberToTwoDigits, formatTimeToTimeString } from './PITR.utils'
// [Joshen] This is trying to do the same thing as TimeSplitInput.tsx
// so can we please look to try to combine these 2 components together if possible
@@ -25,33 +25,37 @@ interface Props {
const TimeInput: FC<Props> = ({ defaultTime, minimumTime, maximumTime, onChange = () => {} }) => {
const [isFocused, setIsFocused] = useState(false)
const [error, setError] = useState<string>()
- const [time, setTime] = useState<Time>({ h: '00', m: '00', s: '00' })
+ const [time, setTime] = useState<Time>(defaultTime || { h: 0, m: 0, s: 0 })
- useEffect(() => {
- if (defaultTime) setTime(defaultTime)
- }, [])
+ const formattedMinimumTime = minimumTime
+ ? dayjs(formatTimeToTimeString(minimumTime), 'HH:mm:ss', true)
+ : undefined
+
+ const formattedMaximumTime = maximumTime
+ ? dayjs(formatTimeToTimeString(maximumTime), 'HH:mm:ss', true)
+ : undefined
useEffect(() => {
- validate(defaultTime ?? time)
+ if (minimumTime || maximumTime) validate(time)
}, [JSON.stringify(minimumTime), JSON.stringify(maximumTime)])
+ useEffect(() => {
+ if (defaultTime) {
+ setTime(defaultTime)
+ validate(defaultTime)
+ }
+ }, [defaultTime])
+
const validate = (time: Time) => {
let error = undefined
- const formattedTime = dayjs(`${time.h}:${time.m}:${time.s}`, 'HH:mm:ss', true)
- if (!formattedTime.isValid()) error = 'Please enter a valid time'
+ const formattedTime = dayjs(formatTimeToTimeString(time), 'HH:mm:ss', true)
- const formattedMinimumTime = minimumTime
- ? dayjs(`${minimumTime.h}:${minimumTime.m}:${minimumTime.s}`, 'HH:mm:ss', true)
- : undefined
- if (formattedMinimumTime && formattedTime.isBefore(formattedMinimumTime)) {
+ if (!formattedTime.isValid()) {
+ error = 'Please enter a valid time'
+ } else if (formattedMinimumTime && formattedTime.isBefore(formattedMinimumTime)) {
error = 'Selected time is before the minimum time allowed'
- }
-
- const formattedMaximumTime = maximumTime
- ? dayjs(`${maximumTime.h}:${maximumTime.m}:${maximumTime.s}`, 'HH:mm:ss', true)
- : undefined
- if (formattedMaximumTime && formattedTime.isAfter(formattedMaximumTime)) {
+ } else if (formattedMaximumTime && formattedTime.isAfter(formattedMaximumTime)) {
error = 'Selected time is after the maximum time allowed'
}
@@ -67,13 +71,12 @@ const TimeInput: FC<Props> = ({ defaultTime, minimumTime, maximumTime, onChange
}
const onInputBlur = (event: ChangeEvent<HTMLInputElement>, unit: 'h' | 'm' | 's') => {
- const formattedInput = formatNumberToTwoDigits(Number(event.target.value))
+ const formattedInput = Number(event.target.value)
const updatedTime = { ...time, [unit]: formattedInput }
setTime(updatedTime)
- const isValid = validate(updatedTime)
- if (isValid) onChange(updatedTime)
-
+ validate(updatedTime)
+ onChange(updatedTime)
setIsFocused(false)
}
@@ -100,7 +103,7 @@ const TimeInput: FC<Props> = ({ defaultTime, minimumTime, maximumTime, onChange
maxLength={2}
pattern="[0-9]*"
placeholder="HH"
- value={time.h}
+ value={formatNumberToTwoDigits(time.h)}
onFocus={onFocus}
aria-label="Hours"
onBlur={(event) => onInputBlur(event, 'h')}
@@ -128,7 +131,7 @@ const TimeInput: FC<Props> = ({ defaultTime, minimumTime, maximumTime, onChange
maxLength={2}
pattern="[0-9]*"
placeholder="MM"
- value={time.m}
+ value={formatNumberToTwoDigits(time.m)}
onFocus={onFocus}
aria-label="Minutes"
onBlur={(event) => onInputBlur(event, 'm')}
@@ -156,7 +159,7 @@ const TimeInput: FC<Props> = ({ defaultTime, minimumTime, maximumTime, onChange
maxLength={2}
pattern="[0-9]*"
placeholder="SS"
- value={time.s}
+ value={formatNumberToTwoDigits(time.s)}
onFocus={onFocus}
aria-label="Seconds"
onBlur={(event) => onInputBlur(event, 's')}
diff --git a/studio/components/ui/PasswordStrengthBar.tsx b/studio/components/ui/PasswordStrengthBar.tsx
index a71db32e2bc..c262bff2118 100644
--- a/studio/components/ui/PasswordStrengthBar.tsx
+++ b/studio/components/ui/PasswordStrengthBar.tsx
@@ -38,12 +38,7 @@ const PasswordStrengthBar = ({
></div>
</div>
)}
- <p
- className={
- // [Joshen TODO] Is this correct?
- passwordStrengthScore >= DEFAULT_MINIMUM_PASSWORD_STRENGTH ? 'text-green-600' : ''
- }
- >
+ <p>
{passwordStrengthMessage
? passwordStrengthMessage
: 'This is the password to your postgres database, so it must be a strong password and hard to guess.'}{' '}
diff --git a/studio/pages/project/[ref]/database/backups/pitr.tsx b/studio/pages/project/[ref]/database/backups/pitr.tsx
index 0afd456b79e..5578e6fd640 100644
--- a/studio/pages/project/[ref]/database/backups/pitr.tsx
+++ b/studio/pages/project/[ref]/database/backups/pitr.tsx
@@ -1,23 +1,22 @@
+import Link from 'next/link'
import { useRouter } from 'next/router'
import { observer } from 'mobx-react-lite'
-import { Tabs } from '@supabase/ui'
+import { IconInfo, Tabs } from '@supabase/ui'
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { NextPageWithLayout } from 'types'
import { useStore, checkPermissions } from 'hooks'
import { DatabaseLayout } from 'components/layouts'
-import { PITRBackupSelection } from 'components/interfaces/Database'
-import { NextPageWithLayout } from 'types'
+import Loading from 'components/ui/Loading'
import NoPermission from 'components/ui/NoPermission'
import { PITRNotice, PITRSelection } from 'components/interfaces/Database/Backups/PITR'
+import BackupsError from 'components/interfaces/Database/Backups/BackupsError'
-const DatabaseScheduledBackups: NextPageWithLayout = () => {
+const DatabasePhysicalBackups: NextPageWithLayout = () => {
const { ui } = useStore()
const router = useRouter()
-
const ref = ui.selectedProject?.ref ?? 'default'
- const canReadPhysicalBackups = checkPermissions(PermissionAction.READ, 'physical_backups')
-
return (
<div className="mx-auto max-w-4xl space-y-6 px-5 pt-12 pb-20">
<h3 className="text-scale-1200 text-xl">Backups</h3>
@@ -34,22 +33,50 @@ const DatabaseScheduledBackups: NextPageWithLayout = () => {
</Tabs>
<div className="space-y-8">
- {canReadPhysicalBackups ? (
- <>
- <PITRNotice />
- <PITRSelection />
- {/* <PITRBackupSelection /> */}
- </>
- ) : (
- <NoPermission resourceText="view PITR backups" />
- )}
+ <PITR />
</div>
</div>
)
}
-DatabaseScheduledBackups.getLayout = (page) => (
+DatabasePhysicalBackups.getLayout = (page) => (
<DatabaseLayout title="Database">{page}</DatabaseLayout>
)
-export default observer(DatabaseScheduledBackups)
+const PITR = () => {
+ const { ui, backups } = useStore()
+ const { configuration, error, isLoading } = backups
+
+ const ref = ui.selectedProject?.ref ?? 'default'
+ const isEnabled = configuration.walg_enabled
+
+ const canReadPhysicalBackups = checkPermissions(PermissionAction.READ, 'physical_backups')
+ if (!canReadPhysicalBackups) return <NoPermission resourceText="view PITR backups" />
+
+ if (isLoading) return <Loading />
+ if (error) return <BackupsError />
+ if (!isEnabled)
+ return (
+ <div className="block w-full rounded border border-gray-400 border-opacity-50 bg-gray-300 p-3">
+ <div className="flex space-x-3">
+ <IconInfo size={20} strokeWidth={1.5} />
+ <p className="text-sm">
+ Point in time backups is an Enterprise feature. Reach out to us{' '}
+ <Link href={`/support/new?ref=${ref}&category=sales`}>
+ <a className="text-brand-900">here</a>
+ </Link>{' '}
+ if you're interested!
+ </p>
+ </div>
+ </div>
+ )
+
+ return (
+ <>
+ <PITRNotice />
+ <PITRSelection />
+ </>
+ )
+}
+
+export default observer(DatabasePhysicalBackups)