Skip to content

Commit

Permalink
fix(useAntdTable): reset pageSize (#2178)
Browse files Browse the repository at this point in the history
* Revert "fix(useAntdTable): reset pageSize (#2090)"

This reverts commit 2d2cd69.

* fix: use defaultParams pageSize when defaultPageSize is not passed

* fix: does not affect submit
  • Loading branch information
hchlq authored Apr 30, 2023
1 parent b92ca0e commit 112c2ef
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
46 changes: 45 additions & 1 deletion packages/hooks/src/useAntdTable/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import useAntdTable from '../index';
interface Query {
current: number;
pageSize: number;

[key: string]: any;
}

Expand Down Expand Up @@ -233,7 +234,7 @@ describe('useAntdTable', () => {
expect(queryArgs.name).toBe('change name');
});

it('should reset params work', async () => {
it('should reset pageSize in defaultParams', async () => {
queryArgs = undefined;
form.resetFields();
act(() => {
Expand Down Expand Up @@ -276,4 +277,47 @@ describe('useAntdTable', () => {
expect(queryArgs.pageSize).toBe(10);
});
});

it('should reset pageSize in defaultPageSize', async () => {
queryArgs = undefined;
form.resetFields();
act(() => {
hook = setUp(asyncFn, {
form,
defaultParams: {
current: 1,
pageSize: 10,
},
defaultPageSize: 20,
});
});

const { search, tableProps } = hook.result.current;
expect(tableProps.loading).toBe(false);
await waitFor(() => expect(queryArgs.current).toBe(1));
expect(queryArgs.pageSize).toBe(20);

// change params
act(() => {
tableProps.onChange({
current: 2,
pageSize: 5,
});
});

await waitFor(() => {
expect(queryArgs.current).toBe(2);
expect(queryArgs.pageSize).toBe(5);
});

// reset params
act(() => {
search.reset();
});

await waitFor(() => {
expect(queryArgs.current).toBe(1);
expect(queryArgs.pageSize).toBe(20);
});
});
});
11 changes: 5 additions & 6 deletions packages/hooks/src/useAntdTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,11 @@ const useAntdTable = <TData extends Data, TParams extends Params>(
if (form) {
form.resetFields();
}
_submit(
defaultParams?.[0] || {
pageSize: options.defaultPageSize || 10,
current: 1,
},
);
_submit({
...(defaultParams?.[0] || {}),
pageSize: options.defaultPageSize || options.defaultParams?.[0]?.pageSize || 10,
current: 1,
});
};

const submit = (e?: any) => {
Expand Down

0 comments on commit 112c2ef

Please sign in to comment.