Skip to content

Commit

Permalink
fix: Table empty filters throw warning
Browse files Browse the repository at this point in the history
close #25979
  • Loading branch information
afc163 committed Aug 4, 2020
1 parent c4418d0 commit 01b9cf3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 42 deletions.
23 changes: 15 additions & 8 deletions components/table/__tests__/Table.filter.test.js
Expand Up @@ -82,16 +82,23 @@ describe('Table.filter', () => {
});

it('renders empty menu correctly', () => {
const wrapper = mount(createTable({
columns: [
{
...column,
filters: [],
},
],
}));
jest.spyOn(console, 'error').mockImplementation(() => undefined);
const wrapper = mount(
createTable({
columns: [
{
...column,
filters: [],
},
],
}),
);
wrapper.find('span.ant-dropdown-trigger').simulate('click', nativeEvent);
expect(wrapper.find('Empty').length).toBe(1);
// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled();
// eslint-disable-next-line no-console
console.error.mockRestore();
});

it('renders radio filter correctly', () => {
Expand Down
25 changes: 1 addition & 24 deletions components/table/demo/head.md
Expand Up @@ -36,30 +36,7 @@ const columns = [
{
title: 'Name',
dataIndex: 'name',
filters: [
{
text: 'Joe',
value: 'Joe',
},
{
text: 'Jim',
value: 'Jim',
},
{
text: 'Submenu',
value: 'Submenu',
children: [
{
text: 'Green',
value: 'Green',
},
{
text: 'Black',
value: 'Black',
},
],
},
],
filters: [],
// specify the condition of filtering result
// here is that finding the name started with `value`
onFilter: (value, record) => record.name.indexOf(value) === 0,
Expand Down
24 changes: 14 additions & 10 deletions components/table/hooks/useFilter/FilterDropdown.tsx
Expand Up @@ -34,17 +34,21 @@ function renderFilterItems({
locale: TableLocale;
}) {
if (filters.length === 0) {
// wrapped with <></> to avoid react warning
// https://github.com/ant-design/ant-design/issues/25979
return (
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={locale.filterEmptyText}
style={{
margin: '16px 0',
}}
imageStyle={{
height: 24,
}}
/>
<>
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={locale.filterEmptyText}
style={{
margin: '16px 0',
}}
imageStyle={{
height: 24,
}}
/>
</>
);
}
return filters.map((filter, index) => {
Expand Down

0 comments on commit 01b9cf3

Please sign in to comment.