Fix project status badges to show counts across all pages
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled

The status summary badges (Eligible, Rejected, Assigned, etc.) were
computed from only the current page's projects. Now uses a groupBy
query on the same filters to return statusCounts for all matching
projects across all pages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt
2026-02-19 09:33:14 +01:00
parent 1308c3ba87
commit 099157bf74
2 changed files with 14 additions and 8 deletions

View File

@@ -711,13 +711,7 @@ export default function ProjectsPage() {
{data && data.projects.length > 0 && (
<div className="flex items-center justify-between gap-4">
<div className="flex flex-wrap items-center gap-2 text-sm">
{Object.entries(
data.projects.reduce<Record<string, number>>((acc, p) => {
const s = p.status ?? 'SUBMITTED'
acc[s] = (acc[s] || 0) + 1
return acc
}, {})
)
{Object.entries(data.statusCounts ?? {})
.sort(([a], [b]) => {
const order = ['SUBMITTED', 'ELIGIBLE', 'ASSIGNED', 'SEMIFINALIST', 'FINALIST', 'WINNER', 'REJECTED', 'WITHDRAWN']
return order.indexOf(a) - order.indexOf(b)

View File

@@ -140,7 +140,7 @@ export const projectRouter = router({
}
}
const [projects, total] = await Promise.all([
const [projects, total, statusGroups] = await Promise.all([
ctx.prisma.project.findMany({
where,
skip,
@@ -152,14 +152,26 @@ export const projectRouter = router({
},
}),
ctx.prisma.project.count({ where }),
ctx.prisma.project.groupBy({
by: ['status'],
where,
_count: true,
}),
])
// Build status counts from groupBy (across all pages)
const statusCounts: Record<string, number> = {}
for (const g of statusGroups) {
statusCounts[g.status] = g._count
}
return {
projects,
total,
page,
perPage,
totalPages: Math.ceil(total / perPage),
statusCounts,
}
}),