-
Notifications
You must be signed in to change notification settings - Fork 190
feat: org projects pagination and add archived pagination #2312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2a058be
82cc38d
11e460c
cc9a62c
86048c1
655b053
4f4c679
7287571
6ad7ee1
c8bbb97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
HarshMN2345 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,25 +18,69 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) => | |
const offset = pageToOffset(page, limit); | ||
const search = getSearch(url); | ||
|
||
const projects = await sdk.forConsole.projects.list({ | ||
queries: [ | ||
Query.offset(offset), | ||
Query.equal('teamId', params.organization), | ||
Query.limit(limit), | ||
Query.orderDesc('') | ||
], | ||
search: search || undefined | ||
}); | ||
const archivedPageRaw = parseInt(url.searchParams.get('archivedPage') || '1', 10); | ||
const archivedPage = | ||
Number.isFinite(archivedPageRaw) && archivedPageRaw > 0 ? archivedPageRaw : 1; | ||
const archivedOffset = pageToOffset(archivedPage, limit); | ||
const [activeProjects, archivedProjects, activeTotal, archivedTotal] = await Promise.all([ | ||
sdk.forConsole.projects.list({ | ||
queries: [ | ||
Query.offset(offset), | ||
Query.equal('teamId', params.organization), | ||
Query.or([Query.equal('status', 'active'), Query.isNull('status')]), | ||
Query.limit(limit), | ||
Query.orderDesc('') | ||
], | ||
search: search || undefined | ||
}), | ||
sdk.forConsole.projects.list({ | ||
queries: [ | ||
Query.offset(archivedOffset), | ||
Query.equal('teamId', params.organization), | ||
Query.equal('status', 'archived'), | ||
Query.limit(limit), | ||
Query.orderDesc('') | ||
], | ||
search: search || undefined | ||
}), | ||
sdk.forConsole.projects.list({ | ||
queries: [ | ||
Query.equal('teamId', params.organization), | ||
Query.or([Query.equal('status', 'active'), Query.isNull('status')]) | ||
], | ||
search: search || undefined | ||
}), | ||
sdk.forConsole.projects.list({ | ||
queries: [ | ||
Query.equal('teamId', params.organization), | ||
Query.equal('status', 'archived') | ||
], | ||
search: search || undefined | ||
}) | ||
]); | ||
Comment on lines
+25
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainOptional: verify Empty field name may be ignored or error depending on SDK version. Confirm intended default ordering or set an explicit field (e.g., createdAt/updatedAt). 🌐 Web query:
💡 Result: No — an empty string is not a valid field for Query.orderDesc(''). To sort by most-recently-created use the created timestamp field (Appwrite exposes $createdAt). Example: Query.orderDesc('$createdAt') — (escape the $ if your language/string parser requires, e.g. '$createdAt' in Flutter). You can also use $sequence for insertion order if preferred. [1][2][3] Use explicit timestamp field in Query.orderDesc 🤖 Prompt for AI Agents
|
||
|
||
// set `default` if no region! | ||
for (const project of projects.projects) { | ||
for (const project of activeProjects.projects) { | ||
project.region ??= 'default'; | ||
} | ||
for (const project of archivedProjects.projects) { | ||
project.region ??= 'default'; | ||
} | ||
|
||
return { | ||
offset, | ||
limit, | ||
projects, | ||
projects: { | ||
...activeProjects, | ||
projects: activeProjects.projects, | ||
total: activeTotal.total | ||
}, | ||
activeProjectsPage: activeProjects.projects, | ||
archivedProjectsPage: archivedProjects.projects, | ||
activeTotalOverall: activeTotal.total, | ||
archivedTotalOverall: archivedTotal.total, | ||
archivedOffset, | ||
archivedPage, | ||
search | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix off-by-one when recomputing page after limit change.
newPage
needs a +1 to convert from 0-based index to 1-based page. Without it, unchanged limits incorrectly drop page N to page N-1, and scaling limits can jump to the wrong page.Apply:
📝 Committable suggestion
🤖 Prompt for AI Agents