🗨️ 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

@ -21,9 +21,12 @@ export function formatPromptGroupsResponse({
hasMore?: boolean;
after?: string | null;
}): PromptGroupsListResponse {
const effectivePageSize = parseInt(pageSize || '') || parseInt(String(actualLimit || '')) || 10;
const totalPages =
promptGroups.length > 0 ? Math.ceil(promptGroups.length / effectivePageSize).toString() : '0';
const currentPage = parseInt(pageNumber || '1');
// Calculate total pages based on whether there are more results
// If hasMore is true, we know there's at least one more page
// We use a high number (9999) to indicate "many pages" since we don't know the exact count
const totalPages = hasMore ? '9999' : currentPage.toString();
return {
promptGroups,

View file

@ -252,8 +252,19 @@ export const getPromptGroup = (_id: string) => `${prompts()}/groups/${_id}`;
export const getPromptGroupsWithFilters = (filter: object) => {
let url = `${prompts()}/groups`;
if (Object.keys(filter).length > 0) {
const queryParams = new URLSearchParams(filter as Record<string, string>).toString();
// Filter out undefined/null values
const cleanedFilter = Object.entries(filter).reduce(
(acc, [key, value]) => {
if (value !== undefined && value !== null && value !== '') {
acc[key] = value;
}
return acc;
},
{} as Record<string, string>,
);
if (Object.keys(cleanedFilter).length > 0) {
const queryParams = new URLSearchParams(cleanedFilter).toString();
url += `?${queryParams}`;
}
return url;

View file

@ -536,8 +536,10 @@ export type TPromptsWithFilterRequest = {
export type TPromptGroupsWithFilterRequest = {
category: string;
pageNumber: string;
pageSize: string | number;
pageNumber?: string; // Made optional for cursor-based pagination
pageSize?: string | number;
limit?: string | number; // For cursor-based pagination
cursor?: string; // For cursor-based pagination
before?: string | null;
after?: string | null;
order?: 'asc' | 'desc';
@ -550,6 +552,8 @@ export type PromptGroupListResponse = {
pageNumber: string;
pageSize: string | number;
pages: string | number;
has_more: boolean; // Added for cursor-based pagination
after: string | null; // Added for cursor-based pagination
};
export type PromptGroupListData = InfiniteData<PromptGroupListResponse>;