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>
This commit is contained in:
parent
334bb95678
commit
e2226f440c
2 changed files with 87 additions and 0 deletions
48
app/(app)/insights/components/sprint-status-donut.tsx
Normal file
48
app/(app)/insights/components/sprint-status-donut.tsx
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
'use client'
|
||||
|
||||
import { PieChart, Pie, Cell, Tooltip, Legend, ResponsiveContainer } from 'recharts'
|
||||
import type { StatusCount } from '@/lib/insights/sprint-status'
|
||||
|
||||
interface Props {
|
||||
data: StatusCount[]
|
||||
}
|
||||
|
||||
const STATUS_COLORS: Record<string, string> = {
|
||||
TO_DO: 'var(--status-todo)',
|
||||
IN_PROGRESS: 'var(--status-in-progress)',
|
||||
DONE: 'var(--status-done)',
|
||||
}
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
TO_DO: 'To do',
|
||||
IN_PROGRESS: 'In progress',
|
||||
DONE: 'Done',
|
||||
}
|
||||
|
||||
export function SprintStatusDonut({ data }: Props) {
|
||||
if (data.length === 0) {
|
||||
return <p className="text-muted-foreground text-sm">Geen actieve sprint-taken</p>
|
||||
}
|
||||
|
||||
const labeled = data.map(d => ({ ...d, name: STATUS_LABELS[d.status] ?? d.status }))
|
||||
|
||||
return (
|
||||
<ResponsiveContainer width="100%" height={240}>
|
||||
<PieChart>
|
||||
<Pie
|
||||
data={labeled}
|
||||
dataKey="count"
|
||||
nameKey="name"
|
||||
innerRadius={50}
|
||||
outerRadius={80}
|
||||
>
|
||||
{labeled.map(entry => (
|
||||
<Cell key={entry.status} fill={STATUS_COLORS[entry.status]} />
|
||||
))}
|
||||
</Pie>
|
||||
<Tooltip />
|
||||
<Legend />
|
||||
</PieChart>
|
||||
</ResponsiveContainer>
|
||||
)
|
||||
}
|
||||
39
lib/insights/sprint-status.ts
Normal file
39
lib/insights/sprint-status.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
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 }))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue