Scrum4Me/components/jobs/job-card.tsx
Janpeter Visser a268df3680
feat(PBI-59): Sprint.code (SP-N sequentieel per product) (#153)
Voegt een verplicht code-veld toe aan Sprint, sequentieel per product
(consistent met PBI-N, ST-NNN, T-N).

- **Schema** — `Sprint.code String @db.VarChar(30)` + `@@unique([product_id, code])`
- **Migratie** — voegt kolom toe als nullable, backfillt bestaande sprints
  via `ROW_NUMBER() OVER (PARTITION BY product_id ORDER BY created_at)`
  als `SP-N`, en zet daarna NOT NULL + UNIQUE.
- **Generator** — `generateNextSprintCode(productId)` in lib/code-server.ts
  volgt het patroon van story/pbi/task; createSprintAction gebruikt
  `createWithCodeRetry` voor race-bescherming.
- **Seed** — sprint-counter per product (`SP-1`, `SP-2`, ...).

Zichtbaar in:
- Sprint-header (`Product › Sprint actief · SP-3`)
- JobCard + JobDetailPane voor SPRINT_IMPLEMENTATION jobs
- Insights: VelocityChart x-axis (compacter dan goal-truncated),
  AlignmentTrend tooltip, SprintInfoStrip
- actions/jobs-page.ts: `sprintCode` is weer een echte code i.p.v. null

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 20:10:16 +02:00

76 lines
2.5 KiB
TypeScript

'use client'
import { cn } from '@/lib/utils'
import { JOB_STATUS_LABELS, JOB_STATUS_COLORS } from '@/components/shared/job-status'
import { jobStatusToApi } from '@/lib/job-status'
import type { ClaudeJobKind, ClaudeJobStatus } from '@prisma/client'
interface JobCardProps {
id: string
kind: ClaudeJobKind
status: ClaudeJobStatus
taskCode?: string | null
taskTitle?: string | null
ideaCode?: string | null
ideaTitle?: string | null
sprintGoal?: string | null
sprintCode?: string | null
productName: string
branch?: string | null
error?: string | null
summary?: string | null
isSelected?: boolean
onClick?: () => void
}
const KIND_LABELS: Record<ClaudeJobKind, string> = {
TASK_IMPLEMENTATION: 'TAAK',
SPRINT_IMPLEMENTATION: 'SPRINT',
IDEA_GRILL: 'GRILL',
IDEA_MAKE_PLAN: 'PLAN',
PLAN_CHAT: 'CHAT',
}
export default function JobCard({
kind, status, taskCode, taskTitle, ideaCode, ideaTitle,
sprintGoal, sprintCode, productName, branch, error, isSelected, onClick,
}: JobCardProps) {
let titleText: string
if (kind === 'TASK_IMPLEMENTATION') {
titleText = taskCode && taskTitle ? `${taskCode} ${taskTitle}` : taskTitle || 'Taak'
} else if (kind === 'SPRINT_IMPLEMENTATION') {
if (sprintCode && sprintGoal) titleText = `${sprintCode} ${sprintGoal}`
else titleText = sprintGoal || sprintCode || 'Sprint'
} else if (kind === 'IDEA_GRILL' || kind === 'IDEA_MAKE_PLAN') {
titleText = ideaCode && ideaTitle ? `${ideaCode} ${ideaTitle}` : ideaTitle || 'Idee'
} else if (kind === 'PLAN_CHAT') {
titleText = ideaCode ? `Chat ${ideaCode}` : 'Chat'
} else {
titleText = 'Job'
}
const detailText = branch || (error ? error.slice(0, 80) : null) || productName
const apiStatus = jobStatusToApi(status)
return (
<div
onClick={onClick}
className={cn(
'border rounded-lg p-3 cursor-pointer hover:bg-surface-container transition-colors text-sm',
isSelected && 'ring-2 ring-primary',
)}
>
<div className="flex justify-between items-center gap-2">
<span className="text-[10px] px-1.5 py-0.5 rounded border bg-muted text-muted-foreground font-mono">
{KIND_LABELS[kind]}
</span>
<span className={cn('text-xs px-2 py-0.5 rounded-full border font-medium', JOB_STATUS_COLORS[apiStatus])}>
{JOB_STATUS_LABELS[apiStatus]}
</span>
</div>
<p className="font-medium truncate mt-1">{titleText}</p>
<p className="text-xs text-muted-foreground truncate mt-0.5">{detailText}</p>
</div>
)
}