mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Table: Fix filter crashes table (#48258)
This commit is contained in:
parent
430b9ae5cb
commit
9df26c7b7c
@ -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', 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user