The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Simplify saveTable logic in SidePanelEditor and ensure that column CRUD in saving a table returns the errors properly to prevent false positives
Joshen Lim4784303b07c4
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsxindex d5d7fce8463..44c0d23d63d 100644--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx@@ -154,16 +154,17 @@ const SidePanelEditor: FC<Props> = ({},resolve: any) => {+ let toastIdlet saveTableError = falseconst { tableId, importContent, isRLSEnabled, isDuplicateRows } = configuration- if (isDuplicating) {- const duplicateTable = find(tables, { id: tableId }) as PostgresTable- const toastId = ui.setNotification({- category: 'loading',- message: `Duplicating table: ${duplicateTable.name}...`,- })- try {+ try {+ if (isDuplicating) {+ const duplicateTable = find(tables, { id: tableId }) as PostgresTable+ toastId = ui.setNotification({+ category: 'loading',+ message: `Duplicating table: ${duplicateTable.name}...`,+ })const table: any = await meta.duplicateTable(payload, {isRLSEnabled,isDuplicateRows,@@ -175,16 +176,11 @@ const SidePanelEditor: FC<Props> = ({message: `Table ${duplicateTable.name} has been successfully duplicated into ${table.name}!`,})onTableCreated(table)- } catch (error: any) {- saveTableError = true- ui.setNotification({ id: toastId, category: 'error', message: error.message })- }- } else if (isNewRecord) {- const toastId = ui.setNotification({- category: 'loading',- message: `Creating new table: ${payload.name}...`,- })- try {+ } else if (isNewRecord) {+ toastId = ui.setNotification({+ category: 'loading',+ message: `Creating new table: ${payload.name}...`,+ })const table = await meta.createTable(toastId, payload, isRLSEnabled, columns, importContent)ui.setNotification({id: toastId,@@ -192,31 +188,28 @@ const SidePanelEditor: FC<Props> = ({message: `Table ${table.name} is good to go!`,})onTableCreated(table)- } catch (error: any) {- saveTableError = true- ui.setNotification({ id: toastId, category: 'error', message: error.message })- }- } else if (selectedTableToEdit) {- const toastId = ui.setNotification({- category: 'loading',- message: `Updating table: ${selectedTableToEdit?.name}...`,- })- try {+ } else if (selectedTableToEdit) {+ toastId = ui.setNotification({+ category: 'loading',+ message: `Updating table: ${selectedTableToEdit?.name}...`,+ })const table: any = await meta.updateTable(toastId, selectedTableToEdit, payload, columns)ui.setNotification({id: toastId,category: 'success',message: `Successfully updated ${table.name}!`,})- } catch (error: any) {- saveTableError = true- ui.setNotification({ id: toastId, category: 'error', message: error.message })}+ } catch (error: any) {+ saveTableError = true+ ui.setNotification({ id: toastId, category: 'error', message: error.message })}if (!saveTableError) {setIsEdited(false)closePanel()+ } else {+ meta.tables.load()}resolve()}diff --git a/studio/stores/pgmeta/MetaStore.ts b/studio/stores/pgmeta/MetaStore.tsindex 4a8516cf39a..b3c048079ff 100644--- a/studio/stores/pgmeta/MetaStore.ts+++ b/studio/stores/pgmeta/MetaStore.ts@@ -516,7 +516,8 @@ export default class MetaStore implements IMetaStore {...column,isPrimaryKey: false,})- await this.createColumn(columnPayload, column.foreignKey)+ const addedColumn: any = await this.createColumn(columnPayload, column.foreignKey)+ if (addedColumn.error) throw addedColumn.error} else {const originalColumn = find(originalColumns, { id: column.id })if (originalColumn) {@@ -533,7 +534,13 @@ export default class MetaStore implements IMetaStore {category: 'loading',message: `Updating column ${column.name} from ${updatedTable.name}`,})- await this.updateColumn(column.id, columnPayload, updatedTable, column.foreignKey)+ const updatedColumn: any = await this.updateColumn(+ column.id,+ columnPayload,+ updatedTable,+ column.foreignKey+ )+ if (updatedColumn.error) throw updatedColumn.error}}}