@itwin/itwinui-react 3.15.4 → 3.15.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.15.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2306](https://github.com/iTwin/iTwinUI/pull/2306): Fixed broken expandable content (`subComponent`) when `Table` is asynchronously re-rendered.
8
+ - [#2306](https://github.com/iTwin/iTwinUI/pull/2306): Fixed `Table`'s max depth reached error caused when passing the `getRowId` prop.
9
+
3
10
  ## 3.15.4
4
11
 
5
12
  ### Patch Changes
@@ -36,6 +36,7 @@ const singleRowSelectedAction = 'singleRowSelected';
36
36
  const shiftRowSelectedAction = 'shiftRowSelected';
37
37
  const tableResizeStartAction = 'tableResizeStart';
38
38
  const tableResizeEndAction = 'tableResizeEnd';
39
+ const iuiId = Symbol('iui-id');
39
40
  const flattenColumns = (columns) => {
40
41
  let flatColumns = [];
41
42
  columns.forEach((column) => {
@@ -88,6 +89,7 @@ const Table = (props) => {
88
89
  headerProps,
89
90
  bodyProps,
90
91
  emptyTableContentProps,
92
+ getRowId,
91
93
  ...rest
92
94
  } = props;
93
95
  (0, _index.useGlobals)();
@@ -225,16 +227,30 @@ const Table = (props) => {
225
227
  ),
226
228
  [data, getSubRows],
227
229
  );
228
- let [rowHasParent] = _react.useState(() => new WeakSet());
229
230
  let getSubRowsWithSubComponents = _react.useCallback(
230
- (originalRow) => {
231
- if (!rowHasParent.has(originalRow)) {
232
- rowHasParent.add(originalRow);
233
- return [originalRow];
234
- }
235
- return originalRow.subRows || [];
231
+ (originalRow, relativeIndex) => {
232
+ if (originalRow[iuiId]) return [];
233
+ if (originalRow.subRows) return originalRow.subRows;
234
+ return [
235
+ {
236
+ [iuiId]: `subcomponent-${relativeIndex}`,
237
+ ...originalRow,
238
+ },
239
+ ];
240
+ },
241
+ [],
242
+ );
243
+ let getRowIdWithSubComponents = _react.useCallback(
244
+ (originalRow, relativeIndex, parent) => {
245
+ let defaultRowId = parent
246
+ ? `${parent.id}.${relativeIndex}`
247
+ : `${relativeIndex}`;
248
+ let rowIdFromUser = getRowId?.(originalRow, relativeIndex, parent);
249
+ if (void 0 !== rowIdFromUser && originalRow[iuiId])
250
+ return `${rowIdFromUser}-${defaultRowId}`;
251
+ return rowIdFromUser ?? defaultRowId;
236
252
  },
237
- [rowHasParent],
253
+ [getRowId],
238
254
  );
239
255
  let instance = (0, _reacttable.useTable)(
240
256
  {
@@ -254,6 +270,7 @@ const Table = (props) => {
254
270
  ...props.initialState,
255
271
  },
256
272
  columnResizeMode,
273
+ getRowId: subComponent ? getRowIdWithSubComponents : getRowId,
257
274
  },
258
275
  _reacttable.useFlexLayout,
259
276
  (0, _index1.useResizeColumns)(ownerDocument),
@@ -459,51 +476,52 @@ const Table = (props) => {
459
476
  (index, virtualItem, virtualizer) => {
460
477
  let row = page[index];
461
478
  prepareRow(row);
462
- if (row.subRows.length > 0 || !subComponent)
463
- return _react.createElement(_TableRowMemoized.TableRowMemoized, {
464
- row: row,
465
- rowProps: rowProps,
466
- isLast: index === page.length - 1,
467
- onRowInViewport: onRowInViewportRef,
468
- onBottomReached: onBottomReachedRef,
469
- intersectionMargin: intersectionMargin,
470
- state: state,
471
- key: row.getRowProps().key,
472
- onClick: onRowClickHandler,
473
- subComponent: subComponent,
474
- isDisabled: !!isRowDisabled?.(row.original),
475
- tableHasSubRows: hasAnySubRows,
476
- tableInstance: instance,
477
- expanderCell: expanderCell,
478
- scrollContainerRef: tableRef.current,
479
- tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
480
- density: density,
481
- virtualItem: virtualItem,
482
- virtualizer: virtualizer,
483
- });
484
- return _react.createElement(
485
- _TableExpandableContentMemoized.TableExpandableContentMemoized,
486
- {
487
- key: row.getRowProps().key,
488
- virtualItem: virtualItem,
489
- ref: enableVirtualization
490
- ? virtualizer?.measureElement
491
- : tableRowRef(row),
492
- isDisabled: !!isRowDisabled?.(row.original),
493
- },
494
- subComponent(row),
495
- );
479
+ let isRowASubComponent = !!row.original[iuiId] && !!subComponent;
480
+ if (isRowASubComponent)
481
+ return _react.createElement(
482
+ _TableExpandableContentMemoized.TableExpandableContentMemoized,
483
+ {
484
+ key: row.getRowProps().key,
485
+ virtualItem: virtualItem,
486
+ ref: enableVirtualization
487
+ ? virtualizer?.measureElement
488
+ : tableRowRef(row),
489
+ isDisabled: !!isRowDisabled?.(row.original),
490
+ },
491
+ subComponent(row),
492
+ );
493
+ return _react.createElement(_TableRowMemoized.TableRowMemoized, {
494
+ row: row,
495
+ rowProps: rowProps,
496
+ isLast: index === page.length - 1,
497
+ onRowInViewport: onRowInViewportRef,
498
+ onBottomReached: onBottomReachedRef,
499
+ intersectionMargin: intersectionMargin,
500
+ state: state,
501
+ key: row.getRowProps().key,
502
+ onClick: onRowClickHandler,
503
+ subComponent: subComponent,
504
+ isDisabled: !!isRowDisabled?.(row.original),
505
+ tableHasSubRows: hasAnySubRows,
506
+ tableInstance: instance,
507
+ expanderCell: expanderCell,
508
+ scrollContainerRef: tableRef.current,
509
+ tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
510
+ density: density,
511
+ virtualItem: virtualItem,
512
+ virtualizer: virtualizer,
513
+ });
496
514
  },
497
515
  [
498
516
  page,
499
517
  prepareRow,
518
+ subComponent,
500
519
  rowProps,
501
520
  onRowInViewportRef,
502
521
  onBottomReachedRef,
503
522
  intersectionMargin,
504
523
  state,
505
524
  onRowClickHandler,
506
- subComponent,
507
525
  isRowDisabled,
508
526
  hasAnySubRows,
509
527
  instance,
package/DEV-cjs/styles.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
- const e = '3.15.4';
3
+ const e = '3.15.5';
4
4
  const u = new Proxy(
5
5
  {},
6
6
  {
@@ -53,6 +53,7 @@ let singleRowSelectedAction = 'singleRowSelected';
53
53
  let shiftRowSelectedAction = 'shiftRowSelected';
54
54
  export const tableResizeStartAction = 'tableResizeStart';
55
55
  let tableResizeEndAction = 'tableResizeEnd';
56
+ let iuiId = Symbol('iui-id');
56
57
  let flattenColumns = (columns) => {
57
58
  let flatColumns = [];
58
59
  columns.forEach((column) => {
@@ -105,6 +106,7 @@ export const Table = (props) => {
105
106
  headerProps,
106
107
  bodyProps,
107
108
  emptyTableContentProps,
109
+ getRowId,
108
110
  ...rest
109
111
  } = props;
110
112
  useGlobals();
@@ -240,16 +242,30 @@ export const Table = (props) => {
240
242
  ),
241
243
  [data, getSubRows],
242
244
  );
243
- let [rowHasParent] = React.useState(() => new WeakSet());
244
245
  let getSubRowsWithSubComponents = React.useCallback(
245
- (originalRow) => {
246
- if (!rowHasParent.has(originalRow)) {
247
- rowHasParent.add(originalRow);
248
- return [originalRow];
249
- }
250
- return originalRow.subRows || [];
246
+ (originalRow, relativeIndex) => {
247
+ if (originalRow[iuiId]) return [];
248
+ if (originalRow.subRows) return originalRow.subRows;
249
+ return [
250
+ {
251
+ [iuiId]: `subcomponent-${relativeIndex}`,
252
+ ...originalRow,
253
+ },
254
+ ];
255
+ },
256
+ [],
257
+ );
258
+ let getRowIdWithSubComponents = React.useCallback(
259
+ (originalRow, relativeIndex, parent) => {
260
+ let defaultRowId = parent
261
+ ? `${parent.id}.${relativeIndex}`
262
+ : `${relativeIndex}`;
263
+ let rowIdFromUser = getRowId?.(originalRow, relativeIndex, parent);
264
+ if (void 0 !== rowIdFromUser && originalRow[iuiId])
265
+ return `${rowIdFromUser}-${defaultRowId}`;
266
+ return rowIdFromUser ?? defaultRowId;
251
267
  },
252
- [rowHasParent],
268
+ [getRowId],
253
269
  );
254
270
  let instance = useTable(
255
271
  {
@@ -269,6 +285,7 @@ export const Table = (props) => {
269
285
  ...props.initialState,
270
286
  },
271
287
  columnResizeMode,
288
+ getRowId: subComponent ? getRowIdWithSubComponents : getRowId,
272
289
  },
273
290
  useFlexLayout,
274
291
  useResizeColumns(ownerDocument),
@@ -469,51 +486,52 @@ export const Table = (props) => {
469
486
  (index, virtualItem, virtualizer) => {
470
487
  let row = page[index];
471
488
  prepareRow(row);
472
- if (row.subRows.length > 0 || !subComponent)
473
- return React.createElement(TableRowMemoized, {
474
- row: row,
475
- rowProps: rowProps,
476
- isLast: index === page.length - 1,
477
- onRowInViewport: onRowInViewportRef,
478
- onBottomReached: onBottomReachedRef,
479
- intersectionMargin: intersectionMargin,
480
- state: state,
481
- key: row.getRowProps().key,
482
- onClick: onRowClickHandler,
483
- subComponent: subComponent,
484
- isDisabled: !!isRowDisabled?.(row.original),
485
- tableHasSubRows: hasAnySubRows,
486
- tableInstance: instance,
487
- expanderCell: expanderCell,
488
- scrollContainerRef: tableRef.current,
489
- tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
490
- density: density,
491
- virtualItem: virtualItem,
492
- virtualizer: virtualizer,
493
- });
494
- return React.createElement(
495
- TableExpandableContentMemoized,
496
- {
497
- key: row.getRowProps().key,
498
- virtualItem: virtualItem,
499
- ref: enableVirtualization
500
- ? virtualizer?.measureElement
501
- : tableRowRef(row),
502
- isDisabled: !!isRowDisabled?.(row.original),
503
- },
504
- subComponent(row),
505
- );
489
+ let isRowASubComponent = !!row.original[iuiId] && !!subComponent;
490
+ if (isRowASubComponent)
491
+ return React.createElement(
492
+ TableExpandableContentMemoized,
493
+ {
494
+ key: row.getRowProps().key,
495
+ virtualItem: virtualItem,
496
+ ref: enableVirtualization
497
+ ? virtualizer?.measureElement
498
+ : tableRowRef(row),
499
+ isDisabled: !!isRowDisabled?.(row.original),
500
+ },
501
+ subComponent(row),
502
+ );
503
+ return React.createElement(TableRowMemoized, {
504
+ row: row,
505
+ rowProps: rowProps,
506
+ isLast: index === page.length - 1,
507
+ onRowInViewport: onRowInViewportRef,
508
+ onBottomReached: onBottomReachedRef,
509
+ intersectionMargin: intersectionMargin,
510
+ state: state,
511
+ key: row.getRowProps().key,
512
+ onClick: onRowClickHandler,
513
+ subComponent: subComponent,
514
+ isDisabled: !!isRowDisabled?.(row.original),
515
+ tableHasSubRows: hasAnySubRows,
516
+ tableInstance: instance,
517
+ expanderCell: expanderCell,
518
+ scrollContainerRef: tableRef.current,
519
+ tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
520
+ density: density,
521
+ virtualItem: virtualItem,
522
+ virtualizer: virtualizer,
523
+ });
506
524
  },
507
525
  [
508
526
  page,
509
527
  prepareRow,
528
+ subComponent,
510
529
  rowProps,
511
530
  onRowInViewportRef,
512
531
  onBottomReachedRef,
513
532
  intersectionMargin,
514
533
  state,
515
534
  onRowClickHandler,
516
- subComponent,
517
535
  isRowDisabled,
518
536
  hasAnySubRows,
519
537
  instance,
package/DEV-esm/styles.js CHANGED
@@ -1,4 +1,4 @@
1
- const t = '3.15.4';
1
+ const t = '3.15.5';
2
2
  const u = new Proxy(
3
3
  {},
4
4
  {
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
3
3
  type NonIdealStateProps = {
4
4
  /**
5
- * An svg component, preferably from @itwin/itwinui-illustrations-react.
5
+ * An svg component, preferably from `@itwin/itwinui-illustrations-react`.
6
6
  *
7
7
  * @example
8
8
  * import { Svg404 } from '@itwin/itwinui-illustrations-react';
@@ -10,13 +10,17 @@ type NonIdealStateProps = {
10
10
  */
11
11
  svg: React.ReactNode;
12
12
  /**
13
- * Primary heading for the error page
13
+ * Primary heading for the `NonIdealState`
14
14
  */
15
15
  heading?: React.ReactNode;
16
16
  /**
17
17
  * Secondary text to explain the error
18
18
  * Can include html in order to provide a hyperlink
19
- * E.g. `Please visit <a href="https://www.bentley.com/help">our support page</a> for help.`
19
+ *
20
+ * @example
21
+ * <>
22
+ * Please visit <Anchor href="https://www.bentley.com/help">our support page</Anchor> for help.
23
+ * </>
20
24
  */
21
25
  description?: React.ReactNode;
22
26
  /**
@@ -24,13 +28,13 @@ type NonIdealStateProps = {
24
28
  * Typically should be a primary and secondary button.
25
29
  *
26
30
  * @example
27
- * <ErrorPage
28
- * actions={
29
- * <>
30
- * <Button styleType={'high-visibility'}>Retry</Button>
31
- * <Button>Contact us</Button>
32
- * </>
33
- * }
31
+ * <NonIdealState
32
+ * actions={
33
+ * <>
34
+ * <Button styleType={'high-visibility'}>Retry</Button>
35
+ * <Button>Contact us</Button>
36
+ * </>
37
+ * }
34
38
  * />
35
39
  */
36
40
  actions?: React.ReactNode;
@@ -53,7 +57,7 @@ type NonIdealStateProps = {
53
57
  };
54
58
  /**
55
59
  * A stylized display to communicate common http errors and other non-ideal states.
56
- * Works well with svgs from @itwin/itwinui-illustrations-react.
60
+ * Works well with svgs from `@itwin/itwinui-illustrations-react`.
57
61
  *
58
62
  * @example
59
63
  * <NonIdealState svg={<Svg404 />} heading='Not found' />
@@ -36,6 +36,7 @@ const singleRowSelectedAction = 'singleRowSelected';
36
36
  const shiftRowSelectedAction = 'shiftRowSelected';
37
37
  const tableResizeStartAction = 'tableResizeStart';
38
38
  const tableResizeEndAction = 'tableResizeEnd';
39
+ const iuiId = Symbol('iui-id');
39
40
  const flattenColumns = (columns) => {
40
41
  let flatColumns = [];
41
42
  columns.forEach((column) => {
@@ -88,6 +89,7 @@ const Table = (props) => {
88
89
  headerProps,
89
90
  bodyProps,
90
91
  emptyTableContentProps,
92
+ getRowId,
91
93
  ...rest
92
94
  } = props;
93
95
  (0, _index.useGlobals)();
@@ -225,16 +227,30 @@ const Table = (props) => {
225
227
  ),
226
228
  [data, getSubRows],
227
229
  );
228
- let [rowHasParent] = _react.useState(() => new WeakSet());
229
230
  let getSubRowsWithSubComponents = _react.useCallback(
230
- (originalRow) => {
231
- if (!rowHasParent.has(originalRow)) {
232
- rowHasParent.add(originalRow);
233
- return [originalRow];
234
- }
235
- return originalRow.subRows || [];
231
+ (originalRow, relativeIndex) => {
232
+ if (originalRow[iuiId]) return [];
233
+ if (originalRow.subRows) return originalRow.subRows;
234
+ return [
235
+ {
236
+ [iuiId]: `subcomponent-${relativeIndex}`,
237
+ ...originalRow,
238
+ },
239
+ ];
240
+ },
241
+ [],
242
+ );
243
+ let getRowIdWithSubComponents = _react.useCallback(
244
+ (originalRow, relativeIndex, parent) => {
245
+ let defaultRowId = parent
246
+ ? `${parent.id}.${relativeIndex}`
247
+ : `${relativeIndex}`;
248
+ let rowIdFromUser = getRowId?.(originalRow, relativeIndex, parent);
249
+ if (void 0 !== rowIdFromUser && originalRow[iuiId])
250
+ return `${rowIdFromUser}-${defaultRowId}`;
251
+ return rowIdFromUser ?? defaultRowId;
236
252
  },
237
- [rowHasParent],
253
+ [getRowId],
238
254
  );
239
255
  let instance = (0, _reacttable.useTable)(
240
256
  {
@@ -254,6 +270,7 @@ const Table = (props) => {
254
270
  ...props.initialState,
255
271
  },
256
272
  columnResizeMode,
273
+ getRowId: subComponent ? getRowIdWithSubComponents : getRowId,
257
274
  },
258
275
  _reacttable.useFlexLayout,
259
276
  (0, _index1.useResizeColumns)(ownerDocument),
@@ -451,51 +468,52 @@ const Table = (props) => {
451
468
  (index, virtualItem, virtualizer) => {
452
469
  let row = page[index];
453
470
  prepareRow(row);
454
- if (row.subRows.length > 0 || !subComponent)
455
- return _react.createElement(_TableRowMemoized.TableRowMemoized, {
456
- row: row,
457
- rowProps: rowProps,
458
- isLast: index === page.length - 1,
459
- onRowInViewport: onRowInViewportRef,
460
- onBottomReached: onBottomReachedRef,
461
- intersectionMargin: intersectionMargin,
462
- state: state,
463
- key: row.getRowProps().key,
464
- onClick: onRowClickHandler,
465
- subComponent: subComponent,
466
- isDisabled: !!isRowDisabled?.(row.original),
467
- tableHasSubRows: hasAnySubRows,
468
- tableInstance: instance,
469
- expanderCell: expanderCell,
470
- scrollContainerRef: tableRef.current,
471
- tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
472
- density: density,
473
- virtualItem: virtualItem,
474
- virtualizer: virtualizer,
475
- });
476
- return _react.createElement(
477
- _TableExpandableContentMemoized.TableExpandableContentMemoized,
478
- {
479
- key: row.getRowProps().key,
480
- virtualItem: virtualItem,
481
- ref: enableVirtualization
482
- ? virtualizer?.measureElement
483
- : tableRowRef(row),
484
- isDisabled: !!isRowDisabled?.(row.original),
485
- },
486
- subComponent(row),
487
- );
471
+ let isRowASubComponent = !!row.original[iuiId] && !!subComponent;
472
+ if (isRowASubComponent)
473
+ return _react.createElement(
474
+ _TableExpandableContentMemoized.TableExpandableContentMemoized,
475
+ {
476
+ key: row.getRowProps().key,
477
+ virtualItem: virtualItem,
478
+ ref: enableVirtualization
479
+ ? virtualizer?.measureElement
480
+ : tableRowRef(row),
481
+ isDisabled: !!isRowDisabled?.(row.original),
482
+ },
483
+ subComponent(row),
484
+ );
485
+ return _react.createElement(_TableRowMemoized.TableRowMemoized, {
486
+ row: row,
487
+ rowProps: rowProps,
488
+ isLast: index === page.length - 1,
489
+ onRowInViewport: onRowInViewportRef,
490
+ onBottomReached: onBottomReachedRef,
491
+ intersectionMargin: intersectionMargin,
492
+ state: state,
493
+ key: row.getRowProps().key,
494
+ onClick: onRowClickHandler,
495
+ subComponent: subComponent,
496
+ isDisabled: !!isRowDisabled?.(row.original),
497
+ tableHasSubRows: hasAnySubRows,
498
+ tableInstance: instance,
499
+ expanderCell: expanderCell,
500
+ scrollContainerRef: tableRef.current,
501
+ tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
502
+ density: density,
503
+ virtualItem: virtualItem,
504
+ virtualizer: virtualizer,
505
+ });
488
506
  },
489
507
  [
490
508
  page,
491
509
  prepareRow,
510
+ subComponent,
492
511
  rowProps,
493
512
  onRowInViewportRef,
494
513
  onBottomReachedRef,
495
514
  intersectionMargin,
496
515
  state,
497
516
  onRowClickHandler,
498
- subComponent,
499
517
  isRowDisabled,
500
518
  hasAnySubRows,
501
519
  instance,
package/cjs/styles.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
- const e = '3.15.4';
3
+ const e = '3.15.5';
4
4
  const u = new Proxy(
5
5
  {},
6
6
  {
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
3
3
  type NonIdealStateProps = {
4
4
  /**
5
- * An svg component, preferably from @itwin/itwinui-illustrations-react.
5
+ * An svg component, preferably from `@itwin/itwinui-illustrations-react`.
6
6
  *
7
7
  * @example
8
8
  * import { Svg404 } from '@itwin/itwinui-illustrations-react';
@@ -10,13 +10,17 @@ type NonIdealStateProps = {
10
10
  */
11
11
  svg: React.ReactNode;
12
12
  /**
13
- * Primary heading for the error page
13
+ * Primary heading for the `NonIdealState`
14
14
  */
15
15
  heading?: React.ReactNode;
16
16
  /**
17
17
  * Secondary text to explain the error
18
18
  * Can include html in order to provide a hyperlink
19
- * E.g. `Please visit <a href="https://www.bentley.com/help">our support page</a> for help.`
19
+ *
20
+ * @example
21
+ * <>
22
+ * Please visit <Anchor href="https://www.bentley.com/help">our support page</Anchor> for help.
23
+ * </>
20
24
  */
21
25
  description?: React.ReactNode;
22
26
  /**
@@ -24,13 +28,13 @@ type NonIdealStateProps = {
24
28
  * Typically should be a primary and secondary button.
25
29
  *
26
30
  * @example
27
- * <ErrorPage
28
- * actions={
29
- * <>
30
- * <Button styleType={'high-visibility'}>Retry</Button>
31
- * <Button>Contact us</Button>
32
- * </>
33
- * }
31
+ * <NonIdealState
32
+ * actions={
33
+ * <>
34
+ * <Button styleType={'high-visibility'}>Retry</Button>
35
+ * <Button>Contact us</Button>
36
+ * </>
37
+ * }
34
38
  * />
35
39
  */
36
40
  actions?: React.ReactNode;
@@ -53,7 +57,7 @@ type NonIdealStateProps = {
53
57
  };
54
58
  /**
55
59
  * A stylized display to communicate common http errors and other non-ideal states.
56
- * Works well with svgs from @itwin/itwinui-illustrations-react.
60
+ * Works well with svgs from `@itwin/itwinui-illustrations-react`.
57
61
  *
58
62
  * @example
59
63
  * <NonIdealState svg={<Svg404 />} heading='Not found' />