From 01b9cf346ed8bc07d82a2f259594f1ea70e19b8f Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 4 Aug 2020 11:14:28 +0800 Subject: [PATCH] fix: Table empty filters throw warning close #25979 --- .../table/__tests__/Table.filter.test.js | 23 +++++++++++------ components/table/demo/head.md | 25 +------------------ .../table/hooks/useFilter/FilterDropdown.tsx | 24 ++++++++++-------- 3 files changed, 30 insertions(+), 42 deletions(-) diff --git a/components/table/__tests__/Table.filter.test.js b/components/table/__tests__/Table.filter.test.js index 8a4990d9a591..ffff2c32abfb 100644 --- a/components/table/__tests__/Table.filter.test.js +++ b/components/table/__tests__/Table.filter.test.js @@ -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', () => { diff --git a/components/table/demo/head.md b/components/table/demo/head.md index d1e4ab9e1de3..dc0f9e31b532 100644 --- a/components/table/demo/head.md +++ b/components/table/demo/head.md @@ -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, diff --git a/components/table/hooks/useFilter/FilterDropdown.tsx b/components/table/hooks/useFilter/FilterDropdown.tsx index 19d1e895df6e..cdd1d5c3caf2 100644 --- a/components/table/hooks/useFilter/FilterDropdown.tsx +++ b/components/table/hooks/useFilter/FilterDropdown.tsx @@ -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 ( - + <> + + ); } return filters.map((filter, index) => {