Skip to content

Commit

Permalink
feat(AnalyticalTable): introduce additionalEmptyRowsCount prop (#5412)
Browse files Browse the repository at this point in the history
Fixes #5278
  • Loading branch information
Lukas742 authored Jan 15, 2024
1 parent f9b7b0e commit e33c227
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
AnalyticalTableScaleWidthMode,
AnalyticalTableSelectionBehavior,
AnalyticalTableSubComponentsBehavior,
AnalyticalTableVisibleRowCountMode,
Button,
Input
} from '../..';
Expand Down Expand Up @@ -1086,7 +1085,15 @@ describe('AnalyticalTable', () => {
>
Data 100
</Button>
<Button
onClick={() => {
setData(data.slice(0, 10));
}}
>
Data 10
</Button>
<AnalyticalTable
{...props}
ref={tableRef}
data-testid="at"
data={internalData}
Expand Down Expand Up @@ -1135,6 +1142,15 @@ describe('AnalyticalTable', () => {
cy.findByText('Name91').should('be.visible');
cy.findByText('Rows: 150').should('be.visible');
cy.get('@more').should('have.been.calledThrice');

//additionalEmptyRowsCount
cy.mount(<TestComp onLoadMore={onLoadMore} additionalEmptyRowsCount={1} />);
cy.get('[data-empty-row="true"]').should('not.exist');
cy.findByText('Data 10').click();
cy.findByText('Rows: 10').should('be.visible');
cy.get('[data-empty-row="true"]').should('exist').should('not.be.visible');
cy.findByTestId('scrollInput').typeIntoUi5Input('11{enter}', { force: true });
cy.findByText('Rows: 60').should('be.visible');
});

it('InfiniteScroll: Tree', () => {
Expand Down Expand Up @@ -2660,6 +2676,17 @@ describe('AnalyticalTable', () => {
cy.findByText('12').should('not.be.visible');
});

it('additionalEmptyRowsCount', () => {
cy.mount(<AnalyticalTable data={data} columns={columns} minRows={4} />);
cy.get('[data-empty-row]').should('not.exist');
cy.mount(<AnalyticalTable data={data} columns={columns} minRows={4} additionalEmptyRowsCount={1} />);
cy.get('[data-empty-row]').should('exist').and('not.be.visible');
cy.mount(<AnalyticalTable data={data} columns={columns} minRows={4} additionalEmptyRowsCount={5} />);
cy.get('[data-empty-row]').should('exist').and('have.length', 5).and('not.be.visible');
cy.get('[data-component-name="AnalyticalTableBody"]').scrollTo('bottom');
cy.get('[data-empty-row]').should('exist').and('have.length', 5).and('be.visible');
});

cypressPassThroughTestsFactory(AnalyticalTable, { data, columns });
});

Expand Down
19 changes: 11 additions & 8 deletions packages/main/src/components/AnalyticalTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
onTableScroll,
LoadingComponent,
NoDataComponent,
additionalEmptyRowsCount = 0,
alwaysShowSubComponent: _omit,
...rest
} = props;
Expand Down Expand Up @@ -748,13 +749,15 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
classes={classes}
prepareRow={prepareRow}
rows={rows}
itemCount={Math.max(
minRows,
rows.length,
visibleRowCountMode === AnalyticalTableVisibleRowCountMode.AutoWithEmptyRows
? internalVisibleRowCount
: 0
)}
itemCount={
Math.max(
minRows,
rows.length,
visibleRowCountMode === AnalyticalTableVisibleRowCountMode.AutoWithEmptyRows
? internalVisibleRowCount
: 0
) + (!tableState.isScrollable ? additionalEmptyRowsCount : 0)
}
scrollToRef={scrollToRef}
isTreeTable={isTreeTable}
internalRowHeight={internalRowHeight}
Expand All @@ -779,7 +782,7 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
</VirtualTableBodyContainer>
)}
</div>
{(tableState.isScrollable === undefined || tableState.isScrollable) && (
{(additionalEmptyRowsCount || tableState.isScrollable === undefined || tableState.isScrollable) && (
<VerticalScrollbar
tableBodyHeight={tableBodyHeight}
internalRowHeight={internalHeaderRowHeight}
Expand Down
11 changes: 10 additions & 1 deletion packages/main/src/components/AnalyticalTable/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,16 @@ export interface AnalyticalTablePropTypes extends Omit<CommonProps, 'title'> {
| AnalyticalTableVisibleRowCountMode
| keyof typeof AnalyticalTableVisibleRowCountMode
| TableVisibleRowCountMode;

/**
* Specifies the number of additional empty rows added to the bottom of a table that is normally __non__ scrollable.
* Use this prop if you want to ensure that the table is scrollable.
*
* __Note:__ It's recommended to use this prop only if `infiniteScroll` is applied and where assessing scrollability is not possible across various resolutions or datasets.
* E.g., when using `visibleRowCountMode` with values `"Auto"` or `"AutoWithEmptyRows"`.
*
* __Note:__ This prop has no effect if the table is already scrollable without additional empty rows.
*/
additionalEmptyRowsCount?: number;
/**
* The number of rows visible without going into overflow.
*
Expand Down

0 comments on commit e33c227

Please sign in to comment.