Skip to content

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

Tidy up UI and fix small issues

Joshen Lim50f2fcca62a5
diff --git a/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts b/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts
index e61b19f861b..edd9bb07aba 100644
--- a/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts
+++ b/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts
@@ -58,6 +58,6 @@ export const convertDatetimetoUnixS = (date: Date, time: Time, timezone: Timezon
const dateString = dayjs(date).format('YYYY-MM-DD')
const timeString = formatTimeToTimeString(time)
const timezoneOffset = getTimezoneOffset(timezone)
- const datetimestringWithTimezone = `${dateString}T${timeString}${timezoneOffset}`
+ const datetimestringWithTimezone = `${dateString}T${timeString}${timezoneOffset || '+00:00'}`
return dayjs(datetimestringWithTimezone).unix()
}
diff --git a/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx b/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
index 1608d4b994b..e491186832a 100644
--- a/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
+++ b/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
@@ -2,7 +2,14 @@ import dayjs from 'dayjs'
import { format } from 'date-fns'
import { useEffect, useState } from 'react'
import DatePicker from 'react-datepicker'
-import { Button, Modal, IconChevronLeft, IconChevronRight, IconHelpCircle } from '@supabase/ui'
+import {
+ Button,
+ Modal,
+ IconChevronLeft,
+ IconChevronRight,
+ IconHelpCircle,
+ Alert,
+} from '@supabase/ui'
import * as Tooltip from '@radix-ui/react-tooltip'
import { useStore } from 'hooks'
@@ -21,7 +28,6 @@ import {
formatTimeToTimeString,
getClientTimezone,
getDatesBetweenRange,
- getTimezoneOffsetText,
} from './PITR.utils'
import { useRouter } from 'next/router'
@@ -115,6 +121,7 @@ const PITRSelection = ({}) => {
const recoveryTimeString = dayjs(recoveryTimeTargetUnix * 1000)
.tz(selectedTimezone?.utc[0])
.format('DD MMM YYYY HH:mm:ss')
+
const isSelectedOutOfRange =
selectedDate &&
(recoveryTimeTargetUnix < earliestPhysicalBackupDateUnix ||
@@ -142,19 +149,13 @@ const PITRSelection = ({}) => {
ui.setNotification({
error,
category: 'error',
- message: `Point in time recovery for project failed`,
+ message: `Failed to being restoration: ${error.message}`,
})
setIsRestoring(false)
} else {
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)
}
@@ -167,7 +168,11 @@ const PITRSelection = ({}) => {
description="Database changes are watched and recorded, so that you can restore your database to any point in time"
/>
{!showConfiguration ? (
- <PITRStatus onSetConfiguration={() => setShowConfiguration(true)} />
+ <PITRStatus
+ selectedTimezone={selectedTimezone}
+ onUpdateTimezone={setSelectedTimezone}
+ onSetConfiguration={() => setShowConfiguration(true)}
+ />
) : (
<FormPanel
disabled={true}
@@ -253,12 +258,7 @@ const PITRSelection = ({}) => {
)}
/>
<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%)',
- }}
- />
+ <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>
@@ -300,8 +300,8 @@ const PITRSelection = ({}) => {
</div>
<TimeInput
defaultTime={selectedTime}
- minimumTime={earliestAvailableBackupTime}
- maximumTime={latestAvailableBackupTime}
+ minimumTime={isSelectedOnEarliest ? earliestAvailableBackupTime : undefined}
+ maximumTime={isSelectedOnLatest ? latestAvailableBackupTime : undefined}
onChange={setSelectedTime}
/>
<div className="!mt-4 space-y-1">
@@ -364,16 +364,21 @@ const PITRSelection = ({}) => {
</Modal.Content>
<Modal.Seperator />
<Modal.Content>
- <div className="py-2 space-y-3">
- <p className="text-sm text-scale-1100">
- Any changes made to your database up to this point of time will be lost. This
- includes any changes involving storage and authentication.
- </p>
- <p className="text-sm text-scale-1100">
- The restoration process will incur some downtime to your project and cannot be
- undone.
- </p>
- </div>
+ <Alert withIcon variant="warning" title="Warning: This action cannot be undone">
+ <div className="space-y-3">
+ <p>
+ Any changes made to your database after this point in time will be lost. This
+ includes any changes to your project's storage and authentication.
+ </p>
+ </div>
+ </Alert>
+ </Modal.Content>
+ <Modal.Seperator />
+ <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.
+ </p>
</Modal.Content>
</div>
</Modal>
diff --git a/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx b/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
index 593f062dd4b..899192e513c 100644
--- a/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
+++ b/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
@@ -1,24 +1,24 @@
import dayjs from 'dayjs'
-import { FC, useState } from 'react'
+import { FC } from 'react'
import { observer } from 'mobx-react-lite'
import { Button, IconAlertCircle } from '@supabase/ui'
import { useStore } from 'hooks'
-import { getClientTimezone } from './PITR.utils'
-import { FormHeader, FormPanel } from 'components/ui/Forms'
+import { Timezone } from './PITR.types'
+import { FormPanel } from 'components/ui/Forms'
import TimezoneSelection from './TimezoneSelection'
interface Props {
+ selectedTimezone: Timezone
+ onUpdateTimezone: (timezone: Timezone) => void
onSetConfiguration: () => void
}
-const PITRStatus: FC<Props> = ({ onSetConfiguration }) => {
+const PITRStatus: FC<Props> = ({ selectedTimezone, onUpdateTimezone, onSetConfiguration }) => {
const { backups } = useStore()
const { earliestPhysicalBackupDateUnix, latestPhysicalBackupDateUnix } =
backups?.configuration?.physicalBackupData ?? {}
- const [selectedTimezone, setSelectedTimezone] = useState<any>(getClientTimezone())
-
const earliestAvailableBackup = dayjs
.unix(earliestPhysicalBackupDateUnix)
.tz(selectedTimezone?.utc[0])
@@ -50,7 +50,7 @@ const PITRStatus: FC<Props> = ({ onSetConfiguration }) => {
<TimezoneSelection
hideLabel
selectedTimezone={selectedTimezone}
- onSelectTimezone={setSelectedTimezone}
+ onSelectTimezone={onUpdateTimezone}
/>
</div>
<div className="flex items-center space-x-20">
diff --git a/studio/components/interfaces/Database/Backups/PITR/TimeInput.tsx b/studio/components/interfaces/Database/Backups/PITR/TimeInput.tsx
index c417426e940..d2c15df7190 100644
--- a/studio/components/interfaces/Database/Backups/PITR/TimeInput.tsx
+++ b/studio/components/interfaces/Database/Backups/PITR/TimeInput.tsx
@@ -48,7 +48,6 @@ const TimeInput: FC<Props> = ({ defaultTime, minimumTime, maximumTime, onChange
const validate = (time: Time) => {
let error = undefined
-
const formattedTime = dayjs(formatTimeToTimeString(time), 'HH:mm:ss', true)
if (!formattedTime.isValid()) {
diff --git a/studio/components/layouts/ProjectLayout/BuildingState.tsx b/studio/components/layouts/ProjectLayout/BuildingState.tsx
index f8b15fa1f77..db734ee71eb 100644
--- a/studio/components/layouts/ProjectLayout/BuildingState.tsx
+++ b/studio/components/layouts/ProjectLayout/BuildingState.tsx
@@ -12,9 +12,12 @@ import { getWithTimeout } from 'lib/common/fetch'
import { Project } from 'types'
import { DisplayApiSettings, DisplayConfigSettings } from 'components/ui/ProjectSettings'
-type ProjectBuildingState = { project: Project }
-const ProjectBuildingState: FC<ProjectBuildingState> = ({ project }) => {
- const { app } = useStore()
+interface Props {
+ project: Project
+}
+
+const BuildingState: FC<Props> = ({ project }) => {
+ const { ui, app } = useStore()
const checkServerInterval = useRef<number>()
async function checkServer() {
@@ -150,7 +153,7 @@ const ProjectBuildingState: FC<ProjectBuildingState> = ({ project }) => {
</div>
)
}
-export default observer(ProjectBuildingState)
+export default observer(BuildingState)
const ChecklistItem = ({ description }: any) => {
return (
diff --git a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
index 41d9b22cbc4..e9b3f6785e9 100644
--- a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
+++ b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
@@ -12,6 +12,7 @@ import LayoutHeader from './LayoutHeader'
import ConnectingState from './ConnectingState'
import PausingState from './PausingState'
import BuildingState from './BuildingState'
+import RestoringState from './RestoringState'
interface Props {
title?: string
@@ -112,6 +113,7 @@ const ContentWrapper: FC<ContentWrapperProps> = observer(({ isLoading, children
const requiresDbConnection: boolean = router.pathname !== '/project/[ref]/settings/general'
const requiresPostgrestConnection = !routesToIgnorePostgrestConnection.includes(router.pathname)
+ const isProjectRestoring = ui.selectedProject?.status === PROJECT_STATUS.RESTORING
const isProjectBuilding = [PROJECT_STATUS.COMING_UP, PROJECT_STATUS.RESTORING].includes(
ui.selectedProject?.status ?? ''
)
@@ -126,6 +128,8 @@ const ContentWrapper: FC<ContentWrapperProps> = observer(({ isLoading, children
<PausingState project={ui.selectedProject} />
) : requiresPostgrestConnection && isProjectOffline ? (
<ConnectingState project={ui.selectedProject} />
+ ) : requiresDbConnection && isProjectRestoring ? (
+ <RestoringState />
) : requiresDbConnection && isProjectBuilding ? (
<BuildingState project={ui.selectedProject} />
) : (
diff --git a/studio/components/layouts/ProjectLayout/RestoringState.tsx b/studio/components/layouts/ProjectLayout/RestoringState.tsx
new file mode 100644
index 00000000000..4ce0213c056
--- /dev/null
+++ b/studio/components/layouts/ProjectLayout/RestoringState.tsx
@@ -0,0 +1,89 @@
+import { FC, useEffect, useRef, useState } from 'react'
+import { Button, IconCheckCircle, IconLoader } from '@supabase/ui'
+
+import { useStore } from 'hooks'
+import { API_URL, PROJECT_STATUS } from 'lib/constants'
+import { getWithTimeout } from 'lib/common/fetch'
+
+interface Props {}
+
+const RestoringState: FC<Props> = ({}) => {
+ const { app, ui } = useStore()
+ const project = ui.selectedProject
+ const checkServerInterval = useRef<number>()
+
+ const [loading, setLoading] = useState(false)
+ const [isCompleted, setIsCompleted] = useState(false)
+
+ useEffect(() => {
+ checkServerInterval.current = window.setInterval(checkServer, 4000)
+ return () => clearInterval(checkServerInterval.current)
+ }, [])
+
+ async function checkServer() {
+ if (!project) return
+
+ const projectStatus = await getWithTimeout(`${API_URL}/projects/${project.ref}/status`, {
+ timeout: 2000,
+ })
+ if (projectStatus && !projectStatus.error) {
+ const { status } = projectStatus
+ if (status === PROJECT_STATUS.ACTIVE_HEALTHY) {
+ clearInterval(checkServerInterval.current)
+ setIsCompleted(true)
+ }
+ }
+ }
+
+ const onConfirm = async () => {
+ setLoading(true)
+ await app.projects.fetchDetail(project?.ref ?? '')
+ }
+
+ return (
+ <div className="flex items-center justify-center h-full">
+ <div
+ className={[
+ 'grid grid-cols-12 gap-4',
+ 'bg-scale-300 border border-scale-400 rounded-md w-3/4 lg:w-1/2 px-8 py-6',
+ ].join(' ')}
+ >
+ {isCompleted ? (
+ <>
+ <div className="col-span-1">
+ <IconCheckCircle className="text-brand-900" strokeWidth={2} />
+ </div>
+ <div className="col-span-11 space-y-1">
+ <p>Restoration complete!</p>
+ <p className="text-sm text-scale-1100">
+ Your project has been successfully restored and is now back online.
+ </p>
+ </div>
+ </>
+ ) : (
+ <>
+ <div className="col-span-1">
+ <IconLoader className="animate-spin" />
+ </div>
+ <div className="col-span-11 space-y-1">
+ <p>Restoration in progress</p>
+ <p className="text-sm text-scale-1100">
+ Restoration can take from a few minutes up to several hours depending on the size of
+ your database. Your project will be offline while the restoration is running.
+ </p>
+ </div>
+ </>
+ )}
+ {isCompleted && (
+ <div className="col-start-2 col-span-11">
+ <Button disabled={loading} loading={loading} onClick={onConfirm}>
+ Confirm
+ </Button>
+ </div>
+ )}
+ </div>
+ </div>
+ )
+}
+
+export default RestoringState
diff --git a/studio/styles/date-picker.scss b/studio/styles/date-picker.scss
index 89cb112980e..d43d5286e2a 100644
--- a/studio/styles/date-picker.scss
+++ b/studio/styles/date-picker.scss
@@ -88,7 +88,8 @@
@apply bg-scale-200;
}
-.react-datepicker__day--selected {
+.react-datepicker__day--selected,
+.react-datepicker__day--selected.react-datepicker__day--highlighted {
@apply bg-brand-800 text-white;
}
@@ -101,9 +102,5 @@
}
.react-datepicker__day--highlighted {
- background: linear-gradient(135deg, #34B27B 0% 20%, transparent 20%);
-}
-
-.react-datepicker__day--selected.react-datepicker__day--highlighted {
- background: linear-gradient(135deg, #34B27B 0% 20%, hsla(153, 60%, 28%, 1) 20%);
+ @apply bg-brand-600 text-scale-1100;
}
\ No newline at end of file
diff --git a/studio/types/ui.ts b/studio/types/ui.ts
index 2095094d2ed..e14c8948e7e 100644
--- a/studio/types/ui.ts
+++ b/studio/types/ui.ts
@@ -5,6 +5,11 @@ export interface Notification {
error?: any // Optional: Any other errors that needs to be logged out in the console
progress?: number // Optional: For loading messages to show a progress bar (Out of 100)
duration?: number // Optional: How long to show the message for (ms)
+ metadata?: NotificationMetadata
+}
+
+interface NotificationMetadata {
+ [key: string]: any
}
export interface ChartIntervals {