Skip to content

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

Set project status within state to restoring when doing a backup restore, and small clean up of grid component

Joshen Limf309bc17eb74
diff --git a/studio/components/grid/components/common/ConfirmAlert.tsx b/studio/components/grid/components/common/ConfirmAlert.tsx
deleted file mode 100644
index d1e0dd7f03a..00000000000
--- a/studio/components/grid/components/common/ConfirmAlert.tsx
+++ /dev/null
@@ -1,98 +0,0 @@
-import * as React from 'react';
-import { Button, Modal } from '@supabase/ui';
-import { render, unmountComponentAtNode } from 'react-dom';
-
-type ConfirmModalProps = {
- title: string;
- message: string;
- onConfirm?: () => void;
- onAsyncConfirm?: () => Promise<void>;
- variant?: 'danger' | 'warning' | 'success' | undefined;
-};
-const ConfirmModal: React.FC<ConfirmModalProps> = ({
- title,
- message,
- onConfirm,
- onAsyncConfirm,
- variant = 'danger',
-}) => {
- const [loading, setLoading] = React.useState(false);
-
- function onCancelClick() {
- if (!loading) onClose();
- }
-
- async function onConfirmClick() {
- if (onAsyncConfirm) {
- setLoading(true);
- await onAsyncConfirm();
-
- onClose();
- } else if (onConfirm) {
- onConfirm();
- onClose();
- }
- }
-
- function onClose() {
- removeElement();
- }
-
- return (
- <Modal
- variant={variant}
- visible={true}
- header={title}
- showIcon={false}
- size="small"
- confirmText="OK"
- cancelText="Cancel"
- onCancel={onCancelClick}
- loading={loading}
- customFooter={
- <>
- <div className="flex items-center gap-2">
- <Button type="default" onClick={() => onCancelClick()}>
- Cancel
- </Button>
- <Button
- type="primary"
- loading={loading}
- onClick={() => onConfirmClick()}
- >
- Confirm
- </Button>
- </div>
- </>
- }
- >
- <Modal.Content>
- <p className="text-sm text-scale-1100">{message}</p>
- </Modal.Content>
- </Modal>
- );
-};
-
-function removeElement() {
- const target = document.getElementById('supabase-ui-confirm-alert');
- if (target) {
- unmountComponentAtNode(target);
- target?.parentNode?.removeChild(target);
- }
-}
-
-function createElement(props: ConfirmModalProps) {
- let divTarget = document.getElementById('supabase-ui-confirm-alert');
- if (divTarget) {
- render(<ConfirmModal {...props} />, divTarget);
- } else {
- divTarget = document.createElement('div');
- divTarget.id = 'supabase-ui-confirm-alert';
- document.body.appendChild(divTarget);
- render(<ConfirmModal {...props} />, divTarget);
- }
-}
-
-export function showConfirmAlert(props: ConfirmModalProps) {
- createElement(props);
-}
diff --git a/studio/components/grid/components/common/index.ts b/studio/components/grid/components/common/index.ts
index ad34f221222..9ac92bc11a2 100644
--- a/studio/components/grid/components/common/index.ts
+++ b/studio/components/grid/components/common/index.ts
@@ -1,8 +1,7 @@
-export * from './BlockKeys';
-export * from './ConfirmAlert';
-export * from './DropdownControl';
-export * from './MonacoEditor';
-export * from './NullValue';
-export * from './Hooks';
-export * from './Shortcuts';
-export * from './EmptyValue';
+export * from './BlockKeys'
+export * from './DropdownControl'
+export * from './MonacoEditor'
+export * from './NullValue'
+export * from './Hooks'
+export * from './Shortcuts'
+export * from './EmptyValue'
diff --git a/studio/components/grid/components/header/Header.tsx b/studio/components/grid/components/header/Header.tsx
index 502a6b2c2d7..2ad4c625b2c 100644
--- a/studio/components/grid/components/header/Header.tsx
+++ b/studio/components/grid/components/header/Header.tsx
@@ -1,13 +1,13 @@
import * as React from 'react'
import { useDispatch, useTrackedState } from '../../store'
-import { Button, Divider, IconDownload, IconPlus, IconX, IconTrash, Typography } from '@supabase/ui'
+import { Button, Divider, IconDownload, IconPlus, IconX, IconTrash } from '@supabase/ui'
import { saveAs } from 'file-saver'
import FilterDropdown from './filter'
import SortPopover from './sort'
import StatusLabel from './StatusLabel'
import RefreshButton from './RefreshButton'
import { exportRowsToCsv } from '../../utils'
-import { showConfirmAlert } from '../common'
+import { confirmAlert } from 'components/to-be-cleaned/ModalsDeprecated/ConfirmModal'
type HeaderProps = {
onAddColumn?: () => void
@@ -91,7 +91,7 @@ const RowHeader: React.FC<RowHeaderProps> = ({}) => {
const { selectedRows, rows: allRows, editable } = state
const onRowsDelete = () => {
- showConfirmAlert({
+ confirmAlert({
title: 'Confirm to delete',
message: 'Are you sure you want to delete the selected rows? This action cannot be undone.',
onConfirm: async () => {
diff --git a/studio/components/grid/components/menu/RowContextMenu.tsx b/studio/components/grid/components/menu/RowContextMenu.tsx
index 0db4c8749c0..2ae413641fc 100644
--- a/studio/components/grid/components/menu/RowContextMenu.tsx
+++ b/studio/components/grid/components/menu/RowContextMenu.tsx
@@ -1,71 +1,69 @@
-import * as React from 'react';
-import { Menu, Item, ItemParams, PredicateParams } from 'react-contexify';
-import { IconTrash, IconClipboard, IconEdit } from '@supabase/ui';
-import { useDispatch, useTrackedState } from '../../store';
-import { formatClipboardValue, copyToClipboard } from '../../utils';
-import { showConfirmAlert } from '../common';
+import * as React from 'react'
+import { Menu, Item, ItemParams, PredicateParams } from 'react-contexify'
+import { IconTrash, IconClipboard, IconEdit } from '@supabase/ui'
+import { useDispatch, useTrackedState } from '../../store'
+import { formatClipboardValue, copyToClipboard } from '../../utils'
+import { confirmAlert } from 'components/to-be-cleaned/ModalsDeprecated/ConfirmModal'
-export const ROW_CONTEXT_MENU_ID = 'row-context-menu-id';
+export const ROW_CONTEXT_MENU_ID = 'row-context-menu-id'
-type RowContextMenuProps = {};
+type RowContextMenuProps = {}
const RowContextMenu: React.FC<RowContextMenuProps> = ({}) => {
- const state = useTrackedState();
- const dispatch = useDispatch();
+ const state = useTrackedState()
+ const dispatch = useDispatch()
function onDeleteRow(p: ItemParams) {
- showConfirmAlert({
+ confirmAlert({
title: 'Confirm to delete',
- message:
- 'Are you sure you want to delete this row? This action cannot be undone.',
+ message: 'Are you sure you want to delete this row? This action cannot be undone.',
onConfirm: async () => {
- const { props } = p;
- const { rowIdx } = props;
- const row = state.rows[rowIdx];
- const { error } = state.rowService!.delete([row]);
+ const { props } = p
+ const { rowIdx } = props
+ const row = state.rows[rowIdx]
+ const { error } = state.rowService!.delete([row])
if (error) {
- if (state.onError) state.onError(error);
+ if (state.onError) state.onError(error)
} else {
- dispatch({ type: 'REMOVE_ROWS', payload: { rowIdxs: [row.idx] } });
+ dispatch({ type: 'REMOVE_ROWS', payload: { rowIdxs: [row.idx] } })
dispatch({
type: 'SELECTED_ROWS_CHANGE',
payload: { selectedRows: new Set() },
- });
+ })
}
},
- });
+ })
}
function onEditRowClick(p: ItemParams) {
- const { props } = p;
- const { rowIdx } = props;
- const row = state.rows[rowIdx];
- if (state.onEditRow) state.onEditRow(row);
+ const { props } = p
+ const { rowIdx } = props
+ const row = state.rows[rowIdx]
+ if (state.onEditRow) state.onEditRow(row)
}
function isItemHidden({ data }: PredicateParams) {
- if (data === 'edit') return state.onEditRow == undefined;
- if (data === 'delete') return !state.editable;
- return false;
+ if (data === 'edit') return state.onEditRow == undefined
+ if (data === 'delete') return !state.editable
+ return false
}
function onCopyCellContent(p: ItemParams) {
- const { props } = p;
+ const { props } = p
if (!state.selectedCellPosition || !props) {
- return;
+ return
}
- const { rowIdx } = props;
- const row = state.rows[rowIdx];
+ const { rowIdx } = props
+ const row = state.rows[rowIdx]
- const columnKey =
- state.gridColumns[state.selectedCellPosition?.idx as number].key;
+ const columnKey = state.gridColumns[state.selectedCellPosition?.idx as number].key
- const value = row[columnKey];
- const text = formatClipboardValue(value);
+ const value = row[columnKey]
+ const text = formatClipboardValue(value)
- copyToClipboard(text);
+ copyToClipboard(text)
}
return (
@@ -85,6 +83,6 @@ const RowContextMenu: React.FC<RowContextMenuProps> = ({}) => {
</Item>
</Menu>
</>
- );
-};
-export default RowContextMenu;
+ )
+}
+export default RowContextMenu
diff --git a/studio/components/grid/components/menu/RowMenu.tsx b/studio/components/grid/components/menu/RowMenu.tsx
index 36437a43fd8..bff5b03eaab 100644
--- a/studio/components/grid/components/menu/RowMenu.tsx
+++ b/studio/components/grid/components/menu/RowMenu.tsx
@@ -3,7 +3,7 @@ import * as React from 'react'
import { useDispatch, useTrackedState } from '../../store'
import { exportRowsToCsv } from '../../utils'
import { saveAs } from 'file-saver'
-import { showConfirmAlert } from '../common'
+import { confirmAlert } from 'components/to-be-cleaned/ModalsDeprecated/ConfirmModal'
type RowMenuProps = {}
@@ -13,7 +13,7 @@ const RowMenu: React.FC<RowMenuProps> = ({}) => {
const { selectedRows, rows: allRows, editable } = state
function onRowsDelete() {
- showConfirmAlert({
+ confirmAlert({
title: 'Confirm to delete',
message: 'Are you sure you want to delete the selected rows? This action cannot be undone.',
onConfirm: async () => {
diff --git a/studio/components/interfaces/Database/Backups/BackupItem.tsx b/studio/components/interfaces/Database/Backups/BackupItem.tsx
index a2f1a7ff794..ae530eb0972 100644
--- a/studio/components/interfaces/Database/Backups/BackupItem.tsx
+++ b/studio/components/interfaces/Database/Backups/BackupItem.tsx
@@ -5,7 +5,7 @@ import { observer } from 'mobx-react-lite'
import { Badge, Button, IconDownload } from '@supabase/ui'
import { useStore } from 'hooks'
-import { API_URL } from 'lib/constants'
+import { API_URL, PROJECT_STATUS } from 'lib/constants'
import { post } from 'lib/common/fetch'
import { confirmAlert } from 'components/to-be-cleaned/ModalsDeprecated/ConfirmModal'
@@ -17,17 +17,26 @@ interface Props {
const BackupItem: FC<Props> = ({ projectRef, backup, index }) => {
const router = useRouter()
- const { ui } = useStore()
+ const { app, ui } = useStore()
const [isDownloading, setDownloading] = useState<boolean>(false)
const [isRestoring, setRestoring] = useState<boolean>(false)
+ const projectId = ui.selectedProject?.id ?? -1
+
async function restore(backup: any) {
setRestoring(true)
try {
post(`${API_URL}/database/${projectRef}/backups/restore`, backup).then(() => {
setTimeout(() => {
- router.push('/project/[id]', `/project/${projectRef}`)
+ app.onProjectStatusUpdated(projectId, PROJECT_STATUS.RESTORING)
+ ui.setNotification({
+ category: 'success',
+ message: `Restoring database back to ${dayjs(backup.inserted_at).format(
+ 'DD MMM YYYY HH:mm:ss'
+ )}`,
+ })
+ router.push(`/project/${projectRef}`)
}, 3000)
})
} catch (error) {
@@ -46,7 +55,7 @@ const BackupItem: FC<Props> = ({ projectRef, backup, index }) => {
const res = await post(`${API_URL}/database/${projectRef}/backups/download`, backup)
const { fileUrl } = await res
- // triger browser download by create,trigger and remove tempLink
+ // Trigger browser download by create,trigger and remove tempLink
const tempLink = document.createElement('a')
tempLink.href = fileUrl
document.body.appendChild(tempLink)
@@ -101,18 +110,16 @@ const BackupItem: FC<Props> = ({ projectRef, backup, index }) => {
}
return (
- <>
- <div
- className={`flex h-12 items-center justify-between px-6 ${
- index ? 'dark:border-dark border-t' : ''
- }`}
- >
- <p className="text-scale-1200 text-sm ">
- {dayjs(backup.inserted_at).format('DD MMM YYYY HH:mm:ss')}
- </p>
- <div className="">{generateSideButtons(backup)}</div>
- </div>
- </>
+ <div
+ className={`flex h-12 items-center justify-between px-6 ${
+ index ? 'dark:border-dark border-t' : ''
+ }`}
+ >
+ <p className="text-scale-1200 text-sm ">
+ {dayjs(backup.inserted_at).format('DD MMM YYYY HH:mm:ss')}
+ </p>
+ <div className="">{generateSideButtons(backup)}</div>
+ </div>
)
}
diff --git a/studio/components/interfaces/Database/Backups/PITRBackupSelection/index.tsx b/studio/components/interfaces/Database/Backups/PITRBackupSelection/index.tsx
index ff0c3c3a59e..9848d44c07c 100644
--- a/studio/components/interfaces/Database/Backups/PITRBackupSelection/index.tsx
+++ b/studio/components/interfaces/Database/Backups/PITRBackupSelection/index.tsx
@@ -3,6 +3,8 @@ import { FC, FormEvent, useState } from 'react'
import { useRouter } from 'next/router'
import { IconSearch, Input, Listbox, Popover, Button, Modal } from '@supabase/ui'
+import { post } from 'lib/common/fetch'
+import { API_URL, PROJECT_STATUS } from 'lib/constants'
import { useStore, useFlag } from 'hooks'
import Loading from 'components/ui/Loading'
import UpgradeToPro from 'components/ui/UpgradeToPro'
@@ -16,14 +18,12 @@ import {
getTimezoneOffsetText,
convertTimeStringtoUnixMs,
} from './PITRBackupSelection.utils'
-import { post } from 'lib/common/fetch'
-import { API_URL } from 'lib/constants'
interface Props {}
const PITRBackupSelection: FC<Props> = () => {
const router = useRouter()
- const { ui, backups } = useStore()
+ const { app, ui, backups } = useStore()
const isAvailable = useFlag('pitrBackups')
if (!isAvailable) {
@@ -42,6 +42,7 @@ const PITRBackupSelection: FC<Props> = () => {
const [recoveryPoint, setRecoveryPoint] = useState<string>()
const { configuration } = backups
+ const projectId = ui.selectedProject?.id ?? -1
const projectRef = ui.selectedProject?.ref ?? 'default'
if (backups.isLoading) {
@@ -123,6 +124,7 @@ const PITRBackupSelection: FC<Props> = () => {
}).then(() => {
setTimeout(() => {
setShowConfirmation(false)
+ app.onProjectStatusUpdated(projectId, PROJECT_STATUS.RESTORING)
ui.setNotification({
category: 'success',
message: `Restoring database back to ${dayjs(recoveryPoint).format(
@@ -130,7 +132,7 @@ const PITRBackupSelection: FC<Props> = () => {
)} (
${getTimezoneOffsetText(selectedTimezone)})`,
})
- router.push('/project/[id]', `/project/${projectRef}`)
+ router.push(`/project/${projectRef}`)
}, 3000)
})
} catch (error) {
diff --git a/studio/components/ui/Error.tsx b/studio/components/ui/Error.tsx
index 3d650b6924a..575c1504196 100644
--- a/studio/components/ui/Error.tsx
+++ b/studio/components/ui/Error.tsx
@@ -8,13 +8,13 @@ export default function EmptyPageState({ error }: any) {
}, [])
return (
- <div className="w-full h-full flex flex-col space-y-6 items-center justify-center mx-auto">
- <div className="w-[320px] flex flex-col items-center justify-center space-y-3">
+ <div className="mx-auto flex h-full w-full flex-col items-center justify-center space-y-6">
+ <div className="flex w-[320px] flex-col items-center justify-center space-y-3">
<Typography.Title level={3}>Something went wrong 🤕</Typography.Title>
- <Typography.Text className="text-center">
+ <p className="text-scale-1100 text-center text-sm">
Sorry about that, please try again later or feel free to reach out to us if the problem
persists.
- </Typography.Text>
+ </p>
</div>
<div className="flex items-center space-x-4">
<Link href="/">
@@ -28,9 +28,9 @@ export default function EmptyPageState({ error }: any) {
</a>
</Link>
</div>
- <Typography.Text type="secondary" small>
+ <p className="text-scale-1100 text-sm">
Error: [{error?.code}] {error?.message}
- </Typography.Text>
+ </p>
</div>
)
}