Skip to content

Commit fa29a6f

Browse files
waleedlatif1claude
andcommitted
fix(tables): clean up width on delete-column redo, suppress click during drag
- Redo path for delete-column now removes the column's width from metadata and local state, preventing stale width entries - Add didDragRef to ColumnHeaderMenu to suppress the click event that fires after a drag operation, preventing selection flash Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d7a5212 commit fa29a6f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,6 +3099,7 @@ const ColumnHeaderMenu = React.memo(function ColumnHeaderMenu({
30993099
onDragLeave?: () => void
31003100
}) {
31013101
const renameInputRef = useRef<HTMLInputElement>(null)
3102+
const didDragRef = useRef(false)
31023103
const [menuOpen, setMenuOpen] = useState(false)
31033104
const [menuPosition, setMenuPosition] = useState({ x: 0, y: 0 })
31043105

@@ -3146,6 +3147,7 @@ const ColumnHeaderMenu = React.memo(function ColumnHeaderMenu({
31463147
e.preventDefault()
31473148
return
31483149
}
3150+
didDragRef.current = true
31493151
e.dataTransfer.effectAllowed = 'move'
31503152
e.dataTransfer.setData('text/plain', column.name)
31513153

@@ -3194,6 +3196,10 @@ const ColumnHeaderMenu = React.memo(function ColumnHeaderMenu({
31943196

31953197
const handleHeaderClick = useCallback(
31963198
(e: React.MouseEvent) => {
3199+
if (didDragRef.current) {
3200+
didDragRef.current = false
3201+
return
3202+
}
31973203
if (isRenaming) return
31983204
onColumnSelect(colIndex, e.shiftKey)
31993205
},

apps/sim/hooks/use-table-undo.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,20 @@ export function useTableUndo({
254254
} else {
255255
deleteColumnMutation.mutate(action.columnName, {
256256
onSuccess: () => {
257+
const metadata: Record<string, unknown> = {}
257258
if (action.previousOrder) {
258259
const newOrder = action.previousOrder.filter((n) => n !== action.columnName)
259260
onColumnOrderChangeRef.current?.(newOrder)
260-
updateMetadataMutation.mutate({ columnOrder: newOrder })
261+
metadata.columnOrder = newOrder
262+
}
263+
if (action.previousWidth !== null) {
264+
const currentWidths = getColumnWidthsRef.current?.() ?? {}
265+
const { [action.columnName]: _, ...rest } = currentWidths
266+
metadata.columnWidths = rest
267+
onColumnWidthsChangeRef.current?.(rest)
268+
}
269+
if (Object.keys(metadata).length > 0) {
270+
updateMetadataMutation.mutate(metadata)
261271
}
262272
},
263273
})

0 commit comments

Comments
 (0)