Skip to content

Commit

Permalink
Table: Fix filter crashes table (#48258)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9df26c7)
  • Loading branch information
zoltanbedi authored and grafanabot committed Apr 26, 2022
1 parent 7ea5d25 commit 5b8d34c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/grafana-ui/src/components/Table/Filter.tsx
Expand Up @@ -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" />
Expand Down
31 changes: 31 additions & 0 deletions packages/grafana-ui/src/components/Table/Table.test.tsx
Expand Up @@ -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);
});
});
});
2 changes: 1 addition & 1 deletion packages/grafana-ui/src/components/Table/Table.tsx
Expand Up @@ -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;
Expand Down

0 comments on commit 5b8d34c

Please sign in to comment.