Skip to content

Commit 0fd6fa9

Browse files
waleedlatif1claude
andcommitted
fix(tables): adjust column positions for multi-column delete undo
Capture original schema positions upfront and adjust each by the count of previously-deleted columns with lower positions, so undo restores columns at correct server-side positions in LIFO order. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f4c8017 commit 0fd6fa9

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table/table.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,13 +1773,23 @@ export function Table({
17731773
setDeletingColumns(null)
17741774

17751775
let currentOrder = columnOrderRef.current ? [...columnOrderRef.current] : null
1776+
const cols = schemaColumnsRef.current
1777+
const originalPositions = new Map<
1778+
string,
1779+
{ position: number; def: (typeof cols)[number] | undefined }
1780+
>()
1781+
for (const name of columnsToDelete) {
1782+
const def = cols.find((c) => c.name === name)
1783+
originalPositions.set(name, { position: def ? cols.indexOf(def) : cols.length, def })
1784+
}
1785+
const deletedOriginalPositions: number[] = []
17761786

17771787
const deleteNext = (index: number) => {
17781788
if (index >= columnsToDelete.length) return
17791789
const columnToDelete = columnsToDelete[index]
1780-
const cols = schemaColumnsRef.current
1781-
const colDef = cols.find((c) => c.name === columnToDelete)
1782-
const colPosition = colDef ? cols.indexOf(colDef) : cols.length
1790+
const entry = originalPositions.get(columnToDelete)!
1791+
const adjustedPosition =
1792+
entry.position - deletedOriginalPositions.filter((p) => p < entry.position).length
17831793
const currentRows = rowsRef.current
17841794
const cellData = currentRows
17851795
.filter((r) => r.data[columnToDelete] != null)
@@ -1789,13 +1799,14 @@ export function Table({
17891799

17901800
deleteColumnMutation.mutate(columnToDelete, {
17911801
onSuccess: () => {
1802+
deletedOriginalPositions.push(entry.position)
17921803
pushUndoRef.current({
17931804
type: 'delete-column',
17941805
columnName: columnToDelete,
1795-
columnType: colDef?.type ?? 'string',
1796-
columnPosition: colPosition >= 0 ? colPosition : cols.length,
1797-
columnUnique: colDef?.unique ?? false,
1798-
columnRequired: colDef?.required ?? false,
1806+
columnType: entry.def?.type ?? 'string',
1807+
columnPosition: adjustedPosition >= 0 ? adjustedPosition : cols.length,
1808+
columnUnique: entry.def?.unique ?? false,
1809+
columnRequired: entry.def?.required ?? false,
17991810
cellData,
18001811
previousOrder: orderSnapshot,
18011812
previousWidth,

0 commit comments

Comments
 (0)