* chore: voeg recharts toe aan dependencies Vereist door SprintStatusDonut component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: SprintStatusDonut + getSprintStatusBreakdown helper PieChart (donut) met TO_DO/IN_PROGRESS/DONE verdeling over alle active sprints. REVIEW wordt samengevoegd in IN_PROGRESS. MD3 status-kleuren via CSS-variabelen. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { prisma } from '@/lib/prisma'
|
|
import { productAccessFilter } from '@/lib/product-access'
|
|
|
|
export type SprintStatusGroup = 'TO_DO' | 'IN_PROGRESS' | 'DONE'
|
|
|
|
export interface StatusCount {
|
|
status: SprintStatusGroup
|
|
count: number
|
|
}
|
|
|
|
// Maps REVIEW → IN_PROGRESS so donut shows 3 buckets only
|
|
function toGroup(status: string): SprintStatusGroup {
|
|
if (status === 'DONE') return 'DONE'
|
|
if (status === 'TO_DO') return 'TO_DO'
|
|
return 'IN_PROGRESS'
|
|
}
|
|
|
|
export async function getSprintStatusBreakdown(userId: string): Promise<StatusCount[]> {
|
|
const tasks = await prisma.task.findMany({
|
|
where: {
|
|
story: {
|
|
sprint: {
|
|
status: 'ACTIVE',
|
|
product: productAccessFilter(userId),
|
|
},
|
|
},
|
|
},
|
|
select: { status: true },
|
|
})
|
|
|
|
const counts: Record<SprintStatusGroup, number> = { TO_DO: 0, IN_PROGRESS: 0, DONE: 0 }
|
|
for (const t of tasks) {
|
|
counts[toGroup(t.status)]++
|
|
}
|
|
|
|
return (Object.entries(counts) as [SprintStatusGroup, number][])
|
|
.filter(([, count]) => count > 0)
|
|
.map(([status, count]) => ({ status, count }))
|
|
}
|