mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-03 20:49:14 +08:00
fix: Table onChange return cached data (#20858)
This commit is contained in:
parent
e3b0104c53
commit
f470f3e1e4
@ -1104,4 +1104,71 @@ describe('Table.filter', () => {
|
|||||||
|
|
||||||
mount(<TestTable />);
|
mount(<TestTable />);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// https://github.com/ant-design/ant-design/issues/20854
|
||||||
|
it('Not cache for onChange state', () => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
|
||||||
|
const wrapper = mount(
|
||||||
|
<Table
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
title: 'Name',
|
||||||
|
dataIndex: 'name',
|
||||||
|
sorter: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Gender',
|
||||||
|
dataIndex: 'gender',
|
||||||
|
filters: [
|
||||||
|
{ text: 'Male', value: 'male' },
|
||||||
|
{ text: 'Female', value: 'female' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
dataSource={[]}
|
||||||
|
onChange={onChange}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Sort it
|
||||||
|
wrapper.find('.ant-table-column-sorters').simulate('click');
|
||||||
|
expect(onChange).toHaveBeenCalledWith(
|
||||||
|
expect.anything(),
|
||||||
|
{
|
||||||
|
gender: null,
|
||||||
|
},
|
||||||
|
expect.objectContaining({
|
||||||
|
column: {
|
||||||
|
dataIndex: 'name',
|
||||||
|
sorter: true,
|
||||||
|
title: 'Name',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
expect.anything(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Filter it
|
||||||
|
onChange.mockReset();
|
||||||
|
wrapper.find('span.ant-dropdown-trigger').simulate('click', nativeEvent);
|
||||||
|
wrapper
|
||||||
|
.find('.ant-dropdown-menu-item')
|
||||||
|
.first()
|
||||||
|
.simulate('click');
|
||||||
|
wrapper.find('.ant-table-filter-dropdown-link.confirm').simulate('click');
|
||||||
|
expect(onChange).toHaveBeenCalledWith(
|
||||||
|
expect.anything(),
|
||||||
|
{
|
||||||
|
gender: ['male'],
|
||||||
|
},
|
||||||
|
expect.objectContaining({
|
||||||
|
column: {
|
||||||
|
dataIndex: 'name',
|
||||||
|
sorter: true,
|
||||||
|
title: 'Name',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
expect.anything(),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -208,18 +208,16 @@ function useFilter<RecordType>({
|
|||||||
onFilterChange(generateFilterInfo(newFilterStates), newFilterStates);
|
onFilterChange(generateFilterInfo(newFilterStates), newFilterStates);
|
||||||
};
|
};
|
||||||
|
|
||||||
const transformColumns = React.useMemo(() => {
|
const transformColumns = (innerColumns: ColumnsType<RecordType>) =>
|
||||||
return (innerColumns: ColumnsType<RecordType>) =>
|
injectFilter(
|
||||||
injectFilter(
|
prefixCls,
|
||||||
prefixCls,
|
dropdownPrefixCls,
|
||||||
dropdownPrefixCls,
|
innerColumns,
|
||||||
innerColumns,
|
mergedFilterStates,
|
||||||
mergedFilterStates,
|
triggerFilter,
|
||||||
triggerFilter,
|
getPopupContainer,
|
||||||
getPopupContainer,
|
tableLocale,
|
||||||
tableLocale,
|
);
|
||||||
);
|
|
||||||
}, [mergedFilterStates]);
|
|
||||||
|
|
||||||
return [transformColumns, mergedFilterStates, getFilters];
|
return [transformColumns, mergedFilterStates, getFilters];
|
||||||
}
|
}
|
||||||
|
@ -362,11 +362,8 @@ export default function useFilterSorter<RecordType>({
|
|||||||
onSorterChange(generateSorterInfo(newSorterStates), newSorterStates);
|
onSorterChange(generateSorterInfo(newSorterStates), newSorterStates);
|
||||||
}
|
}
|
||||||
|
|
||||||
const transformColumns = React.useCallback(
|
const transformColumns = (innerColumns: ColumnsType<RecordType>) =>
|
||||||
(innerColumns: ColumnsType<RecordType>) =>
|
injectSorter(prefixCls, innerColumns, mergedSorterStates, triggerSorter, sortDirections);
|
||||||
injectSorter(prefixCls, innerColumns, mergedSorterStates, triggerSorter, sortDirections),
|
|
||||||
[mergedSorterStates],
|
|
||||||
);
|
|
||||||
|
|
||||||
const getSorters = () => {
|
const getSorters = () => {
|
||||||
return generateSorterInfo(mergedSorterStates);
|
return generateSorterInfo(mergedSorterStates);
|
||||||
|
Loading…
Reference in New Issue
Block a user