Skip to content

Commit d2cd2e2

Browse files
committed
Fix useInfiniteListController does not return response meta
1 parent b225a5e commit d2cd2e2

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

packages/ra-core/src/controller/list/useInfiniteListController.spec.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,4 +740,38 @@ describe('useInfiniteListController', () => {
740740
expect(authProvider.canAccess).not.toHaveBeenCalled();
741741
});
742742
});
743+
744+
describe('response metadata', () => {
745+
it('should return response metadata as meta', async () => {
746+
const getList = jest.fn().mockImplementation(() =>
747+
Promise.resolve({
748+
data: [],
749+
total: 0,
750+
meta: { foo: 'bar' },
751+
})
752+
);
753+
const dataProvider = testDataProvider({ getList });
754+
const children = jest.fn().mockReturnValue(<span>children</span>);
755+
const props = {
756+
...defaultProps,
757+
children,
758+
};
759+
render(
760+
<CoreAdminContext dataProvider={dataProvider}>
761+
<InfiniteListController {...props} />
762+
</CoreAdminContext>
763+
);
764+
await waitFor(() => {
765+
expect(children).toHaveBeenCalledWith(
766+
expect.objectContaining({
767+
page: 1,
768+
total: 0,
769+
hasNextPage: false,
770+
hasPreviousPage: false,
771+
meta: { foo: 'bar' },
772+
})
773+
);
774+
});
775+
});
776+
});
743777
});

packages/ra-core/src/controller/list/useInfiniteListController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export const useInfiniteListController = <
111111
fetchPreviousPage,
112112
isFetchingPreviousPage,
113113
refetch,
114+
meta: responseMeta,
114115
} = useInfiniteGetList<RecordType, ErrorType>(
115116
resource,
116117
{
@@ -223,6 +224,7 @@ export const useInfiniteListController = <
223224
isFetchingNextPage,
224225
fetchPreviousPage,
225226
isFetchingPreviousPage,
227+
meta: responseMeta,
226228
} as InfiniteListControllerResult<RecordType, ErrorType>;
227229
};
228230

packages/ra-core/src/controller/list/useListController.spec.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,4 +719,38 @@ describe('useListController', () => {
719719
).toBeNull();
720720
});
721721
});
722+
723+
describe('response metadata', () => {
724+
it('should return response metadata as meta', async () => {
725+
const getList = jest.fn().mockImplementation(() =>
726+
Promise.resolve({
727+
data: [],
728+
total: 0,
729+
meta: { foo: 'bar' },
730+
})
731+
);
732+
const dataProvider = testDataProvider({ getList });
733+
const children = jest.fn().mockReturnValue(<span>children</span>);
734+
const props = {
735+
...defaultProps,
736+
children,
737+
};
738+
render(
739+
<CoreAdminContext dataProvider={dataProvider}>
740+
<ListController {...props} />
741+
</CoreAdminContext>
742+
);
743+
await waitFor(() => {
744+
expect(children).toHaveBeenCalledWith(
745+
expect.objectContaining({
746+
page: 1,
747+
total: 0,
748+
hasNextPage: false,
749+
hasPreviousPage: false,
750+
meta: { foo: 'bar' },
751+
})
752+
);
753+
});
754+
});
755+
});
722756
});

packages/ra-core/src/dataProvider/useInfiniteGetList.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,5 @@ export type UseInfiniteGetListHookValue<
275275
> & {
276276
total?: number;
277277
pageParam?: number;
278+
meta?: any;
278279
};

0 commit comments

Comments
 (0)