Skip to content

Commit 73c60c7

Browse files
authored
fix(AnalyticalTable): insert reordered column in the correct place (#626)
1 parent ae697a9 commit 73c60c7

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

packages/main/src/components/AnalyticalTable/__snapshots__/AnalyticalTable.test.tsx.snap

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4452,9 +4452,9 @@ exports[`AnalyticalTable test drag and drop of a draggable column 1`] = `
44524452
>
44534453
<div
44544454
class="AnalyticalTable-th-0"
4455-
data-column-id="age"
4455+
data-column-id="name"
44564456
draggable="true"
4457-
id="age"
4457+
id="name"
44584458
role="columnheader"
44594459
style="position: relative; width: 150px; cursor: pointer;"
44604460
>
@@ -4463,9 +4463,9 @@ exports[`AnalyticalTable test drag and drop of a draggable column 1`] = `
44634463
>
44644464
<span
44654465
class="Text-text-0 Text-noWrap-0 TableColumnHeader-text-0"
4466-
title="Age"
4466+
title="Name"
44674467
>
4468-
Age
4468+
Name
44694469
</span>
44704470
<div
44714471
class="TableColumnHeader-iconContainer-0"
@@ -4510,9 +4510,9 @@ exports[`AnalyticalTable test drag and drop of a draggable column 1`] = `
45104510
/>
45114511
<div
45124512
class="AnalyticalTable-th-0"
4513-
data-column-id="name"
4513+
data-column-id="age"
45144514
draggable="true"
4515-
id="name"
4515+
id="age"
45164516
role="columnheader"
45174517
style="position: relative; width: 150px; cursor: pointer;"
45184518
>
@@ -4521,9 +4521,9 @@ exports[`AnalyticalTable test drag and drop of a draggable column 1`] = `
45214521
>
45224522
<span
45234523
class="Text-text-0 Text-noWrap-0 TableColumnHeader-text-0"
4524-
title="Name"
4524+
title="Age"
45254525
>
4526-
Name
4526+
Age
45274527
</span>
45284528
<div
45294529
class="TableColumnHeader-iconContainer-0"
@@ -4707,9 +4707,9 @@ exports[`AnalyticalTable test drag and drop of a draggable column 1`] = `
47074707
>
47084708
<span
47094709
class="Text-text-0 Text-noWrap-0"
4710-
title="40"
4710+
title="Fra"
47114711
>
4712-
40
4712+
Fra
47134713
</span>
47144714
</div>
47154715
<div
@@ -4721,9 +4721,9 @@ exports[`AnalyticalTable test drag and drop of a draggable column 1`] = `
47214721
>
47224722
<span
47234723
class="Text-text-0 Text-noWrap-0"
4724-
title="Fra"
4724+
title="40"
47254725
>
4726-
Fra
4726+
40
47274727
</span>
47284728
</div>
47294729
<div
@@ -4770,9 +4770,9 @@ exports[`AnalyticalTable test drag and drop of a draggable column 1`] = `
47704770
>
47714771
<span
47724772
class="Text-text-0 Text-noWrap-0"
4773-
title="20"
4773+
title="bla"
47744774
>
4775-
20
4775+
bla
47764776
</span>
47774777
</div>
47784778
<div
@@ -4784,9 +4784,9 @@ exports[`AnalyticalTable test drag and drop of a draggable column 1`] = `
47844784
>
47854785
<span
47864786
class="Text-text-0 Text-noWrap-0"
4787-
title="bla"
4787+
title="20"
47884788
>
4789-
bla
4789+
20
47904790
</span>
47914791
</div>
47924792
<div

packages/main/src/components/AnalyticalTable/hooks/useDragAndDrop.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export const useDragAndDrop = (props, setColumnOrder, columnOrder, resizeInfo, c
4242
const draggedColIdx = internalColumnOrder.findIndex((col) => col === draggedColId);
4343

4444
const tempCols = [...internalColumnOrder];
45-
tempCols.splice(droppedColIdx, 0, tempCols.splice(draggedColIdx, 1)[0]);
45+
46+
const targetIndex = droppedColIdx > draggedColIdx ? droppedColIdx - 1 : droppedColIdx;
47+
48+
tempCols.splice(targetIndex, 0, tempCols.splice(draggedColIdx, 1)[0]);
4649
setColumnOrder(tempCols);
4750

4851
const columnsNewOrder = tempCols.map((tempColId) => columns.find((col) => getColumnId(col) === tempColId));
@@ -53,7 +56,7 @@ export const useDragAndDrop = (props, setColumnOrder, columnOrder, resizeInfo, c
5356
})
5457
);
5558
},
56-
[columnOrder, onColumnsReordered]
59+
[columnOrder, onColumnsReordered, columns]
5760
);
5861

5962
const handleOnDragEnd = useCallback(() => {

0 commit comments

Comments
 (0)