Skip to content

Commit 83a808e

Browse files
authored
fix(AnalyticalTable): prevent crash if unsupported rowId is set as selectedRowId (#615)
* fix(AnalyticalTable): prevent crash if unsupported rowId is set as selectedRowId
1 parent 47104f9 commit 83a808e

File tree

1 file changed

+8
-2
lines changed
  • packages/main/src/components/AnalyticalTable

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,14 @@ export interface TableProps extends CommonProps {
100100
onColumnsReordered?: (e?: CustomEvent<{ columnsNewOrder: string[]; column: unknown }>) => void;
101101
onLoadMore?: (e?: { detail: { rowCount: number } }) => void;
102102
/**
103-
* additional options which will be passed to [react-table´s useTable hook](https://github.com/tannerlinsley/react-table/blob/master/docs/api/useTable.md#table-options)
103+
* Additional options which will be passed to [react-table´s useTable hook](https://react-table.tanstack.com/docs/api/useTable#table-options)
104104
*/
105105
reactTableOptions?: object;
106106
tableHooks?: PluginHook<any>[];
107107
subRowsKey?: string;
108+
/**
109+
* The key must consist of a valid `rowId` like `{ 2: true }` or `{ '0.2.0': true }` for nested rows.
110+
*/
108111
selectedRowIds?: { [key: string]: boolean };
109112
isTreeTable?: boolean;
110113
overscanCount?: number;
@@ -269,8 +272,11 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
269272

270273
useEffect(() => {
271274
toggleAllRowsSelected(false);
275+
const validChars = /^(\d\.)*\d$/;
272276
for (const row in selectedRowIds) {
273-
toggleRowSelected(row, selectedRowIds[row]);
277+
if (validChars.test(row)) {
278+
toggleRowSelected(row, selectedRowIds[row]);
279+
}
274280
}
275281
}, [toggleRowSelected, toggleAllRowsSelected, selectedRowIds]);
276282

0 commit comments

Comments
 (0)