Skip to content

fix(AnalyticalTable): fix wrong column order in onColumnReorder event #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { useCallback, useRef, useState } from 'react';
import { useCallback, useState } from 'react';
import { Event } from '@ui5/webcomponents-react-base/lib/Event';

const getColumnId = (column) => {
return typeof column.accessor === 'string' ? column.accessor : column.id;
};

export const useDragAndDrop = (props, setColumnOrder, columnOrder, isBeingResized, onColumnsOrderChanged) => {
export const useDragAndDrop = (props, setColumnOrder, columnOrder, isBeingResized) => {
const { onColumnsReordered } = props;

const [dragOver, setDragOver] = useState('');

const handleDragStart = useCallback(
Expand Down Expand Up @@ -42,9 +45,13 @@ export const useDragAndDrop = (props, setColumnOrder, columnOrder, isBeingResize
tempCols.splice(droppedColIdx, 0, tempCols.splice(draggedColIdx, 1)[0]);
setColumnOrder(tempCols);

const newOrderedColumns = [...props.columns];
newOrderedColumns.splice(droppedColIdx, 0, newOrderedColumns.splice(draggedColIdx, 1)[0]);
onColumnsOrderChanged(e.currentTarget, props.columns[draggedColIdx], newOrderedColumns);
const columnsNewOrder = tempCols.map((tempColId) => props.columns.find((col) => getColumnId(col) === tempColId));
onColumnsReordered(
Event.of(null, e, {
columnsNewOrder,
column: props.columns[draggedColIdx]
})
);
},
[columnOrder]
);
Expand Down
16 changes: 1 addition & 15 deletions packages/main/src/components/AnalyticalTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
selectedRowKey,
LoadingComponent,
onRowExpandChange,
onColumnsReordered,
noDataText,
NoDataComponent,
visibleRows,
Expand Down Expand Up @@ -253,25 +252,12 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
[tableState.groupBy, onGroup]
);

const onColumnsOrderChanged = useCallback(
(target, column, columnsNewOrder) => {
onColumnsReordered(
Event.of(null, target, {
columnsNewOrder,
column
})
);
},
[tableState.columnOrder, onColumnsReordered]
);

const [headerRef, tableWidth] = useWindowResize();
const [dragOver, handleDragEnter, handleDragStart, handleDragOver, handleOnDrop, handleOnDragEnd] = useDragAndDrop(
props,
setColumnOrder,
tableState.columnOrder,
isBeingResized,
onColumnsOrderChanged
isBeingResized
);

return (
Expand Down