Table: Fix filter crashes table (#48258)

This commit is contained in:
Zoltán Bedi 2022-04-26 13:26:48 +02:00 committed by GitHub
parent 430b9ae5cb
commit 9df26c7b7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 1 deletions

View File

@ -32,6 +32,7 @@ export const Filter: FC<Props> = ({ column, field, tableStyles }) => {
<span
className={cx(tableStyles.headerFilter, filterEnabled ? styles.filterIconEnabled : styles.filterIconDisabled)}
ref={ref}
role="filterIcon"
onClick={onShowPopover}
>
<Icon name="filter" />

View File

@ -177,4 +177,35 @@ describe('Table', () => {
]);
});
});
describe('on filtering', () => {
it('the rows should be filtered', async () => {
getTestContext({
data: toDataFrame({
name: 'A',
fields: [
{
name: 'number',
type: FieldType.number,
values: [1, 1, 1, 2, 2, 3, 4, 5],
config: {
custom: {
filterable: true,
},
},
},
],
}),
});
expect(within(getTable()).getAllByRole('row')).toHaveLength(9);
await userEvent.click(within(getColumnHeader(/number/)).getByRole('filterIcon'));
await userEvent.click(screen.getByLabelText('1'));
await userEvent.click(screen.getByText('Ok'));
// 3 + header row
expect(within(getTable()).getAllByRole('row')).toHaveLength(4);
});
});
});

View File

@ -251,7 +251,7 @@ export const Table: FC<Props> = memo((props: Props) => {
[gotoPage]
);
const itemCount = enablePagination ? page.length : data.length;
const itemCount = enablePagination ? page.length : rows.length;
let paginationEl = null;
if (enablePagination) {
const itemsRangeStart = state.pageIndex * state.pageSize + 1;