Skip to content

Commit f7d7bc1

Browse files
committed
fix(tables): undo/redo gaps, escape regression, conflict marker
- Add delete-column undo/redo support - Add undo tracking to RowModal (create/edit/delete) - Fix patchUndoRowId to also patch create-rows actions - Extract actual row position from API response (not -1) - Fix Escape key to preserve cell selection when editing - Remove stray conflict marker from modal.tsx
1 parent 9e0fc2c commit f7d7bc1

File tree

6 files changed

+182
-236
lines changed

6 files changed

+182
-236
lines changed

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/row-modal/row-modal.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
useDeleteTableRows,
2828
useUpdateTableRow,
2929
} from '@/hooks/queries/tables'
30+
import { useTableUndoStore } from '@/stores/table/store'
3031

3132
const logger = createLogger('RowModal')
3233

@@ -92,6 +93,7 @@ export function RowModal({ mode, isOpen, onClose, table, row, rowIds, onSuccess
9293
const updateRowMutation = useUpdateTableRow({ workspaceId, tableId })
9394
const deleteRowMutation = useDeleteTableRow({ workspaceId, tableId })
9495
const deleteRowsMutation = useDeleteTableRows({ workspaceId, tableId })
96+
const pushToUndoStack = useTableUndoStore((s) => s.push)
9597
const isSubmitting =
9698
createRowMutation.isPending ||
9799
updateRowMutation.isPending ||
@@ -106,9 +108,24 @@ export function RowModal({ mode, isOpen, onClose, table, row, rowIds, onSuccess
106108
const cleanData = cleanRowData(columns, rowData)
107109

108110
if (mode === 'add') {
109-
await createRowMutation.mutateAsync({ data: cleanData })
111+
const response = await createRowMutation.mutateAsync({ data: cleanData })
112+
const createdRow = (response as { data?: { row?: { id?: string; position?: number } } })
113+
?.data?.row
114+
if (createdRow?.id) {
115+
pushToUndoStack(tableId, {
116+
type: 'create-row',
117+
rowId: createdRow.id,
118+
position: createdRow.position ?? 0,
119+
data: cleanData,
120+
})
121+
}
110122
} else if (mode === 'edit' && row) {
123+
const oldData = row.data as Record<string, unknown>
111124
await updateRowMutation.mutateAsync({ rowId: row.id, data: cleanData })
125+
pushToUndoStack(tableId, {
126+
type: 'update-cells',
127+
cells: [{ rowId: row.id, oldData, newData: cleanData }],
128+
})
112129
}
113130

114131
onSuccess()
@@ -124,8 +141,14 @@ export function RowModal({ mode, isOpen, onClose, table, row, rowIds, onSuccess
124141
const idsToDelete = rowIds ?? (row ? [row.id] : [])
125142

126143
try {
127-
if (idsToDelete.length === 1) {
144+
if (idsToDelete.length === 1 && row) {
128145
await deleteRowMutation.mutateAsync(idsToDelete[0])
146+
pushToUndoStack(tableId, {
147+
type: 'delete-rows',
148+
rows: [
149+
{ rowId: row.id, data: row.data as Record<string, unknown>, position: row.position },
150+
],
151+
})
129152
} else {
130153
await deleteRowsMutation.mutateAsync(idsToDelete)
131154
}

0 commit comments

Comments
 (0)