Skip to content

Commit c262ef6

Browse files
authored
feat(AnalyticalTable): add IncludeHeightExpandable option to subComponentsBehavior prop (#5250)
Closes #1700
1 parent c4b3658 commit c262ef6

File tree

8 files changed

+57
-15
lines changed

8 files changed

+57
-15
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,33 @@ describe('AnalyticalTable', () => {
16391639
cy.findByText('SubComponent 2').should('be.visible');
16401640
cy.findByTitle('Expand Node').should('not.exist');
16411641
cy.findByTitle('Collapse Node').should('not.exist');
1642+
1643+
const loadMore = cy.spy().as('more');
1644+
cy.mount(
1645+
<AnalyticalTable
1646+
onLoadMore={loadMore}
1647+
infiniteScroll={true}
1648+
infiniteScrollThreshold={0}
1649+
data={data}
1650+
columns={columns}
1651+
renderRowSubComponent={renderRowSubComponentLarge}
1652+
visibleRows={3}
1653+
subComponentsBehavior={AnalyticalTableSubComponentsBehavior.IncludeHeightExpandable}
1654+
/>
1655+
);
1656+
cy.findByText('A').should('be.visible');
1657+
cy.findByText('X').should('be.visible');
1658+
cy.findByText('C').should('not.be.visible');
1659+
cy.get('[aria-rowindex="1"] > [aria-colindex="1"] > [title="Expand Node"] > [ui5-button]').click();
1660+
cy.findByText('A').should('be.visible');
1661+
cy.findByText('X').should('be.visible');
1662+
cy.findByText('C').should('not.be.visible');
1663+
cy.get('[aria-rowindex="2"] > [aria-colindex="1"] > [title="Expand Node"] > [ui5-button]').click();
1664+
cy.findByText('A').should('be.visible');
1665+
cy.findByText('X').should('be.visible');
1666+
cy.findByText('C').should('not.be.visible');
1667+
cy.get('[data-component-name="AnalyticalTableBody"]').scrollTo('bottom');
1668+
cy.get('@more').should('have.been.calledOnce');
16421669
});
16431670

16441671
it('pop-in columns', () => {

packages/main/src/components/AnalyticalTable/AnalyticalTable.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ The prop expects a function with an optional parameter containing the `row` inst
283283

284284
- When `renderRowSubComponent` is set, `grouping` is disabled.
285285
- When rendering active elements inside the subcomponent, make sure to add the `data-subcomponent-active-element' attribute, otherwise focus behavior won't be consistent.
286+
- When `AnalyticalTableSubComponentsBehavior.IncludeHeight` or `AnalyticalTableSubComponentsBehavior.IncludeHeightExpandable` is used, `AnalyticalTableVisibleRowCountMode.Interactive` is not supported.
286287

287288
<ControlsWithNote of={ComponentStories.Subcomponents} include={['renderRowSubComponent', 'subComponentsBehavior']} />
288289

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -478,15 +478,7 @@ export const Subcomponents: Story = {
478478
</FlexBox>
479479
);
480480
};
481-
return (
482-
<AnalyticalTable
483-
{...args}
484-
data={args.data}
485-
columns={args.columns}
486-
renderRowSubComponent={renderRowSubComponent}
487-
alwaysShowSubComponent={args.alwaysShowSubComponent}
488-
/>
489-
);
481+
return <AnalyticalTable {...args} renderRowSubComponent={renderRowSubComponent} />;
490482
}
491483
};
492484

packages/main/src/components/AnalyticalTable/TableBody/RowSubComponent.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ interface RowSubComponent {
2828
rowIndex: number;
2929
}
3030

31-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3231
export const RowSubComponent = (props: RowSubComponent) => {
3332
const {
3433
subComponentsHeight,

packages/main/src/components/AnalyticalTable/TableBody/VirtualTableBody.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useVirtualizer } from '@tanstack/react-virtual';
33
import { clsx } from 'clsx';
44
import type { MutableRefObject, ReactNode } from 'react';
55
import React, { useCallback, useMemo, useRef } from 'react';
6+
import { AnalyticalTableSubComponentsBehavior } from '../../../enums/index.js';
67
import type { ScrollToRefType } from '../interfaces.js';
78
import type { AnalyticalTablePropTypes, DivWithCustomScrollProp } from '../types/index.js';
89
import { getSubRowsByString } from '../util/index.js';
@@ -33,6 +34,7 @@ interface VirtualTableBodyProps {
3334
manualGroupBy?: boolean;
3435
subRowsKey: string;
3536
scrollContainerRef?: MutableRefObject<HTMLDivElement>;
37+
subComponentsBehavior: AnalyticalTablePropTypes['subComponentsBehavior'];
3638
}
3739

3840
const measureElement = (el: HTMLElement) => {
@@ -63,7 +65,8 @@ export const VirtualTableBody = (props: VirtualTableBodyProps) => {
6365
columnVirtualizer,
6466
manualGroupBy,
6567
subRowsKey,
66-
scrollContainerRef
68+
scrollContainerRef,
69+
subComponentsBehavior
6770
} = props;
6871

6972
const itemCount = Math.max(minRows, rows.length);
@@ -172,7 +175,13 @@ export const VirtualTableBody = (props: VirtualTableBodyProps) => {
172175
const isNavigatedCell = markNavigatedRow(row);
173176
const RowSubComponent = typeof renderRowSubComponent === 'function' ? renderRowSubComponent(row) : undefined;
174177

175-
if (!RowSubComponent && subComponentsHeight && subComponentsHeight?.[virtualRow.index]?.subComponentHeight) {
178+
if (
179+
(!RowSubComponent ||
180+
(subComponentsBehavior === AnalyticalTableSubComponentsBehavior.IncludeHeightExpandable &&
181+
!row.isExpanded)) &&
182+
subComponentsHeight &&
183+
subComponentsHeight?.[virtualRow.index]?.subComponentHeight
184+
) {
176185
dispatch({
177186
type: 'SUB_COMPONENTS_HEIGHT',
178187
payload: {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
278278

279279
const includeSubCompRowHeight =
280280
!!renderRowSubComponent &&
281-
subComponentsBehavior === AnalyticalTableSubComponentsBehavior.IncludeHeight &&
281+
(subComponentsBehavior === AnalyticalTableSubComponentsBehavior.IncludeHeight ||
282+
subComponentsBehavior === AnalyticalTableSubComponentsBehavior.IncludeHeightExpandable) &&
282283
!!tableState.subComponentsHeight &&
283284
!!Object.keys(tableState.subComponentsHeight);
284285

@@ -434,7 +435,6 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
434435
adjustTableHeightOnPopIn
435436
? popInRowHeight
436437
: internalRowHeight;
437-
438438
if (includeSubCompRowHeight) {
439439
let initialBodyHeightWithSubComps = 0;
440440
for (let i = 0; i < rowNum; i++) {
@@ -722,6 +722,7 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
722722
columnVirtualizer={columnVirtualizer}
723723
manualGroupBy={reactTableOptions?.manualGroupBy as boolean | undefined}
724724
subRowsKey={subRowsKey}
725+
subComponentsBehavior={subComponentsBehavior}
725726
/>
726727
</VirtualTableBodyContainer>
727728
)}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,11 @@ export interface AnalyticalTablePropTypes extends Omit<CommonProps, 'title'> {
549549
* - __"Expandable":__ Render subcomponents as expandable container of each row.
550550
* - __"Visible":__ Render subcomponents below each row.
551551
* - __"IncludeHeight":__ Render subcomponents below each row. The height of each initially visible subcomponent (defined by `visibleRows`) is taken into account when defining the body height of the table.
552+
* - __"IncludeHeightExpandable":__ Render subcomponents as expandable container of each row. The height of each expanded subcomponent of visible rows (defined by `visibleRows`) is taken into account when defining the body height of the table, so that the height of the table changes when a subcomponent is expanded/collapsed. (since: v1.23.0)
552553
*
553554
* __Default:__ `"Expandable"`
554555
*
556+
* @since 1.19.0
555557
*/
556558
subComponentsBehavior?: AnalyticalTableSubComponentsBehavior | keyof typeof AnalyticalTableSubComponentsBehavior;
557559
/**

packages/main/src/enums/AnalyticalTableSubComponentsBehavior.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ export enum AnalyticalTableSubComponentsBehavior {
1212
Visible = 'Visible',
1313
/**
1414
* Render subcomponents below each row. The height of each initially visible subcomponent (defined by `visibleRows`) is taken into account when defining the body height of the table.
15+
*
16+
* __Note:__ `AnalyticalTableVisibleRowCountMode.Interactive` is not supported with this mode.
1517
*/
16-
IncludeHeight = 'IncludeHeight'
18+
IncludeHeight = 'IncludeHeight',
19+
/**
20+
* Render subcomponents as expandable container of each row. The height of each expanded subcomponent of visible rows (defined by `visibleRows`) is taken into account when defining the body height of the table, so that the height of the table changes when a subcomponent is expanded/collapsed.
21+
*
22+
* __Note:__ This mode can lead to performance degradation, please use with caution!
23+
* __Note:__ `AnalyticalTableVisibleRowCountMode.Interactive` is not supported with this mode.
24+
*
25+
* @since 1.23.0
26+
*/
27+
IncludeHeightExpandable = 'IncludeHeightExpandable'
1728
}

0 commit comments

Comments
 (0)