'use client'; import type { BeadIssue } from '../../lib/types'; /** Props for an individual task card in the grid. */ /** Details for a blocker task shown on the card. */ export interface BlockerDetail { id: string; title: string; status: BeadIssue['status']; priority: BeadIssue['priority']; epicTitle?: string; } /** Props for an individual task card in the grid. */ interface TaskCardProps { /** The issue data for this card. */ issue: BeadIssue; /** Whether this card is the currently selected task. */ selected: boolean; /** Number of issues blocking this task. */ blockedBy: number; /** Number of issues this task blocks. */ blocks: number; /** List of issues blocking this task. */ blockers: BlockerDetail[]; /** List of issues this task blocks. */ blocking: BlockerDetail[]; /** Whether this task is actionable (unblocked). */ isActionable: boolean; /** Callback fired when the user clicks this card (or a blocker). */ onSelect: (id: string, shouldOpenDrawer?: boolean) => void; } /** Props for the TaskCardGrid component. */ interface TaskCardGridProps { /** List of tasks to display in the grid. */ tasks: BeadIssue[]; /** ID of the currently selected task, or null. */ selectedId: string | null; /** Map of issue ID to blocker/blocks counts. */ signalById: Map; /** Map of issue ID to detailed blocker info. */ blockerDetailsMap: Map; /** Map of issue ID to detailed downstream blocking info. */ blocksDetailsMap: Map; /** Set of actionable (unblocked) task IDs. */ actionableIds: Set; /** Callback fired when the user selects a task. */ onSelect: (id: string, shouldOpenDrawer?: boolean) => void; } /** * Returns the Tailwind background color class for a status dot indicator. * Mirrors the statusDot function from the original monolith. */ function statusDot(status: BeadIssue['status']): string { switch (status) { case 'open': return 'bg-sky-400'; case 'in_progress': return 'bg-amber-400'; case 'blocked': return 'bg-rose-500'; case 'deferred': return 'bg-slate-400'; case 'closed': return 'bg-emerald-400'; case 'pinned': return 'bg-violet-400'; case 'hooked': return 'bg-orange-400'; default: return 'bg-zinc-500'; } } /** * Returns a human-friendly label and text color class for a status. */ function statusBadge(status: BeadIssue['status'], isActionable: boolean, hasBlockers: boolean): { label: string; textColor: string; bgColor: string } { // If effectively blocked (has open blockers), show Blocked (unless closed/done) if (hasBlockers && status !== 'closed' && status !== 'in_progress') { return { label: 'Blocked', textColor: 'text-rose-400', bgColor: 'bg-rose-400/10' }; } // Special case: "Blocked Now Open" -> Ready if (status === 'blocked' && isActionable) { return { label: 'Ready', textColor: 'text-cyan-400', bgColor: 'bg-cyan-400/10' }; } switch (status) { case 'in_progress': return { label: 'In Progress', textColor: 'text-amber-400', bgColor: 'bg-amber-400/10' }; case 'blocked': return { label: 'Blocked', textColor: 'text-rose-400', bgColor: 'bg-rose-400/10' }; case 'closed': return { label: 'Done', textColor: 'text-emerald-400', bgColor: 'bg-emerald-400/10' }; case 'deferred': return { label: 'Deferred', textColor: 'text-slate-400', bgColor: 'bg-slate-400/10' }; case 'open': // Open with no blockers -> Ready return { label: 'Ready', textColor: 'text-cyan-400', bgColor: 'bg-cyan-400/10' }; default: return { label: status, textColor: 'text-zinc-400', bgColor: 'bg-zinc-400/10' }; } } /** * Returns a card-level border class based on status for visual distinction. */ function statusBorder(status: BeadIssue['status'], isActionable: boolean, hasBlockers: boolean): string { if (hasBlockers && status !== 'closed' && status !== 'in_progress') { return 'border-l-2 border-l-rose-500/60'; } if (status === 'blocked' && isActionable) { return 'border-l-2 border-l-cyan-400/60'; } if (status === 'open') { return 'border-l-2 border-l-cyan-400/60'; } switch (status) { case 'in_progress': return 'border-l-2 border-l-amber-400/60'; case 'blocked': return 'border-l-2 border-l-rose-500/60'; case 'closed': return 'border-l-2 border-l-emerald-400/40 opacity-60'; default: return ''; } } /** * A single task card displaying the issue ID, title, priority, type, assignee, * and detailed blocker list (interactive). */ function TaskCard({ issue, selected, blockedBy, blocks, blockers, blocking, isActionable, onSelect }: TaskCardProps) { const hasBlockers = blockers.length > 0; // Note: blockers list only contains OPEN blockers (computed in page) const badge = statusBadge(issue.status, isActionable, hasBlockers); const projectName = (issue as BeadIssue & { project?: { name?: string } }).project?.name ?? null; return (
onSelect(issue.id, false)} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onSelect(issue.id, false); } }} className={`workflow-card group relative flex w-full flex-col rounded-xl px-4 py-4 text-left transition duration-200 ${statusBorder( issue.status, isActionable, hasBlockers, )} ${selected ? 'workflow-card-selected' : 'hover:border-sky-300/40 hover:bg-[linear-gradient(165deg,rgba(76,94,134,0.2),rgba(18,20,30,0.84))]' }`} > {/* Expand / Open Drawer Button */}
{issue.id} {/* Status Badge */} {badge.label}
{projectName ? (
project: {projectName}
) : null}

{issue.title}

{/* Labels */} {issue.labels?.length > 0 ? (
{issue.labels.map((label) => ( {label} ))}
) : null} {/* "Waiting On" section for blockers */} {blockers.length > 0 ? (

Waiting On

{blockers.map((blocker) => (
{ e.stopPropagation(); onSelect(blocker.id, false); }} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.stopPropagation(); onSelect(blocker.id, false); } }} className="group relative flex flex-col gap-0.5 rounded border border-white/5 bg-white/5 px-2.5 py-2 hover:border-sky-400/30 hover:bg-white/10 transition-colors" > {/* Expand Button */}
{blocker.id} {blocker.title}
{blocker.epicTitle ? (
↳ {blocker.epicTitle}
) : null}
))}
) : null} {/* "Blocking" section (downstream) */} {blocking.length > 0 ? (
0 ? 'mt-2' : 'mt-auto'} w-full`}>

Blocking

{blocking.map((item) => (
{ e.stopPropagation(); onSelect(item.id, false); }} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.stopPropagation(); onSelect(item.id, false); } }} className="group relative flex flex-col gap-0.5 rounded border border-white/5 bg-white/5 px-2.5 py-2 hover:border-sky-400/30 hover:bg-white/10 transition-colors" > {/* Expand Button */}
{item.id} {item.title}
{item.epicTitle ? (
↳ {item.epicTitle}
) : null}
))}
) : null} {/* Footer Metadata: Assignee, Due Date */}
{/* Assignee */}
{issue.assignee ?? 'Unassigned'}
{/* Due Date (if exists) */} {issue.due_at ? (
{new Date(issue.due_at as string).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })}
) : null}
); } /** * Renders a responsive grid of task cards. * Uses auto-fill with minmax to prevent cards from being too narrow to read. */ export function TaskCardGrid({ tasks, selectedId, signalById, blockerDetailsMap, blocksDetailsMap, actionableIds, onSelect }: TaskCardGridProps) { // Show an empty state when no tasks exist in the selected epic if (tasks.length === 0) { return (

No tasks in this epic

); } return (
{tasks.map((task) => ( ))}
); }