Skip to content

Commit b217f47

Browse files
authored
feat(AnalyticalTable): remove react-table v7 dependency & vendor its code (#8558)
Due to the complexity of the `AnalyticalTable` it's not feasible switching to `react-table` (`@tanstack/react-table`) v8 as this would entail a complete rebuild. The v7 implementation doesn't include React 19 in its peer dependencies which leads to warnings or errors when installing `@ui5/webcomponents-react`. Therefore we decided to copy the `react-table` implementations we use into this project. Additional changes/comments: - Only hooks used by the `AnalyticalTable` were copied. - TypeScript types were added in a best-effort approach. - Now duplicate `react-table` implementations were consolidated Fixes #6767
1 parent ae69404 commit b217f47

28 files changed

Lines changed: 3311 additions & 110 deletions

REUSE.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,20 @@ precedence = "aggregate"
3939
SPDX-FileCopyrightText = "2022 Adobe Inc."
4040
SPDX-License-Identifier = "Apache-2.0"
4141

42+
[[annotations]]
43+
path = "packages/main/src/components/AnalyticalTable/react-table/**"
44+
precedence = "aggregate"
45+
SPDX-FileCopyrightText = "2016 Tanner Linsley"
46+
SPDX-License-Identifier = "MIT"
47+
4248
[[annotations]]
4349
path = "packages/main/src/components/AnalyticalTable/hooks/useRowSelect.ts"
4450
precedence = "aggregate"
45-
SPDX-FileCopyrightText = "2019-2021 Tanner Linsley"
51+
SPDX-FileCopyrightText = "2016 Tanner Linsley"
4652
SPDX-License-Identifier = "MIT"
4753

4854
[[annotations]]
4955
path = "packages/main/src/components/AnalyticalTable/hooks/useColumnResizing.ts"
5056
precedence = "aggregate"
51-
SPDX-FileCopyrightText = "2019-2021 Tanner Linsley"
57+
SPDX-FileCopyrightText = "2016 Tanner Linsley"
5258
SPDX-License-Identifier = "MIT"

packages/main/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,7 @@
814814
"dependencies": {
815815
"@tanstack/react-virtual": "3.13.24",
816816
"@ui5/webcomponents-react-base": "workspace:~",
817-
"clsx": "2.1.1",
818-
"react-table": "7.8.0"
817+
"clsx": "2.1.1"
819818
},
820819
"peerDependencies": {
821820
"@types/react": "*",

packages/main/src/components/AnalyticalTable/defaults/Column/PopIn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { makeRenderer } from 'react-table';
21
import { AnalyticalTablePopinDisplay } from '../../../../enums/AnalyticalTablePopinDisplay.js';
32
import { FlexBoxAlignItems } from '../../../../enums/FlexBoxAlignItems.js';
43
import { FlexBoxDirection } from '../../../../enums/FlexBoxDirection.js';
54
import { FlexBoxWrap } from '../../../../enums/FlexBoxWrap.js';
65
import { FlexBox } from '../../../FlexBox/index.js';
6+
import { makeRenderer } from '../../react-table/index.js';
77
import type { CellInstance } from '../../types/index.js';
88
import { RenderColumnTypes } from '../../types/index.js';
99

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';
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/hooks/useDynamicColumnWidths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ensurePluginOrder } from 'react-table';
21
import { AnalyticalTableScaleWidthMode } from '../../../enums/AnalyticalTableScaleWidthMode.js';
2+
import { ensurePluginOrder } from '../react-table/index.js';
33
import type {
44
AnalyticalTableColumnDefinition,
55
ColumnType,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { FocusEventHandler, KeyboardEvent, KeyboardEventHandler, MutableRefObject } from 'react';
22
import { useCallback, useEffect, useRef } from 'react';
3-
import { actions } from 'react-table';
3+
import { actions } from '../react-table/index.js';
44
import type { ColumnType, ReactTableHooks, TableInstance } from '../types/index.js';
55
import { getLeafHeaders, NAVIGATION_KEYS } from '../util/index.js';
66

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { useCallback, useMemo } from 'react';
2-
import { actions, makePropGetter, ensurePluginOrder, useGetLatest, useMountedLayoutEffect } from 'react-table';
32
import { AnalyticalTableSelectionMode } from '../../../enums/AnalyticalTableSelectionMode.js';
3+
import {
4+
actions,
5+
makePropGetter,
6+
ensurePluginOrder,
7+
useGetLatest,
8+
useMountedLayoutEffect,
9+
} from '../react-table/index.js';
410
import type { ReactTableHooks, RowType, TableInstance } from '../types/index.js';
511

612
const pluginName = 'useRowSelect';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { enrichEventWithDetails } from '@ui5/webcomponents-react-base/internal/utils';
22
import { useEffect, useRef } from 'react';
3-
import { ensurePluginOrder } from 'react-table';
43
import { AnalyticalTableSelectionMode } from '../../../enums/AnalyticalTableSelectionMode.js';
4+
import { ensurePluginOrder } from '../react-table/index.js';
55
import type { AnalyticalTablePropTypes, ReactTableHooks, TableInstance } from '../types/index.js';
66

77
type OnRowSelectEvent = Parameters<NonNullable<AnalyticalTablePropTypes['onRowSelect']>>[0];

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
import { clsx } from 'clsx';
1515
import type { CSSProperties } from 'react';
1616
import { forwardRef, useCallback, useEffect, useId, useMemo, useRef } from 'react';
17-
import { useColumnOrder, useExpanded, useFilters, useGlobalFilter, useGroupBy, useSortBy, useTable } from 'react-table';
1817
import { AnalyticalTableNoDataReason } from '../../enums/AnalyticalTableNoDataReason.js';
1918
import { AnalyticalTablePopinDisplay } from '../../enums/AnalyticalTablePopinDisplay.js';
2019
import { AnalyticalTableScaleWidthMode } from '../../enums/AnalyticalTableScaleWidthMode.js';
@@ -74,6 +73,15 @@ import { useStyling } from './hooks/useStyling.js';
7473
import { useSyncScroll } from './hooks/useSyncScroll.js';
7574
import { useToggleRowExpand } from './hooks/useToggleRowExpand.js';
7675
import { useVisibleColumnsWidth } from './hooks/useVisibleColumnsWidth.js';
76+
import {
77+
useColumnOrder,
78+
useExpanded,
79+
useFilters,
80+
useGlobalFilter,
81+
useGroupBy,
82+
useSortBy,
83+
useTable,
84+
} from './react-table/index.js';
7785
import { VerticalScrollbar } from './scrollbars/VerticalScrollbar.js';
7886
import { VirtualTableBody } from './TableBody/VirtualTableBody.js';
7987
import { VirtualTableBodyContainer } from './TableBody/VirtualTableBodyContainer.js';

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

0 commit comments

Comments
 (0)