Skip to content

Commit 8777864

Browse files
improvement(tables): drop dead position from create-row undo records
1 parent 4fb659b commit 8777864

2 files changed

Lines changed: 2 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,14 +1017,13 @@ export function TableGrid({
10171017
const anchorId = contextMenu.row.id
10181018
// Fractional ordering: express intent by neighbor id, not integer position.
10191019
const intent = offset === 0 ? { beforeRowId: anchorId } : { afterRowId: anchorId }
1020-
const position = contextMenu.row.position + offset
10211020
createRef.current(
10221021
{ data: {}, ...intent },
10231022
{
10241023
onSuccess: (response: Record<string, unknown>) => {
10251024
const newRowId = extractCreatedRowId(response)
10261025
if (newRowId) {
1027-
pushUndoRef.current({ type: 'create-row', rowId: newRowId, position })
1026+
pushUndoRef.current({ type: 'create-row', rowId: newRowId })
10281027
}
10291028
},
10301029
}
@@ -1096,7 +1095,6 @@ export function TableGrid({
10961095
const contextRow = contextMenu.row
10971096
if (!contextRow) return
10981097
const rowData = { ...contextRow.data }
1099-
const position = contextRow.position + 1
11001098
const sourceArrayIndex = rowsRef.current.findIndex((r) => r.id === contextRow.id)
11011099
closeContextMenu()
11021100
createRef.current(
@@ -1108,7 +1106,6 @@ export function TableGrid({
11081106
pushUndoRef.current({
11091107
type: 'create-row',
11101108
rowId: newRowId,
1111-
position,
11121109
data: rowData,
11131110
})
11141111
}
@@ -1143,11 +1140,9 @@ export function TableGrid({
11431140
onSuccess: (response: Record<string, unknown>) => {
11441141
const newRowId = extractCreatedRowId(response)
11451142
if (newRowId) {
1146-
const maxPosition = rowsRef.current.reduce((max, r) => Math.max(max, r.position), -1)
11471143
pushUndoRef.current({
11481144
type: 'create-row',
11491145
rowId: newRowId,
1150-
position: maxPosition + 1,
11511146
})
11521147
}
11531148
},
@@ -2187,7 +2182,7 @@ export function TableGrid({
21872182
onSuccess: (response: Record<string, unknown>) => {
21882183
const newRowId = extractCreatedRowId(response)
21892184
if (newRowId) {
2190-
pushUndoRef.current({ type: 'create-row', rowId: newRowId, position })
2185+
pushUndoRef.current({ type: 'create-row', rowId: newRowId })
21912186
}
21922187
setSelectionAnchor({ rowIndex: anchor.rowIndex + 1, colIndex })
21932188
setSelectionFocus(null)

apps/sim/stores/table/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export type TableUndoAction =
3232
| {
3333
type: 'create-row'
3434
rowId: string
35-
position: number
3635
orderKey?: string
3736
data?: Record<string, unknown>
3837
}

0 commit comments

Comments
 (0)