Table: Fix filter crashes table (#48258) (#48261)

(cherry picked from commit 9df26c7b7c)

Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2022-04-26 14:04:30 +02:00
committed by GitHub
co-authored by Zoltán Bedi
parent b07c7797f3
commit a5fd91e492
3 changed files with 33 additions and 1 deletions
@@ -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" />
@@ -177,4 +177,35 @@ describe('Table', () => {
]);
});
});
describe('on filtering', () => {
it('the rows should be filtered', () => {
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);
userEvent.click(within(getColumnHeader(/number/)).getByRole('filterIcon'));
userEvent.click(screen.getByLabelText('1'));
userEvent.click(screen.getByText('Ok'));
// 3 + header row
expect(within(getTable()).getAllByRole('row')).toHaveLength(4);
});
});
});
@@ -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;