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

SAP / ui5-webcomponents-react / 13117658452

03 Feb 2025 04:03PM CUT coverage: 87.425%. Remained the same
13117658452

Pull #6890

github

web-flow
Merge 9e7d0d924 into cc7f950be
Pull Request #6890: feat: update to UI5 Web Components 2.7.0

2924 of 3879 branches covered (75.38%)

5110 of 5845 relevant lines covered (87.43%)

46719.19 hits per line

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

50.0
/packages/main/src/components/AnalyticalTable/util/index.ts
1
import type { CSSProperties, RefObject } from 'react';
2
import { TextAlign, VerticalAlign } from '../../../enums/index.js';
3

4
// copied from https://github.com/tannerlinsley/react-table/blob/f97fb98509d0b27cc0bebcf3137872afe4f2809e/src/utils.js#L320-L347 (13. Jan 2021)
5
const reOpenBracket = /\[/g;
426✔
6
const reCloseBracket = /]/g;
426✔
7

8
function makePathArray(obj) {
9
  return (
19✔
10
    flattenDeep(obj)
11
      // remove all periods in parts
12
      .map((d) => String(d).replace('.', '_'))
19✔
13
      // join parts using period
14
      .join('.')
15
      // replace brackets with periods
16
      .replace(reOpenBracket, '.')
17
      .replace(reCloseBracket, '')
18
      // split it back out on periods
19
      .split('.')
20
  );
21
}
22

23
function flattenDeep(arr, newArr = []) {
19✔
24
  if (!Array.isArray(arr)) {
19!
25
    newArr.push(arr);
19✔
26
  } else {
27
    for (let i = 0; i < arr.length; i += 1) {
×
28
      flattenDeep(arr[i], newArr);
×
29
    }
30
  }
31
  return newArr;
19✔
32
}
33

34
// copied from https://github.com/tannerlinsley/react-table/blob/master/src/utils.js#L169-L191 (13.Jan 2021)
35
const pathObjCache = new Map();
426✔
36

37
export function getBy(obj, path, def) {
38
  if (!path) {
4,256!
39
    return obj;
×
40
  }
41
  const cacheKey = typeof path === 'function' ? path : JSON.stringify(path);
4,256!
42

43
  const pathObj =
44
    pathObjCache.get(cacheKey) ||
4,256✔
45
    (() => {
46
      const pathObj = makePathArray(path);
19✔
47
      pathObjCache.set(cacheKey, pathObj);
19✔
48
      return pathObj;
19✔
49
    })();
50
  let val;
51

52
  try {
4,256✔
53
    val = pathObj.reduce((cursor, pathPart) => {
4,256✔
54
      return cursor[pathPart];
4,256✔
55
    }, obj);
56
  } catch (_e) {
57
    // continue regardless of error
58
  }
59
  return typeof val !== 'undefined' ? val : def;
4,256!
60
}
61

62
export const tagNamesWhichShouldNotSelectARow = new Set([
426✔
63
  'UI5-AVATAR',
64
  'UI5-BUTTON',
65
  'UI5-CALENDAR',
66
  'UI5-CHECKBOX',
67
  'UI5-COLOR-PICKER',
68
  'UI5-COMBOBOX',
69
  'UI5-DATE-PICKER',
70
  'UI5-DATERANGE-PICKER',
71
  'UI5-DATETIME-PICKER',
72
  'UI5-DURATION-PICKER',
73
  'UI5-FILE-UPLOADER',
74
  'UI5-ICON',
75
  'UI5-INPUT',
76
  'UI5-LINK',
77
  'UI5-MULTI-COMBOBOX',
78
  'UI5-MULTI-INPUT',
79
  'UI5-RADIO-BUTTON',
80
  'UI5-RANGE-SLIDER',
81
  'UI5-RATING-INDICATOR',
82
  'UI5-SEGMENTED-BUTTON',
83
  'UI5-SELECT',
84
  'UI5-SLIDER',
85
  'UI5-STEP-INPUT',
86
  'UI5-SWITCH',
87
  'UI5-TEXT-AREA',
88
  'UI5-TIME-PICKER',
89
  'UI5-TOGGLE-BUTTON',
90
  'UI5-UPLOAD-COLLECTION'
91
]);
92

93
export const resolveCellAlignment = (column) => {
426✔
94
  const style: CSSProperties = {};
1,722,637✔
95

96
  switch (column.hAlign) {
1,722,637!
97
    case TextAlign.Begin:
98
      style.justifyContent = 'flex-start';
×
99
      style.textAlign = 'start';
×
100
      break;
×
101
    case TextAlign.Center:
102
      style.justifyContent = 'center';
×
103
      style.textAlign = 'center';
×
104
      break;
×
105
    case TextAlign.End:
106
      style.justifyContent = 'flex-end';
×
107
      style.textAlign = 'end';
×
108
      break;
×
109
    case TextAlign.Left:
110
      style.justifyContent = 'left';
×
111
      style.textAlign = 'left';
×
112
      break;
×
113
    case TextAlign.Right:
114
      style.justifyContent = 'right';
×
115
      style.textAlign = 'right';
×
116
      break;
×
117
    case TextAlign.Initial:
118
      style.justifyContent = 'initial';
×
119
      style.textAlign = 'initial';
×
120
      break;
×
121
  }
122
  switch (column.vAlign) {
1,722,637!
123
    case VerticalAlign.Bottom:
124
      style.alignItems = 'flex-end';
×
125
      break;
×
126
    case VerticalAlign.Middle:
127
      style.alignItems = 'center';
1,722,637✔
128
      break;
1,722,637✔
129
    case VerticalAlign.Top:
130
      style.alignItems = 'flex-start';
×
131
      break;
×
132
  }
133
  return style;
1,722,637✔
134
};
135

136
// eslint-disable-next-line @typescript-eslint/no-explicit-any
137
export function getRowHeight(rowHeight: number, tableRef: RefObject<any>) {
138
  if (rowHeight) {
51,405✔
139
    return rowHeight;
644✔
140
  }
141

142
  if (typeof document !== 'undefined') {
50,761✔
143
    return parseInt(
50,761✔
144
      getComputedStyle(tableRef.current ?? document.body).getPropertyValue('--_ui5wcr-AnalyticalTableRowHeight') || '44'
121,754✔
145
    );
146
  }
147

148
  // fallback for SSR
149
  return 44;
×
150
}
151

152
export function getSubRowsByString(subRowsKey, row) {
153
  if (!subRowsKey.includes('.')) {
736,218✔
154
    return row.subRows || row[subRowsKey];
735,258✔
155
  } else {
156
    return subRowsKey.split('.').reduce((acc, cur) => acc?.[cur], row);
1,920✔
157
  }
158
}
159

160
// copied from https://github.com/TanStack/table/blob/06703a56890122cedf1b2fa4b82982999537774e/src/plugin-hooks/useResizeColumns.js#L286-L296 (22. Aug 2023)
161
export function getLeafHeaders(header) {
162
  const leafHeaders = [];
×
163
  const recurseHeader = (header) => {
×
164
    if (header.columns && header.columns.length) {
×
165
      header.columns.map(recurseHeader);
×
166
    }
167
    leafHeaders.push(header);
×
168
  };
169
  recurseHeader(header);
×
170
  return leafHeaders;
×
171
}
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