import { useMemo, useState } from "react" import { AnimatePresence, motion } from "framer-motion" import { ArrowsClockwise, CaretRight, Gear, Lightning, Play, Trash, X } from "@phosphor-icons/react" import type { WorkflowPipelineRecord, WorkflowStep } from "@shared/types" import { timeAgo } from "../../lib/formatters" import { ActionButton } from "../ui" import { ACCENT, LINE, triggerConfig, actionConfig, workflowStatusColors, stepStatusConfig, safeJsonParse } from "./automation-config" function StepTimeline({ steps }: { steps: WorkflowStep[] }) { if (steps.length === 0) return
No steps defined
return (
{steps.map((step, idx) => { const colors = stepStatusConfig[step.status]; const info = actionConfig[step.action] return (
{idx + 1}{step.name}
{step.status}
{info?.label ?? step.action}{step.assigneeDepartment ? <>{step.assigneeDepartment} : null}{step.requiresApproval ? <>Requires approval : null}{step.timeoutSec > 0 ? <>{step.timeoutSec}s timeout : null}
) })}
) } function WorkflowCard({ workflow, isRunning, onDelete, onEdit, onRun }: { workflow: WorkflowPipelineRecord; isRunning: boolean; onDelete: () => void; onEdit: () => void; onRun: () => void }) { const [expanded, setExpanded] = useState(false); const colors = workflowStatusColors[workflow.status] const triggerInfo = triggerConfig[workflow.triggerType]; const TriggerIcon = triggerInfo?.icon ?? Lightning const steps: WorkflowStep[] = useMemo(() => { const parsed = safeJsonParse(workflow.stepsJson); return Array.isArray(parsed) ? (parsed as WorkflowStep[]) : [] }, [workflow.stepsJson]) return (
{expanded ?
{workflow.description ?

{workflow.description}

: null}
: null}
) } export { WorkflowCard, StepTimeline }