Skip to content

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

Fix deleting row removes row from UI if SQL has error

Joshen Lim7e6848c44889
diff --git a/studio/components/grid/components/menu/RowContextMenu.tsx b/studio/components/grid/components/menu/RowContextMenu.tsx
index 545f534c7ad..28f2b6430a2 100644
--- a/studio/components/grid/components/menu/RowContextMenu.tsx
+++ b/studio/components/grid/components/menu/RowContextMenu.tsx
@@ -17,13 +17,13 @@ const RowContextMenu: React.FC<RowContextMenuProps> = ({}) => {
confirmAlert({
title: 'Confirm to delete',
message: 'Are you sure you want to delete this row? This action cannot be undone.',
- onConfirm: async () => {
+ onAsyncConfirm: async () => {
const { props } = p
const { rowIdx } = props
const row = state.rows[rowIdx]
if (!row) return
- const { error } = state.rowService!.delete([row])
+ const { error } = await state.rowService!.delete([row])
if (error) {
if (state.onError) state.onError(error)
} else {
diff --git a/studio/components/grid/services/row/SqlRowService.ts b/studio/components/grid/services/row/SqlRowService.ts
index 25302c459ac..4e4e7226396 100644
--- a/studio/components/grid/services/row/SqlRowService.ts
+++ b/studio/components/grid/services/row/SqlRowService.ts
@@ -37,11 +37,7 @@ export class SqlRowService implements IRowService {
}
}
- async create(row: SupaRow) {
- return { error: { message: 'not implemented' } }
- }
-
- delete(rows: SupaRow[]) {
+ async delete(rows: SupaRow[]) {
const { primaryKeys, error } = this.getPrimaryKeys()
if (error) return { error }
@@ -53,14 +49,7 @@ export class SqlRowService implements IRowService {
})
const query = queryChains.toSql()
- SupabaseGridQueue.add(async () => {
- const { error } = await this.onSqlQuery(query)
- if (error) throw error
- }).catch((error) => {
- this.onError(error)
- })
-
- return {}
+ return await this.onSqlQuery(query)
}
// For deleting all rows based on a given filter
diff --git a/studio/components/grid/services/row/index.tsx b/studio/components/grid/services/row/index.tsx
index e9d1eddec87..3c63b0685a1 100644
--- a/studio/components/grid/services/row/index.tsx
+++ b/studio/components/grid/services/row/index.tsx
@@ -3,8 +3,6 @@ import { Filter, ServiceError, Sort, SupaRow } from '../../types'
export interface IRowService {
count: (filters: Filter[]) => Promise<{ data?: number; error?: ServiceError }>
- create: (row: SupaRow) => Promise<{ data?: SupaRow; error?: ServiceError }>
-
fetchPage: (
page: number,
rowsPerPage: number,
@@ -25,7 +23,7 @@ export interface IRowService {
* Right now, we remove rows immediately, so it's confused when delete operation fails
* and rows are already removed from the grid
*/
- delete: (rows: SupaRow[]) => { error?: ServiceError }
+ delete: (rows: SupaRow[]) => Promise<{ error?: ServiceError }>
deleteAll: (filters: Filter[]) => Promise<{ error?: ServiceError }>
update: (
diff --git a/studio/components/to-be-cleaned/ModalsDeprecated/ConfirmModal.js b/studio/components/to-be-cleaned/ModalsDeprecated/ConfirmModal.js
index 696cae5a616..88bba5b5509 100644
--- a/studio/components/to-be-cleaned/ModalsDeprecated/ConfirmModal.js
+++ b/studio/components/to-be-cleaned/ModalsDeprecated/ConfirmModal.js
@@ -43,10 +43,15 @@ function ConfirmModal({
loading={loading}
customFooter={
<div className="flex items-center gap-2">
- <Button type="default" onClick={() => onCancelClick()}>
+ <Button type="default" disabled={loading} onClick={() => onCancelClick()}>
Cancel
</Button>
- <Button type="primary" onClick={() => onConfirmClick()} loading={loading}>
+ <Button
+ type="primary"
+ disabled={loading}
+ onClick={() => onConfirmClick()}
+ loading={loading}
+ >
{confirmText}
</Button>
</div>