@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.
@@ -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),
@@ -461,51 +478,52 @@ export const Table = (props) => {
461
478
  (index, virtualItem, virtualizer) => {
462
479
  let row = page[index];
463
480
  prepareRow(row);
464
- if (row.subRows.length > 0 || !subComponent)
465
- return React.createElement(TableRowMemoized, {
466
- row: row,
467
- rowProps: rowProps,
468
- isLast: index === page.length - 1,
469
- onRowInViewport: onRowInViewportRef,
470
- onBottomReached: onBottomReachedRef,
471
- intersectionMargin: intersectionMargin,
472
- state: state,
473
- key: row.getRowProps().key,
474
- onClick: onRowClickHandler,
475
- subComponent: subComponent,
476
- isDisabled: !!isRowDisabled?.(row.original),
477
- tableHasSubRows: hasAnySubRows,
478
- tableInstance: instance,
479
- expanderCell: expanderCell,
480
- scrollContainerRef: tableRef.current,
481
- tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
482
- density: density,
483
- virtualItem: virtualItem,
484
- virtualizer: virtualizer,
485
- });
486
- return React.createElement(
487
- TableExpandableContentMemoized,
488
- {
489
- key: row.getRowProps().key,
490
- virtualItem: virtualItem,
491
- ref: enableVirtualization
492
- ? virtualizer?.measureElement
493
- : tableRowRef(row),
494
- isDisabled: !!isRowDisabled?.(row.original),
495
- },
496
- subComponent(row),
497
- );
481
+ let isRowASubComponent = !!row.original[iuiId] && !!subComponent;
482
+ if (isRowASubComponent)
483
+ return React.createElement(
484
+ TableExpandableContentMemoized,
485
+ {
486
+ key: row.getRowProps().key,
487
+ virtualItem: virtualItem,
488
+ ref: enableVirtualization
489
+ ? virtualizer?.measureElement
490
+ : tableRowRef(row),
491
+ isDisabled: !!isRowDisabled?.(row.original),
492
+ },
493
+ subComponent(row),
494
+ );
495
+ return React.createElement(TableRowMemoized, {
496
+ row: row,
497
+ rowProps: rowProps,
498
+ isLast: index === page.length - 1,
499
+ onRowInViewport: onRowInViewportRef,
500
+ onBottomReached: onBottomReachedRef,
501
+ intersectionMargin: intersectionMargin,
502
+ state: state,
503
+ key: row.getRowProps().key,
504
+ onClick: onRowClickHandler,
505
+ subComponent: subComponent,
506
+ isDisabled: !!isRowDisabled?.(row.original),
507
+ tableHasSubRows: hasAnySubRows,
508
+ tableInstance: instance,
509
+ expanderCell: expanderCell,
510
+ scrollContainerRef: tableRef.current,
511
+ tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
512
+ density: density,
513
+ virtualItem: virtualItem,
514
+ virtualizer: virtualizer,
515
+ });
498
516
  },
499
517
  [
500
518
  page,
501
519
  prepareRow,
520
+ subComponent,
502
521
  rowProps,
503
522
  onRowInViewportRef,
504
523
  onBottomReachedRef,
505
524
  intersectionMargin,
506
525
  state,
507
526
  onRowClickHandler,
508
- subComponent,
509
527
  isRowDisabled,
510
528
  hasAnySubRows,
511
529
  instance,
package/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
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/itwinui-react",
3
- "version": "3.15.4",
3
+ "version": "3.15.5",
4
4
  "author": "Bentley Systems",
5
5
  "license": "MIT",
6
6
  "type": "module",