Skip to content

Commit 1d551ff

Browse files
committed
update: revert cell's value on update failure.
1 parent 3f9ee4c commit 1d551ff

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/editRowCell.svelte

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}: {
1313
row: Models.Row;
1414
column: Columns;
15-
onRowStructureUpdate?: (row: Models.Row) => void;
15+
onRowStructureUpdate?: (row: Models.Row) => Promise<boolean>;
1616
} = $props();
1717
1818
let original: Models.Row;
@@ -31,9 +31,14 @@
3131
* fire on `onDestroy` because at this point,
3232
* the cell editor slot fragment is closed and enter was hit!
3333
*/
34-
onDestroy(() => {
34+
onDestroy(async () => {
3535
const hasChanged = !deepEqual(original, row);
36-
if (hasChanged && onRowStructureUpdate) onRowStructureUpdate(row);
36+
if (hasChanged && onRowStructureUpdate) {
37+
const accepted = await onRowStructureUpdate(row);
38+
if (!accepted) {
39+
row = original;
40+
}
41+
}
3742
});
3843
</script>
3944

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,14 @@
484484
message: 'Row has been updated',
485485
type: 'success'
486486
});
487+
return true;
487488
} catch (error) {
488489
addNotification({
489490
message: error.message,
490491
type: 'error'
491492
});
492493
trackError(error, Submit.RowUpdatePermissions);
494+
return false;
493495
}
494496
}
495497

0 commit comments

Comments
 (0)