Skip to content

Commit 6dc1b12

Browse files
authored
fix(AnalyticalTable - TypeScript): improve instance types (#7935)
1 parent 8511f5a commit 6dc1b12

File tree

1 file changed

+37
-34
lines changed
  • packages/main/src/components/AnalyticalTable/types

1 file changed

+37
-34
lines changed

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

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export interface ColumnType extends Omit<AnalyticalTableColumnDefinition, 'id'>
9393
export interface CellType {
9494
column: ColumnType;
9595
row: RowType;
96-
value: string | undefined | null;
96+
value: boolean | number | string | undefined | null;
9797
getCellProps: (userProps?: any) => any;
9898
/**
9999
* Indicates whether the cell is aggregated.
@@ -107,16 +107,16 @@ export interface CellType {
107107
}
108108

109109
export interface TableInstance {
110-
allColumns?: ColumnType[];
110+
allColumns: ColumnType[];
111111
allColumnsHidden?: boolean;
112112
columns: ColumnType[];
113113
data: Record<string, any>[];
114-
defaultColumn?: Record<string, any>;
115-
disableFilters?: boolean;
114+
defaultColumn: Record<string, any>;
115+
disableFilters: boolean;
116116
disableGlobalFilter?: boolean;
117-
disableGroupBy?: boolean;
118-
disableSortBy?: boolean;
119-
dispatch?: (action: {
117+
disableGroupBy: boolean;
118+
disableSortBy: boolean;
119+
dispatch: (action: {
120120
type: string;
121121
payload?: Record<string, unknown> | AnalyticalTableState['popInColumns'] | boolean | string | number;
122122
clientX?: number;
@@ -126,36 +126,36 @@ export interface TableInstance {
126126
filteredFlatRows?: RowType[];
127127
filteredRows?: RowType[];
128128
filteredRowsById?: Record<string, RowType>;
129-
flatHeaders?: ColumnType[];
130-
flatRows?: RowType[];
129+
flatHeaders: ColumnType[];
130+
flatRows: RowType[];
131131
footerGroups?: Record<string, any>[];
132-
getHooks?: () => any[];
133-
getRowId?: (row: RowType, index: number, parent?: any) => string;
134-
getSubRows?: (row: RowType, relativeIndex?: number) => RowType[];
135-
getTableBodyProps?: any;
136-
getTableProps?: any;
137-
getToggleAllPageRowsSelectedProps?: any;
138-
getToggleAllRowsExpandedProps?: any;
139-
getToggleAllRowsSelectedProps?: any;
140-
getToggleHideAllColumnsProps?: any;
132+
getHooks: () => ReactTableHooks;
133+
getRowId: (row: RowType, index: number, parent?: any) => string;
134+
getSubRows: (row: RowType, relativeIndex?: number) => RowType[];
135+
getTableBodyProps?: (userProps?: Record<string, any>) => Record<string, any>;
136+
getTableProps?: (userProps?: Record<string, any>) => Record<string, any>;
137+
getToggleAllPageRowsSelectedProps?: (userProps?: Record<string, any>) => Record<string, any>;
138+
getToggleAllRowsExpandedProps?: (userProps?: Record<string, any>) => Record<string, any>;
139+
getToggleAllRowsSelectedProps?: (userProps?: Record<string, any>) => Record<string, any>;
140+
getToggleHideAllColumnsProps?: (userProps?: Record<string, any>) => Record<string, any>;
141141
globalFilteredFlatRows?: RowType[];
142142
globalFilteredRows?: RowType[];
143143
globalFilteredRowsById?: Record<string, RowType>;
144144
groupedFlatRows?: RowType[];
145145
groupedRows?: RowType[];
146146
groupedRowsById?: Record<string, RowType>;
147-
headerGroups?: Record<string, any>[];
148-
headers?: ColumnType[];
149-
initialRows?: RowType[];
150-
initialState?: Record<string, any>;
147+
headerGroups: Record<string, any>[];
148+
headers: ColumnType[];
149+
initialRows: RowType[];
150+
initialState: Record<string, any>;
151151
isAllPageRowsSelected?: boolean;
152152
isAllRowsExpanded?: boolean;
153153
isAllRowsSelected?: boolean;
154154
nonGroupedFlatRows?: RowType[];
155155
nonGroupedRowsById?: Record<string, RowType>;
156156
onlyGroupedFlatRows?: RowType[];
157157
onlyGroupedRowsById?: Record<string, RowType>;
158-
plugins?: any[];
158+
plugins: ((hooks: ReactTableHooks) => void)[];
159159
preExpandedRows?: RowType[];
160160
preFilteredFlatRows?: RowType[];
161161
preFilteredRows?: RowType[];
@@ -169,13 +169,13 @@ export interface TableInstance {
169169
preSortedFlatRows?: RowType[];
170170
preSortedRows?: RowType[];
171171
prepareRow?: (row: RowType) => void;
172-
resetResizing?: any;
172+
resetResizing?: () => void;
173173
rows: RowType[];
174-
rowsById?: Record<string, RowType>;
175-
selectSubRows?: boolean;
174+
rowsById: Record<string, RowType>;
175+
selectSubRows: boolean;
176176
selectedFlatRows?: RowType[];
177177
setAllFilters?: (filtersObjectArray: Record<string, any>[]) => void;
178-
setColumnOrder?: any;
178+
setColumnOrder?: (columnOrder: AnalyticalTableState['columnOrder']) => void;
179179
/**
180180
* Set the filter value for the defined column.
181181
*
@@ -185,8 +185,8 @@ export interface TableInstance {
185185
setGlobalFilter?: (filterValue: string) => void;
186186
setGroupBy?: (columnIds: string[]) => void;
187187
setHiddenColumns?: (columnIds: string[]) => void;
188-
setSortBy?: any;
189-
sortTypes?: Record<string, any>;
188+
setSortBy?: (sortBy: AnalyticalTableState['sortBy']) => void;
189+
sortTypes: Record<string, any>;
190190
sortedFlatRows?: Record<string, RowType>[];
191191
sortedRows?: Record<string, RowType>[];
192192
state: AnalyticalTableState & Record<string, any>;
@@ -208,7 +208,10 @@ export interface TableInstance {
208208
totalColumnsMaxWidth?: number;
209209
totalColumnsMinWidth?: number;
210210
totalColumnsWidth?: number;
211-
useControlledState?: any;
211+
useControlledState: (
212+
state: TableInstance['state'] & Record<string, any>,
213+
instance?: { instance: TableInstance },
214+
) => TableInstance['state'] & Record<string, any>;
212215
virtualRowsRange?: {
213216
startIndex: number;
214217
endIndex: number;
@@ -973,7 +976,7 @@ export interface AnalyticalTablePropTypes extends Omit<CommonProps, 'title'> {
973976
* - When rendering active elements inside the subcomponent, make sure to add the `data-subcomponent-active-element' attribute, otherwise focus behavior won't be consistent.
974977
* - Subcomponents can affect performance, especially when used in a tree table (`isTreeTable={true}`). If you face performance issues, please try memoizing your subcomponent.
975978
*/
976-
renderRowSubComponent?: (row?: RowType) => ReactNode;
979+
renderRowSubComponent?: (row: RowType) => ReactNode;
977980
/**
978981
* Defines the rendering and height calculation behavior of subcomponents when `renderRowSubComponent` is used.
979982
*
@@ -994,7 +997,7 @@ export interface AnalyticalTablePropTypes extends Omit<CommonProps, 'title'> {
994997
*
995998
* __Must be memoized!__
996999
*/
997-
markNavigatedRow?: (row?: RowType) => boolean;
1000+
markNavigatedRow?: (row: RowType) => boolean;
9981001
/**
9991002
* Fired when the sorting of the rows changes.
10001003
*/
@@ -1033,7 +1036,7 @@ export interface AnalyticalTablePropTypes extends Omit<CommonProps, 'title'> {
10331036
/**
10341037
* Fired when a row is expanded or collapsed
10351038
*/
1036-
onRowExpandChange?: (e: CustomEvent<{ row: unknown; column: unknown }>) => void;
1039+
onRowExpandChange?: (e: CustomEvent<{ row: RowType; column: ColumnType }>) => void;
10371040
/**
10381041
* Fired when the columns order is changed.
10391042
*/
@@ -1055,7 +1058,7 @@ export interface AnalyticalTablePropTypes extends Omit<CommonProps, 'title'> {
10551058
* non-memoized or expensive calculations can have a __huge impact on performance__ and cause visible lag.
10561059
* Throttling or debouncing is always recommended to reduce performance overhead.
10571060
*/
1058-
onTableScroll?: (e: CustomEvent<{ rows: Record<string, any>[]; rowElements: HTMLCollection }>) => void;
1061+
onTableScroll?: (e: CustomEvent<{ rows: RowType[]; rowElements: HTMLCollection }>) => void;
10591062
/**
10601063
* Fired when the table is resized by double-clicking the Resizer.
10611064
*

0 commit comments

Comments
 (0)