/** * WorkflowStepNode - Custom React Flow node for workflow steps * Displays step status, issue info, and provides interactive selection */ import { memo, useCallback } from 'react' import { Handle, Position, type NodeProps } from '@xyflow/react' import { Clock, Circle, Loader2, CheckCircle2, XCircle, MinusCircle, AlertCircle, ExternalLink, } from 'lucide-react' import { cn } from '@/lib/utils' import type { WorkflowStep } from '@/types/workflow' import type { Issue } from '@/types/api' import { STEP_STATUS_STYLES, STEP_STATUS_LABELS } from '@/types/workflow' // ============================================================================= // Types // ============================================================================= export interface WorkflowStepNodeData { step: WorkflowStep issue?: Issue isSelected?: boolean onSelect?: (stepId: string) => void } // ============================================================================= // Utility Functions // ============================================================================= /** * Calculate duration from timestamps or return elapsed time for running steps */ function getStepDuration(step: WorkflowStep): string | null { // For now, we don't have start/end timestamps on steps // This would need to be added to the WorkflowStep type // Return null to indicate no duration available if (step.status === 'running') { return 'running...' } if (step.status === 'completed' && step.executionId) { return 'done' } return null } // ============================================================================= // Status Icon Component // ============================================================================= interface StatusIconProps { status: WorkflowStep['status'] className?: string } function StatusIcon({ status, className }: StatusIconProps) { const iconClass = cn('h-4 w-4', className) switch (status) { case 'pending': return case 'ready': return case 'running': return case 'completed': return case 'failed': return case 'skipped': return case 'blocked': return default: return } } // ============================================================================= // Status Badge Component // ============================================================================= function StatusBadge({ status }: { status: WorkflowStep['status'] }) { const label = STEP_STATUS_LABELS[status] || status const badgeStyles: Record = { pending: 'bg-muted text-muted-foreground', ready: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300', running: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300', completed: 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-300', failed: 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-300', skipped: 'bg-muted text-muted-foreground', blocked: 'bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-300', } return ( {label} ) } // ============================================================================= // Main Component // ============================================================================= function WorkflowStepNodeComponent({ data }: NodeProps) { // Cast data to our expected type const nodeData = data as unknown as WorkflowStepNodeData const { step, issue, isSelected, onSelect } = nodeData const styles = STEP_STATUS_STYLES[step.status] || STEP_STATUS_STYLES.pending // Direct click handler for reliable selection const handleClick = useCallback(() => { onSelect?.(step.id) }, [onSelect, step.id]) // Get title and truncate if needed const title = issue?.title || `Step ${step.index + 1}` const needsTruncation = title.length > 32 const displayTitle = needsTruncation ? `${title.slice(0, 32)}...` : title // Get duration const duration = getStepDuration(step) return ( <> {/* Input handle (top) */} {/* Node content */}
{/* Header: Status icon + Issue ID + Status badge */}
{step.issueId}
{/* Divider */}
{/* Title */}
{displayTitle}
{/* Footer: Agent + Duration */}
{step.agentType && ( {step.agentType} )}
{duration && ( {duration} )} {step.executionId && ( )}
{/* Error indicator (if failed) */} {step.status === 'failed' && step.error && (
{step.error}
)}
{/* Output handle (bottom) */} ) } export const WorkflowStepNode = memo(WorkflowStepNodeComponent)