mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 20:19:44 +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 />);
|
||||
});
|
||||
|
||||
// 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);
|
||||
};
|
||||
|
||||
const transformColumns = React.useMemo(() => {
|
||||
return (innerColumns: ColumnsType<RecordType>) =>
|
||||
injectFilter(
|
||||
prefixCls,
|
||||
dropdownPrefixCls,
|
||||
innerColumns,
|
||||
mergedFilterStates,
|
||||
triggerFilter,
|
||||
getPopupContainer,
|
||||
tableLocale,
|
||||
);
|
||||
}, [mergedFilterStates]);
|
||||
const transformColumns = (innerColumns: ColumnsType<RecordType>) =>
|
||||
injectFilter(
|
||||
prefixCls,
|
||||
dropdownPrefixCls,
|
||||
innerColumns,
|
||||
mergedFilterStates,
|
||||
triggerFilter,
|
||||
getPopupContainer,
|
||||
tableLocale,
|
||||
);
|
||||
|
||||
return [transformColumns, mergedFilterStates, getFilters];
|
||||
}
|
||||
|
@ -362,11 +362,8 @@ export default function useFilterSorter<RecordType>({
|
||||
onSorterChange(generateSorterInfo(newSorterStates), newSorterStates);
|
||||
}
|
||||
|
||||
const transformColumns = React.useCallback(
|
||||
(innerColumns: ColumnsType<RecordType>) =>
|
||||
injectSorter(prefixCls, innerColumns, mergedSorterStates, triggerSorter, sortDirections),
|
||||
[mergedSorterStates],
|
||||
);
|
||||
const transformColumns = (innerColumns: ColumnsType<RecordType>) =>
|
||||
injectSorter(prefixCls, innerColumns, mergedSorterStates, triggerSorter, sortDirections);
|
||||
|
||||
const getSorters = () => {
|
||||
return generateSorterInfo(mergedSorterStates);
|
||||
|
Loading…
Reference in New Issue
Block a user