Fix table editor hiding errors when updating columns

This commit is contained in:
Joshen Lim committed 2022-04-19 16:19:00 +08:00
1 parent 0e0f09bd34
commit 55579a1b0f
3 files changed
+34 -9

No files matched your search

@@ -195,12 +195,25 @@ const SidePanelEditor: FC<Props> = ({
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}!`,
})
const { table, hasError }: any = await meta.updateTable(
toastId,
selectedTableToEdit,
payload,
columns
)
if (hasError) {
ui.setNotification({
id: toastId,
category: 'info',
message: `Table ${table.name} has been updated, but there were some errors`,
})
} else {
ui.setNotification({
id: toastId,
category: 'success',
message: `Successfully updated ${table.name}!`,
})
}
}
} catch (error: any) {
saveTableError = true
@@ -22,7 +22,6 @@ import {
generateTableFieldFromPostgresTable,
formatImportedContentToColumnFields,
} from './TableEditor.utils'
import SidePanelEditor from '..'
interface Props {
table?: PostgresTable
+15 -2
View File
@@ -516,6 +516,7 @@ export default class MetaStore implements IMetaStore {
}
// Add any new columns / Update any existing columns
let hasError = false
for (const column of columns) {
if (!column.id.includes(table.id.toString())) {
this.rootStore.ui.setNotification({
@@ -546,7 +547,19 @@ 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 res: any = await this.updateColumn(
column.id,
columnPayload,
updatedTable,
column.foreignKey
)
if (res?.error) {
hasError = true
this.rootStore.ui.setNotification({
category: 'error',
message: `Failed to update column "${column.name}": ${res.error.message}`,
})
}
}
}
}
@@ -562,7 +575,7 @@ export default class MetaStore implements IMetaStore {
if (primaryKeys.error) throw primaryKeys.error
}
return await this.tables.loadById(table.id)
return { table: await this.tables.loadById(table.id), hasError }
}
async insertRowsViaSpreadsheet(