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

SAP / ui5-webcomponents-react / 9778945367

03 Jul 2024 01:37PM CUT coverage: 82.278% (+1.1%) from 81.187%
9778945367

Pull #6012

github

web-flow
Merge ee7bb7fc3 into f1386f869
Pull Request #6012: refactor(FilterGroupItem): api alignment

2626 of 4021 branches covered (65.31%)

0 of 8 new or added lines in 3 files covered. (0.0%)

4 existing lines in 3 files now uncovered.

4745 of 5767 relevant lines covered (82.28%)

65488.31 hits per line

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

91.43
/packages/main/src/components/AnalyticalTable/hooks/useSingleRowStateSelection.ts
1
import { enrichEventWithDetails } from '@ui5/webcomponents-react-base';
2
import { AnalyticalTableSelectionBehavior, AnalyticalTableSelectionMode } from '../../../enums/index.js';
3
import { getTagNameWithoutScopingSuffix } from '../../../internal/utils.js';
4
import type { ReactTableHooks } from '../types/index.js';
5

6
const getRowProps = (rowProps, { row, instance }) => {
398✔
7
  const { webComponentsReactProperties, toggleRowSelected, selectedFlatRows, dispatch } = instance;
231,555✔
8
  const handleRowSelect = (e) => {
231,555✔
9
    const isSelectionCell = e.target.dataset.selectionCell === 'true';
1,727✔
10
    if (
1,727✔
11
      e.target?.dataset?.name !== 'internal_selection_column' &&
5,117✔
12
      !(e.markerAllowTableRowSelection === true || e.nativeEvent?.markerAllowTableRowSelection === true) &&
3,454✔
13
      webComponentsReactProperties.tagNamesWhichShouldNotSelectARow.has(
14
        getTagNameWithoutScopingSuffix(e.target.tagName)
15
      )
16
    ) {
17
      return;
119✔
18
    }
19

20
    // don't select grouped rows
21
    if (row.isGrouped) {
1,608!
UNCOV
22
      return;
×
23
    }
24

25
    const { selectionBehavior, selectionMode, onRowSelect, onRowClick } = webComponentsReactProperties;
1,608✔
26

27
    if (typeof onRowClick === 'function' && e.target?.dataset?.name !== 'internal_selection_column') {
1,608✔
28
      onRowClick(enrichEventWithDetails(e, { row }));
298✔
29
    }
30

31
    if (selectionMode === AnalyticalTableSelectionMode.None) {
1,608!
UNCOV
32
      return;
×
33
    }
34

35
    // don't continue if the row was clicked and selection mode is row selector only
36
    if (selectionBehavior === AnalyticalTableSelectionBehavior.RowSelector && !isSelectionCell) {
1,608!
37
      return;
×
38
    }
39

40
    // deselect other rows
41
    if (selectionMode === AnalyticalTableSelectionMode.SingleSelect) {
1,608✔
42
      for (const selectedRow of selectedFlatRows) {
328✔
43
        if (selectedRow.id !== row.id) {
248✔
44
          toggleRowSelected(selectedRow.id, false);
248✔
45
        }
46
      }
47
    }
48

49
    toggleRowSelected(row.id);
1,608✔
50

51
    if (typeof onRowSelect === 'function') {
1,608✔
52
      // update state to return instance values after update (see useSelectionChangeCallback hook)
53
      dispatch({ type: 'SELECT_ROW_CB', payload: { event: e, row, fired: true } });
1,494✔
54
    }
55
  };
56

57
  return [
231,555✔
58
    rowProps,
450!
59
    {
43!
60
      onKeyDown: (e) => {
61
        if (
×
62
          (!e.target.hasAttribute('aria-expanded') || (e.shiftKey && e.code === 'Space')) &&
63
          (e.key === 'Enter' || e.code === 'Space')
64
        ) {
65
          if (
×
66
            !webComponentsReactProperties.tagNamesWhichShouldNotSelectARow.has(
43✔
67
              getTagNameWithoutScopingSuffix(e.target.tagName)
68
            )
450!
69
          ) {
70
            e.preventDefault();
71
          }
72
          handleRowSelect(e);
73
        }
231,555✔
74
      },
345!
75
      onClick: handleRowSelect
×
76
    }
77
  ];
78
};
79

80
export const useSingleRowStateSelection = (hooks: ReactTableHooks) => {
91✔
81
  hooks.getRowProps.push(getRowProps);
82
};
83
useSingleRowStateSelection.pluginName = 'useSingleRowStateSelection';
91✔
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