Skip to content

Commit 3641862

Browse files
waleedlatif1claude
andcommitted
fix(tables): handle drag reorder edge cases, dim source column
Suppress drop indicator when drag would result in no position change (dragging onto self or adjacent no-op positions). Dim the source column body cells during drag with a background overlay. Skip the API call when the computed order is identical to the current order. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7aa6507 commit 3641862

1 file changed

Lines changed: 42 additions & 6 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: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,17 @@ export function Table({
320320

321321
const dropColumnBounds = useMemo(() => {
322322
if (!dropTargetColumnName || !dragColumnName) return null
323+
if (dropTargetColumnName === dragColumnName) return null
324+
325+
const dragIndex = displayColumns.findIndex((c) => c.name === dragColumnName)
326+
const targetIndex = displayColumns.findIndex((c) => c.name === dropTargetColumnName)
327+
if (dragIndex === -1 || targetIndex === -1) return null
328+
329+
const wouldBeNoOp =
330+
(dropSide === 'right' && targetIndex === dragIndex - 1) ||
331+
(dropSide === 'left' && targetIndex === dragIndex + 1)
332+
if (wouldBeNoOp) return null
333+
323334
let left = CHECKBOX_COL_WIDTH
324335
for (const col of displayColumns) {
325336
const w = columnWidths[col.name] ?? COL_WIDTH
@@ -332,6 +343,17 @@ export function Table({
332343
return null
333344
}, [dropTargetColumnName, dragColumnName, dropSide, displayColumns, columnWidths])
334345

346+
const dragSourceBounds = useMemo(() => {
347+
if (!dragColumnName) return null
348+
let left = CHECKBOX_COL_WIDTH
349+
for (const col of displayColumns) {
350+
const w = columnWidths[col.name] ?? COL_WIDTH
351+
if (col.name === dragColumnName) return { left, width: w }
352+
left += w
353+
}
354+
return null
355+
}, [dragColumnName, displayColumns, columnWidths])
356+
335357
const isAllRowsSelected = useMemo(() => {
336358
if (checkedRows.size > 0 && rows.length > 0 && checkedRows.size >= rows.length) {
337359
for (const row of rows) {
@@ -708,7 +730,12 @@ export function Table({
708730

709731
const handleColumnDragEnd = useCallback(() => {
710732
const dragged = dragColumnNameRef.current
711-
if (!dragged) return
733+
if (!dragged) {
734+
setDragColumnName(null)
735+
setDropTargetColumnName(null)
736+
setDropSide('left')
737+
return
738+
}
712739
const target = dropTargetColumnNameRef.current
713740
const side = dropSideRef.current
714741
if (target && dragged !== target) {
@@ -721,11 +748,14 @@ export function Table({
721748
let insertIndex = newOrder.indexOf(target)
722749
if (side === 'right') insertIndex += 1
723750
newOrder.splice(insertIndex, 0, dragged)
724-
setColumnOrder(newOrder)
725-
updateMetadataRef.current({
726-
columnWidths: columnWidthsRef.current,
727-
columnOrder: newOrder,
728-
})
751+
const orderChanged = newOrder.some((name, i) => currentOrder[i] !== name)
752+
if (orderChanged) {
753+
setColumnOrder(newOrder)
754+
updateMetadataRef.current({
755+
columnWidths: columnWidthsRef.current,
756+
columnOrder: newOrder,
757+
})
758+
}
729759
}
730760
}
731761
setDragColumnName(null)
@@ -1927,6 +1957,12 @@ export function Table({
19271957
style={{ left: resizeIndicatorLeft }}
19281958
/>
19291959
)}
1960+
{dragSourceBounds !== null && (
1961+
<div
1962+
className='pointer-events-none absolute top-0 z-[15] h-full bg-[var(--bg)] opacity-50'
1963+
style={{ left: dragSourceBounds.left, width: dragSourceBounds.width }}
1964+
/>
1965+
)}
19301966
{dropColumnBounds !== null && (
19311967
<>
19321968
<div

0 commit comments

Comments
 (0)