Fix project status badges to show counts across all pages
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled
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:
@@ -711,13 +711,7 @@ export default function ProjectsPage() {
|
|||||||
{data && data.projects.length > 0 && (
|
{data && data.projects.length > 0 && (
|
||||||
<div className="flex items-center justify-between gap-4">
|
<div className="flex items-center justify-between gap-4">
|
||||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||||
{Object.entries(
|
{Object.entries(data.statusCounts ?? {})
|
||||||
data.projects.reduce<Record<string, number>>((acc, p) => {
|
|
||||||
const s = p.status ?? 'SUBMITTED'
|
|
||||||
acc[s] = (acc[s] || 0) + 1
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
)
|
|
||||||
.sort(([a], [b]) => {
|
.sort(([a], [b]) => {
|
||||||
const order = ['SUBMITTED', 'ELIGIBLE', 'ASSIGNED', 'SEMIFINALIST', 'FINALIST', 'WINNER', 'REJECTED', 'WITHDRAWN']
|
const order = ['SUBMITTED', 'ELIGIBLE', 'ASSIGNED', 'SEMIFINALIST', 'FINALIST', 'WINNER', 'REJECTED', 'WITHDRAWN']
|
||||||
return order.indexOf(a) - order.indexOf(b)
|
return order.indexOf(a) - order.indexOf(b)
|
||||||
|
|||||||
@@ -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({
|
ctx.prisma.project.findMany({
|
||||||
where,
|
where,
|
||||||
skip,
|
skip,
|
||||||
@@ -152,14 +152,26 @@ export const projectRouter = router({
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
ctx.prisma.project.count({ where }),
|
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 {
|
return {
|
||||||
projects,
|
projects,
|
||||||
total,
|
total,
|
||||||
page,
|
page,
|
||||||
perPage,
|
perPage,
|
||||||
totalPages: Math.ceil(total / perPage),
|
totalPages: Math.ceil(total / perPage),
|
||||||
|
statusCounts,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user