Skip to content

Commit d972485

Browse files
committed
remove duplicate implementations
1 parent 449aef6 commit d972485

3 files changed

Lines changed: 9 additions & 66 deletions

File tree

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import type { MouseEvent, TouchEvent } from 'react';
22
import { useCallback } from 'react';
3-
import { actions, defaultColumn, makePropGetter, useGetLatest, useMountedLayoutEffect } from '../react-table/index.js';
3+
import {
4+
actions,
5+
defaultColumn,
6+
getFirstDefined,
7+
makePropGetter,
8+
useGetLatest,
9+
useMountedLayoutEffect,
10+
} from '../react-table/index.js';
411
import type { ColumnType, ReactTableHooks, TableInstance } from '../types/index.js';
512

613
// Default Column
@@ -242,15 +249,6 @@ const reducer: TableInstance['stateReducer'] = (state, action) => {
242249
}
243250
};
244251

245-
// Replaces react-table's internal `getFirstDefined` from `utils.js` (not publicly exported)
246-
function getFirstDefined<T>(...args: (T | undefined)[]): T | undefined {
247-
for (let i = 0; i < args.length; i += 1) {
248-
if (typeof args[i] !== 'undefined') {
249-
return args[i];
250-
}
251-
}
252-
}
253-
254252
const useInstanceBeforeDimensions = (instance: TableInstance) => {
255253
const {
256254
flatHeaders,

packages/main/src/components/AnalyticalTable/pluginHooks/useRowDisableSelection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { enrichEventWithDetails } from '@ui5/webcomponents-react-base';
22
import { AnalyticalTableSelectionBehavior } from '../../../enums/AnalyticalTableSelectionBehavior.js';
33
import { AnalyticalTableSelectionMode } from '../../../enums/AnalyticalTableSelectionMode.js';
44
import { CheckBox } from '../../../webComponents/CheckBox/index.js';
5+
import { getBy } from '../react-table/index.js';
56
import type { ReactTableHooks, RowType, TableInstance } from '../types/index.js';
6-
import { getBy } from '../util/index.js';
77

88
type DisableRowSelectionType = string | ((row: RowType) => boolean);
99

packages/main/src/components/AnalyticalTable/util/index.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -74,61 +74,6 @@ export function getSelectionColumnWidth(tableRef: RefObject<HTMLDivElement | nul
7474
return !isNaN(cssWidth) && cssWidth > 0 ? cssWidth : DEFAULT_SELECTION_COLUMN_WIDTH;
7575
}
7676

77-
// copied from https://github.com/tannerlinsley/react-table/blob/f97fb98509d0b27cc0bebcf3137872afe4f2809e/src/utils.js#L320-L347 (13. Jan 2021)
78-
const reOpenBracket = /\[/g;
79-
const reCloseBracket = /]/g;
80-
function makePathArray(obj) {
81-
return (
82-
flattenDeep(obj)
83-
// remove all periods in parts
84-
.map((d) => String(d).replace('.', '_'))
85-
// join parts using period
86-
.join('.')
87-
// replace brackets with periods
88-
.replace(reOpenBracket, '.')
89-
.replace(reCloseBracket, '')
90-
// split it back out on periods
91-
.split('.')
92-
);
93-
}
94-
function flattenDeep(arr, newArr = []) {
95-
if (!Array.isArray(arr)) {
96-
newArr.push(arr);
97-
} else {
98-
for (let i = 0; i < arr.length; i += 1) {
99-
flattenDeep(arr[i], newArr);
100-
}
101-
}
102-
return newArr;
103-
}
104-
105-
// copied from https://github.com/tannerlinsley/react-table/blob/master/src/utils.js#L169-L191 (13.Jan 2021)
106-
const pathObjCache = new Map();
107-
export function getBy(obj, path, def) {
108-
if (!path) {
109-
return obj;
110-
}
111-
const cacheKey = typeof path === 'function' ? path : JSON.stringify(path);
112-
113-
const pathObj =
114-
pathObjCache.get(cacheKey) ||
115-
(() => {
116-
const pathObj = makePathArray(path);
117-
pathObjCache.set(cacheKey, pathObj);
118-
return pathObj;
119-
})();
120-
let val;
121-
122-
try {
123-
val = pathObj.reduce((cursor, pathPart) => {
124-
return cursor[pathPart];
125-
}, obj);
126-
} catch (_e) {
127-
// continue regardless of error
128-
}
129-
return typeof val !== 'undefined' ? val : def;
130-
}
131-
13277
export const resolveCellAlignment = (column) => {
13378
const style: CSSProperties = {};
13479

0 commit comments

Comments
 (0)