"use client"; import { Activity, Bot, CheckCircle, Circle, Clock, GitBranch, Play, Target, Users } from "lucide-react"; import { Badge } from "~/components/ui/badge"; import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card"; import { Progress } from "~/components/ui/progress"; import { Separator } from "~/components/ui/separator"; interface TrialProgressProps { steps: Array<{ id: string; name: string; type: "wizard_action" | "robot_action" | "parallel_steps" | "conditional_branch"; description?: string; duration?: number; parameters?: any; }>; currentStepIndex: number; trialStatus: "scheduled" | "in_progress" | "completed" | "aborted" | "failed"; } const stepTypeConfig = { wizard_action: { label: "Wizard", icon: Play, color: "blue", bgColor: "bg-blue-100", textColor: "text-blue-600", borderColor: "border-blue-300" }, robot_action: { label: "Robot", icon: Bot, color: "green", bgColor: "bg-green-100", textColor: "text-green-600", borderColor: "border-green-300" }, parallel_steps: { label: "Parallel", icon: Users, color: "purple", bgColor: "bg-purple-100", textColor: "text-purple-600", borderColor: "border-purple-300" }, conditional_branch: { label: "Branch", icon: GitBranch, color: "orange", bgColor: "bg-orange-100", textColor: "text-orange-600", borderColor: "border-orange-300" } }; export function TrialProgress({ steps, currentStepIndex, trialStatus }: TrialProgressProps) { if (!steps || steps.length === 0) { return ( No experiment steps defined ); } const progress = trialStatus === "completed" ? 100 : trialStatus === "aborted" ? 0 : ((currentStepIndex + 1) / steps.length) * 100; const completedSteps = trialStatus === "completed" ? steps.length : trialStatus === "aborted" || trialStatus === "failed" ? 0 : currentStepIndex; const getStepStatus = (index: number) => { if (trialStatus === "aborted" || trialStatus === "failed") return "aborted"; if (trialStatus === "completed" || index < currentStepIndex) return "completed"; if (index === currentStepIndex && trialStatus === "in_progress") return "active"; if (index === currentStepIndex && trialStatus === "scheduled") return "pending"; return "upcoming"; }; const getStepStatusConfig = (status: string) => { switch (status) { case "completed": return { icon: CheckCircle, iconColor: "text-green-600", bgColor: "bg-green-100", borderColor: "border-green-300", textColor: "text-green-800" }; case "active": return { icon: Activity, iconColor: "text-blue-600", bgColor: "bg-blue-100", borderColor: "border-blue-300", textColor: "text-blue-800" }; case "pending": return { icon: Clock, iconColor: "text-amber-600", bgColor: "bg-amber-100", borderColor: "border-amber-300", textColor: "text-amber-800" }; case "aborted": return { icon: Circle, iconColor: "text-red-600", bgColor: "bg-red-100", borderColor: "border-red-300", textColor: "text-red-800" }; default: // upcoming return { icon: Circle, iconColor: "text-slate-400", bgColor: "bg-slate-100", borderColor: "border-slate-300", textColor: "text-slate-600" }; } }; const totalDuration = steps.reduce((sum, step) => sum + (step.duration || 0), 0); return ( Trial Progress {completedSteps}/{steps.length} steps {totalDuration > 0 && ( ~{Math.round(totalDuration / 60)}min )} {/* Overall Progress Bar */} Overall Progress {Math.round(progress)}% Start {trialStatus === "completed" ? "Completed" : trialStatus === "aborted" ? "Aborted" : trialStatus === "failed" ? "Failed" : trialStatus === "in_progress" ? "In Progress" : "Not Started"} {/* Steps Timeline */} Experiment Steps {steps.map((step, index) => { const stepConfig = stepTypeConfig[step.type]; const StepIcon = stepConfig.icon; const status = getStepStatus(index); const statusConfig = getStepStatusConfig(status); const StatusIcon = statusConfig.icon; return ( {/* Connection Line */} {index < steps.length - 1 && ( )} {/* Step Card */} {/* Step Number & Status */} {index + 1} {/* Step Content */} {step.name} {step.description && ( {step.description} )} {stepConfig.label} {step.duration && ( {step.duration}s )} {/* Step Status Message */} {status === "active" && trialStatus === "in_progress" && ( Currently executing... )} {status === "active" && trialStatus === "scheduled" && ( Ready to start )} {status === "completed" && ( Completed )} ); })} {/* Summary Stats */} {completedSteps} Completed {trialStatus === "in_progress" ? 1 : 0} Active {steps.length - completedSteps - (trialStatus === "in_progress" ? 1 : 0)} Remaining ); }
No experiment steps defined
{step.description}