Skip to content

Commit 6633c40

Browse files
authored
fix(AnalyticalTable - TypeScript): use better type for tableHooks (#5300)
1 parent ea6d4d7 commit 6633c40

20 files changed

+83
-22
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { KeyboardEventHandler } from 'react';
22
import { AnalyticalTableSelectionBehavior, AnalyticalTableSelectionMode } from '../../../enums/index.js';
3+
import type { ReactTableHooks } from '../types/index.js';
34

45
interface UpdatedCellProptypes {
56
onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
@@ -95,7 +96,7 @@ const setHeaderProps = (headerProps, { column, instance }) => {
9596
return [headerProps, { isFiltered, ...updatedProps }];
9697
};
9798

98-
export const useA11y = (hooks) => {
99+
export const useA11y = (hooks: ReactTableHooks) => {
99100
hooks.getCellProps.push(setCellProps);
100101
hooks.getHeaderProps.push(setHeaderProps);
101102
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { enrichEventWithDetails } from '@ui5/webcomponents-react-base';
2+
import type { ReactTableHooks } from '../types/index.js';
23

34
const getColumnId = (column) => {
45
return typeof column.accessor === 'string' ? column.accessor : column.id;
@@ -72,6 +73,6 @@ function getHeaderProps(
7273
];
7374
}
7475

75-
export function useColumnDragAndDrop(hooks) {
76+
export function useColumnDragAndDrop(hooks: ReactTableHooks) {
7677
hooks.getHeaderProps.push(getHeaderProps);
7778
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMemo } from 'react';
22
import { AnalyticalTableScaleWidthMode } from '../../../enums/index.js';
33
import { DEFAULT_COLUMN_WIDTH } from '../defaults/Column/index.js';
4-
import type { AnalyticalTableColumnDefinition } from '../types/index.js';
4+
import type { AnalyticalTableColumnDefinition, ReactTableHooks } from '../types/index.js';
55

66
const ROW_SAMPLE_SIZE = 20;
77
const MAX_WIDTH = 700;
@@ -416,7 +416,7 @@ const columns = (columns: AnalyticalTableColumnDefinition[], { instance }) => {
416416
});
417417
};
418418

419-
export const useDynamicColumnWidths = (hooks) => {
419+
export const useDynamicColumnWidths = (hooks: ReactTableHooks) => {
420420
hooks.columns.push(columns);
421421
hooks.columnsDeps.push(columnsDeps);
422422
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useCallback, useEffect, useRef } from 'react';
22
import { actions } from 'react-table';
3+
import type { ReactTableHooks } from '../types/index.js';
34
import { getLeafHeaders } from '../util/index.js';
45

56
const CELL_DATA_ATTRIBUTES = ['visibleColumnIndex', 'columnIndex', 'rowIndex', 'visibleRowIndex'];
@@ -359,7 +360,7 @@ const setHeaderProps = (headerProps, { instance: { dispatch }, column }) => {
359360
return [headerProps, { onKeyDown: handleKeyDown }];
360361
};
361362

362-
export const useKeyboardNavigation = (hooks) => {
363+
export const useKeyboardNavigation = (hooks: ReactTableHooks) => {
363364
hooks.getTableProps.push(useGetTableProps);
364365
hooks.getHeaderProps.push(setHeaderProps);
365366
};

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ReactTableHooks } from '../types/index.js';
2+
13
const popInVisibleColumnsDeps = (deps, { instance: { state } }) => [...deps, state.tableClientWidth];
24

35
const popInVisibleColumns = (cols, { instance }) => {
@@ -22,7 +24,7 @@ const popInVisibleColumns = (cols, { instance }) => {
2224
);
2325
};
2426

25-
export const usePopIn = (hooks) => {
27+
export const usePopIn = (hooks: ReactTableHooks) => {
2628
hooks.visibleColumns.push(popInVisibleColumns);
2729
hooks.visibleColumnsDeps.push(popInVisibleColumnsDeps);
2830
};

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ReactTableHooks } from '../types/index.js';
2+
13
const useGetResizerProps = (props) => {
24
return {
35
...props,
@@ -8,7 +10,7 @@ const useGetResizerProps = (props) => {
810
};
911
};
1012

11-
export const useResizeColumnsConfig = (hooks) => {
13+
export const useResizeColumnsConfig = (hooks: ReactTableHooks) => {
1214
hooks.getResizerProps.push(useGetResizerProps);
1315
};
1416

packages/main/src/components/AnalyticalTable/hooks/useRowHighlight.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { ValueState } from '../../../enums/index.js';
3+
import type { ReactTableHooks } from '../types/index.js';
34

45
const baseStyles = {
56
width: '100%',
@@ -67,7 +68,7 @@ const columns = (currentColumns, { instance }) => {
6768
];
6869
};
6970

70-
export const useRowHighlight = (hooks) => {
71+
export const useRowHighlight = (hooks: ReactTableHooks) => {
7172
hooks.columns.push(columns);
7273
hooks.columnsDeps.push(columnsDeps);
7374
hooks.visibleColumnsDeps.push(visibleColumnsDeps);

packages/main/src/components/AnalyticalTable/hooks/useRowNavigationIndicator.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import type { ReactTableHooks } from '../types/index.js';
23

34
const baseStyles = {
45
width: '100%',
@@ -67,7 +68,7 @@ const columns = (currentColumns, { instance }) => {
6768
];
6869
};
6970

70-
export const useRowNavigationIndicators = (hooks) => {
71+
export const useRowNavigationIndicators = (hooks: ReactTableHooks) => {
7172
hooks.columns.push(columns);
7273
hooks.columnsDeps.push(columnsDeps);
7374
hooks.visibleColumnsDeps.push(visibleColumnsDeps);

packages/main/src/components/AnalyticalTable/hooks/useRowSelectionColumn.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { CSSProperties } from 'react';
33
import React from 'react';
44
import { AnalyticalTableSelectionBehavior, AnalyticalTableSelectionMode } from '../../../enums/index.js';
55
import { CheckBox } from '../../../webComponents/CheckBox/index.js';
6+
import type { ReactTableHooks } from '../types/index.js';
67

78
const customCheckBoxStyling = {
89
verticalAlign: 'middle',
@@ -181,7 +182,7 @@ const setToggleRowSelectedProps = (props, { instance: { webComponentsReactProper
181182
return [props, { className: classes.checkBox, title: undefined }];
182183
};
183184

184-
export const useRowSelectionColumn = (hooks) => {
185+
export const useRowSelectionColumn = (hooks: ReactTableHooks) => {
185186
hooks.getCellProps.push(getCellProps);
186187
hooks.getHeaderProps.push(headerProps);
187188
hooks.getToggleRowSelectedProps.push(setToggleRowSelectedProps);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { enrichEventWithDetails } from '@ui5/webcomponents-react-base';
22
import { useEffect } from 'react';
33
import { AnalyticalTableSelectionMode } from '../../../enums/index.js';
4+
import type { ReactTableHooks } from '../types/index.js';
45

5-
export const useSelectionChangeCallback = (hooks) => {
6+
export const useSelectionChangeCallback = (hooks: ReactTableHooks) => {
67
hooks.useControlledState.push((state, { instance }) => {
78
const { selectedRowPayload, selectedRowIds, filters, globalFilter } = state;
89
const { rowsById, preFilteredRowsById, webComponentsReactProperties, dispatch } = instance;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { enrichEventWithDetails } from '@ui5/webcomponents-react-base';
22
import { AnalyticalTableSelectionBehavior, AnalyticalTableSelectionMode } from '../../../enums/index.js';
3+
import type { ReactTableHooks } from '../types/index.js';
34

45
const getRowProps = (rowProps, { row, instance }) => {
56
const { webComponentsReactProperties, toggleRowSelected, selectedFlatRows, dispatch } = instance;
@@ -69,7 +70,7 @@ const getRowProps = (rowProps, { row, instance }) => {
6970
];
7071
};
7172

72-
export const useSingleRowStateSelection = (hooks) => {
73+
export const useSingleRowStateSelection = (hooks: ReactTableHooks) => {
7374
hooks.getRowProps.push(getRowProps);
7475
};
7576
useSingleRowStateSelection.pluginName = 'useSingleRowStateSelection';

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { CSSProperties } from 'react';
22
import { AnalyticalTableSelectionBehavior, AnalyticalTableSelectionMode } from '../../../enums/index.js';
3+
import type { ReactTableHooks } from '../types/index.js';
34
import { getSubRowsByString, resolveCellAlignment } from '../util/index.js';
45

56
const getHeaderGroupProps = (headerGroupProps, { instance }) => {
@@ -106,7 +107,7 @@ const getCellProps = (cellProps, { cell: { column }, instance }) => {
106107
];
107108
};
108109

109-
export const useStyling = (hooks) => {
110+
export const useStyling = (hooks: ReactTableHooks) => {
110111
hooks.getHeaderGroupProps.push(getHeaderGroupProps);
111112
hooks.getHeaderProps.push(getHeaderProps);
112113
hooks.getRowProps.push(getRowProps);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { enrichEventWithDetails } from '@ui5/webcomponents-react-base';
2+
import type { ReactTableHooks } from '../types/index.js';
23

34
const getToggleRowExpandedProps = (rowProps, { row, instance, userProps }) => {
45
const { dispatch, manualGroupBy } = instance;
@@ -56,7 +57,7 @@ const getToggleRowExpandedProps = (rowProps, { row, instance, userProps }) => {
5657
];
5758
};
5859

59-
export const useToggleRowExpand = (hooks) => {
60+
export const useToggleRowExpand = (hooks: ReactTableHooks) => {
6061
hooks.getToggleRowExpandedProps.push(getToggleRowExpandedProps);
6162
};
6263
useToggleRowExpand.pluginName = 'useToggleRowExpand';
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import type { ReactTableHooks } from '../types/index.js';
2+
13
const getVisibleColumnsWidth = (instance) => {
24
const visibleColumnsWidth = instance.visibleColumns.map((item) => item.totalWidth);
35
Object.assign(instance, { visibleColumnsWidth });
46
};
57

6-
export const useVisibleColumnsWidth = (hooks) => {
8+
export const useVisibleColumnsWidth = (hooks: ReactTableHooks) => {
79
hooks.useInstance.push(getVisibleColumnsWidth);
810
};
911
useVisibleColumnsWidth.pluginName = 'useVisibleColumnsWidth';

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useEffect } from 'react';
44
import { AnalyticalTableSelectionBehavior, AnalyticalTableSelectionMode } from '../../../enums/index.js';
5+
import type { ReactTableHooks } from '../types/index.js';
56

67
type onIndeterminateChange = (e: {
78
indeterminateRowsById: Record<string | number, boolean>;
@@ -146,7 +147,7 @@ export const useIndeterminateRowSelection = (onIndeterminateChange?: onIndetermi
146147
}, [indeterminateRows]);
147148
};
148149

149-
const useIndeterminate = (hooks) => {
150+
const useIndeterminate = (hooks: ReactTableHooks) => {
150151
hooks.getToggleRowSelectedProps.push(toggleRowProps);
151152
hooks.stateReducers.push(stateReducer);
152153
hooks.useInstanceAfterData.push(useInstanceAfterData);

packages/main/src/components/AnalyticalTable/pluginHooks/useManualRowSelect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

33
import { useEffect } from 'react';
4+
import type { ReactTableHooks } from '../types/index.js';
45

56
/**
67
* A plugin hook for manual row selection.
@@ -19,7 +20,7 @@ export const useManualRowSelect = (manualRowSelectedKey = 'isSelected') => {
1920
}, [flatRows, manualRowSelectedKey]);
2021
};
2122

22-
const manualRowSelect = (hooks) => {
23+
const manualRowSelect = (hooks: ReactTableHooks) => {
2324
hooks.useInstanceAfterData.push(instanceAfterData);
2425
};
2526

packages/main/src/components/AnalyticalTable/pluginHooks/useOnColumnResize.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { debounce } from '@ui5/webcomponents-react-base';
44
import { useEffect, useRef } from 'react';
5+
import type { ReactTableHooks } from '../types/index.js';
56

67
interface useOnColumnResizeOptions {
78
/**
@@ -67,7 +68,7 @@ export const useOnColumnResize = (callback: useOnColumnResizeFunc, options?: use
6768
}, [columnResizing, options?.liveUpdate, columns]);
6869
};
6970

70-
const useOnColumnResizeHooks = (hooks) => {
71+
const useOnColumnResizeHooks = (hooks: ReactTableHooks) => {
7172
hooks.useFinalInstance.push(useInstance);
7273
};
7374

packages/main/src/components/AnalyticalTable/pluginHooks/useOrderedMultiSort.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
*
66
* @param {string[]} orderedIds - Array of column IDs, defining the sorting priority.
77
*/
8+
import type { ReactTableHooks } from '../types/index.js';
9+
810
export const useOrderedMultiSort = (orderedIds: string[]) => {
9-
const useOrderedMultiSortPlugin = (hooks) => {
11+
const useOrderedMultiSortPlugin = (hooks: ReactTableHooks) => {
1012
hooks.stateReducers.push((newState, action) => {
1113
if (action.type === 'toggleSortBy') {
1214
if (newState.sortBy.length <= 1) {

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

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

78
type DisableRowSelectionType = string | ((row: Record<any, any>) => boolean);
@@ -130,7 +131,7 @@ export const useRowDisableSelection = (disableRowSelection: DisableRowSelectionT
130131
return rowProps;
131132
};
132133

133-
const useDisableSelectionRow = (hooks) => {
134+
const useDisableSelectionRow = (hooks: ReactTableHooks) => {
134135
hooks.getHeaderProps.push(headerProps);
135136
hooks.getRowProps.push(getRowProps);
136137
hooks.columns.push(columns);

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { ComponentType, ReactNode, Ref } from 'react';
2-
import type { PluginHook } from 'react-table';
32
import type {
43
AnalyticalTableScaleWidthMode,
54
AnalyticalTableScrollMode,
@@ -17,6 +16,46 @@ import type {
1716
} from '../../../enums/index.js';
1817
import type { CommonProps } from '../../../interfaces/index.js';
1918

19+
export interface ReactTableHooks {
20+
useOptions: any[];
21+
stateReducers: any[];
22+
useControlledState: any[];
23+
columns: any[];
24+
columnsDeps: any[];
25+
allColumns: any[];
26+
allColumnsDeps: any[];
27+
accessValue: any[];
28+
materializedColumns: any[];
29+
materializedColumnsDeps: any[];
30+
useInstanceAfterData: any[];
31+
visibleColumns: any[];
32+
visibleColumnsDeps: any[];
33+
headerGroups: any[];
34+
headerGroupsDeps: any[];
35+
useInstanceBeforeDimensions: any[];
36+
useInstance: any[];
37+
prepareRow: any[];
38+
getTableProps: any[];
39+
getTableBodyProps: any[];
40+
getHeaderGroupProps: any[];
41+
getFooterGroupProps: any[];
42+
getHeaderProps: any[];
43+
getFooterProps: any[];
44+
getRowProps: any[];
45+
getCellProps: any[];
46+
useFinalInstance: any[];
47+
getToggleHiddenProps: any[];
48+
getToggleHideAllColumnsProps: any[];
49+
getGroupByToggleProps: any[];
50+
getSortByToggleProps: any[];
51+
getToggleAllRowsExpandedProps: any[];
52+
getToggleRowExpandedProps: any[];
53+
getToggleRowSelectedProps: any[];
54+
getToggleAllRowsSelectedProps: any[];
55+
getToggleAllPageRowsSelectedProps: any[];
56+
getResizerProps: any[];
57+
}
58+
2059
export interface AnalyticalTableState {
2160
columnOrder: string[];
2261
columnResizing: Record<string, any>;
@@ -463,7 +502,7 @@ export interface AnalyticalTablePropTypes extends Omit<CommonProps, 'title'> {
463502
/**
464503
* You can use this prob to add custom hooks to the table.
465504
*/
466-
tableHooks?: PluginHook<any>[];
505+
tableHooks?: ((hooks?: ReactTableHooks) => void)[];
467506
/**
468507
* Defines the key for nested rows.
469508
*

0 commit comments

Comments
 (0)