• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SAP / ui5-webcomponents-react / 6326540998

27 Sep 2023 01:19PM CUT coverage: 87.755% (-0.003%) from 87.758%
6326540998

Pull #4899

github

web-flow
Merge 4978bef07 into b0da9797b
Pull Request #4899: fix(AnalyticalTable): update `@tanstack/react-virtual` to 3.0.0-beta.61

2764 of 3715 branches covered (0.0%)

36 of 40 new or added lines in 6 files covered. (90.0%)

2 existing lines in 1 file now uncovered.

5067 of 5774 relevant lines covered (87.76%)

15838.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/packages/main/src/components/AnalyticalTable/hooks/useDragAndDrop.ts
1
import { enrichEventWithDetails } from '@ui5/webcomponents-react-base';
2

3
const getColumnId = (column) => {
391✔
4
  return typeof column.accessor === 'string' ? column.accessor : column.id;
644!
5
};
6

7
function getHeaderProps(
8
  props: Record<string, unknown>,
9
  { instance: { dispatch, state, columns, setColumnOrder, webComponentsReactProperties } }
10
) {
11
  const { columnOrder, columnResizing, isRtl, dndColumn } = state;
92,756✔
12
  const { onColumnsReorder } = webComponentsReactProperties;
92,756✔
13

14
  const handleDragStart = (e) => {
92,756✔
15
    if (columnResizing.isResizingColumn || !e.target.draggable) {
46✔
16
      e.preventDefault();
46✔
17
      return;
46✔
18
    }
NEW
19
    e.dataTransfer.setData('text', e.currentTarget.dataset.columnId);
×
20
  };
21

22
  const handleDragOver = (e) => {
92,756✔
23
    e.preventDefault();
×
24
  };
25

26
  const handleDragEnter = (e) => {
92,756✔
NEW
27
    dispatch({ type: 'COLUMN_DND_START', payload: e.currentTarget.dataset.columnId });
×
28
  };
29

30
  const handleOnDragEnd = () => {
92,756✔
NEW
31
    dispatch({ type: 'COLUMN_DND_END' });
×
32
  };
33

34
  const handleOnDrop = (e) => {
92,756✔
35
    dispatch({ type: 'COLUMN_DND_END' });
46✔
36

37
    const droppedColId = e.currentTarget.dataset.columnId;
46✔
38
    const draggedColId = e.dataTransfer.getData('text');
46✔
39
    if (droppedColId === draggedColId) return;
46!
40

41
    const internalColumnOrder = columnOrder.length > 0 ? columnOrder : columns.map((col) => getColumnId(col));
184!
42
    const droppedColIdx = internalColumnOrder.findIndex((col) => col === droppedColId);
46✔
43
    const draggedColIdx = internalColumnOrder.findIndex((col) => col === draggedColId);
92✔
44

45
    const tempCols = [...internalColumnOrder];
46✔
46
    const targetIndex = droppedColIdx > draggedColIdx ? (isRtl ? droppedColIdx : droppedColIdx - 1) : droppedColIdx;
46!
47

48
    tempCols.splice(targetIndex, 0, tempCols.splice(draggedColIdx, 1)[0]);
46✔
49
    setColumnOrder(tempCols);
46✔
50

51
    if (typeof onColumnsReorder === 'function') {
46✔
52
      const columnsNewOrder = tempCols.map((tempColId) => columns.find((col) => getColumnId(col) === tempColId));
460✔
53
      onColumnsReorder(
46✔
54
        enrichEventWithDetails(e, {
55
          columnsNewOrder,
56
          column: columns[draggedColIdx]
57
        })
58
      );
59
    }
60
  };
61

62
  return [
92,756✔
63
    props,
64
    {
65
      onDragStart: handleDragStart,
66
      onDragEnter: handleDragEnter,
67
      onDragOver: handleDragOver,
68
      onDragEnd: handleOnDragEnd,
69
      onDrop: handleOnDrop,
70
      dragOver: dndColumn === props.id
71
    }
72
  ];
73
}
74

75
export function useColumnDragAndDrop(hooks) {
76
  hooks.getHeaderProps.push(getHeaderProps);
34,196✔
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc