-
Notifications
You must be signed in to change notification settings - Fork 191
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 2 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -28,15 +28,42 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) => | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
search: search || undefined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let allProjects: typeof projects.projects = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let fetchedCount = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const total = projects.total; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
while (fetchedCount < total) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HarshMN2345 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const next = await sdk.forConsole.projects.list({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
queries: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Query.offset(fetchedCount), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Query.equal('teamId', params.organization), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Query.limit(limit), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Query.orderDesc('') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
search: search || undefined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
allProjects = allProjects.concat(next.projects); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fetchedCount += next.projects.length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (next.projects.length === 0) break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
let allProjects: typeof projects.projects = []; | |
let fetchedCount = 0; | |
const total = projects.total; | |
while (fetchedCount < total) { | |
const next = await sdk.forConsole.projects.list({ | |
queries: [ | |
Query.offset(fetchedCount), | |
Query.equal('teamId', params.organization), | |
Query.limit(limit), | |
Query.orderDesc('') | |
], | |
search: search || undefined | |
}); | |
allProjects = allProjects.concat(next.projects); | |
fetchedCount += next.projects.length; | |
if (next.projects.length === 0) break; | |
} | |
// Seed with the initial page of projects instead of starting empty | |
let allProjects: typeof projects.projects = projects.projects.slice(); | |
let fetchedCount = allProjects.length; | |
const total = projects.total; | |
while (fetchedCount < total) { | |
const next = await sdk.forConsole.projects.list({ | |
queries: [ | |
Query.offset(fetchedCount), | |
Query.equal('teamId', params.organization), | |
Query.limit(limit), | |
Query.orderDesc('') | |
], | |
search: search || undefined | |
}); | |
allProjects = allProjects.concat(next.projects); | |
fetchedCount += next.projects.length; | |
if (next.projects.length === 0) break; | |
} |
🤖 Prompt for AI Agents
In src/routes/(console)/organization-[organization]/+page.ts around lines 31 to
48, the code currently performs an initial projects fetch but then starts the
loop that refetches from offset 0, doubling cost and latency; instead, perform
the first sdk.forConsole.projects.list call once, initialize allProjects with
that response and set fetchedCount to that response.projects.length, then enter
a loop that requests subsequent pages starting at the current fetchedCount
(using Query.offset(fetchedCount)) until fetchedCount >= total or a page returns
zero items; this removes the redundant page-0 fetch while preserving the same
paging logic.
HarshMN2345 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
💡 Verification agent
🧩 Analysis chain
Don’t mutate the projects
contract; return aggregates separately
Overwriting projects.projects
with all items and projects.total
with “active total” breaks consumers expecting API semantics. Keep projects
intact and expose new top-level fields for UI.
- projects: { ...projects, projects: allProjects, total: allActiveProjects.length },
- activeProjectsPage: activeProjectsForPage,
- archivedProjectsPage: allArchivedProjects,
- activeTotalOverall: allActiveProjects.length,
+ projects, // preserve API contract for stores and other consumers
+ activeProjectsPage: activeProjectsForPage,
+ archivedProjectsPage: allArchivedProjects,
+ activeTotalOverall: allActiveProjects.length,
+ // Optionally expose allProjects if needed elsewhere:
+ // allProjects,
🏁 Script executed:
#!/bin/bash
# Audit for consumers that assume `projects.total` is "all results" (not just active).
rg -nP --type=ts --type=svelte -C2 '\bprojects\.total\b'
Length of output: 89
🏁 Script executed:
#!/bin/bash
# Audit for consumers that assume `projects.total` remains the full count
rg -nP -g '*.ts' -g '*.svelte' -C2 '\bprojects\.total\b'
Length of output: 4397
Preserve projects
API contract and expose aggregates separately
Overriding projects.projects
and projects.total
with active-only values breaks UI components that rely on the full project count (plan checks, creation modals, settings pages). Undo the mutation and introduce new top-level fields for the aggregates, for example:
- projects: { ...projects, projects: allProjects, total: allActiveProjects.length },
+ projects, // preserve API contract
activeProjectsPage: activeProjectsForPage,
archivedProjectsPage: allArchivedProjects,
+ activeTotalOverall: allActiveProjects.length,
+ allProjects, // full list if needed
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In src/routes/(console)/organization-[organization]/+page.ts around lines 63 to
67, the code is mutating the existing projects object by replacing
projects.projects and projects.total with active-only values which breaks
consumers expecting the full projects API; revert that mutation so the original
projects object remains intact and add new top-level fields (e.g.,
activeProjectsPage and activeProjectsTotal or activeProjectsAggregate) to expose
active-only lists and counts, update any callers that need the active-only
values to use these new fields, and ensure the returned payload preserves the
original projects structure while exposing the aggregates separately.
Uh oh!
There was an error while loading. Please reload this page.