🗨️ fix: Prompts Pagination (#9385)

* 🗨️ fix: Prompts Pagination

* ci: Simplify user middleware setup in prompt tests
This commit is contained in:
Danny Avila 2025-08-30 15:58:49 -04:00 committed by GitHub
parent 3a47deac07
commit 460eac36f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 536 additions and 237 deletions

View file

@ -400,22 +400,27 @@ export const usePromptGroupsInfiniteQuery = (
params?: t.TPromptGroupsWithFilterRequest,
config?: UseInfiniteQueryOptions<t.PromptGroupListResponse, unknown>,
) => {
const { name, pageSize, category, ...rest } = params || {};
const { name, pageSize, category } = params || {};
return useInfiniteQuery<t.PromptGroupListResponse, unknown>(
[QueryKeys.promptGroups, name, category, pageSize],
({ pageParam = '1' }) =>
dataService.getPromptGroups({
...rest,
({ pageParam }) => {
const queryParams: t.TPromptGroupsWithFilterRequest = {
name,
category: category || '',
pageNumber: pageParam?.toString(),
pageSize: (pageSize || 10).toString(),
}),
limit: (pageSize || 10).toString(),
};
// Only add cursor if it's a valid string
if (pageParam && typeof pageParam === 'string') {
queryParams.cursor = pageParam;
}
return dataService.getPromptGroups(queryParams);
},
{
getNextPageParam: (lastPage) => {
const currentPageNumber = Number(lastPage.pageNumber);
const totalPages = Number(lastPage.pages);
return currentPageNumber < totalPages ? currentPageNumber + 1 : undefined;
// Use cursor-based pagination - ensure we return a valid cursor or undefined
return lastPage.has_more && lastPage.after ? lastPage.after : undefined;
},
refetchOnWindowFocus: false,
refetchOnReconnect: false,