"use client"; import { Fragment, memo, useMemo, useState } from "react"; import { IconCheck, IconChevronDown, IconLogicBuffer } from "@tabler/icons-react"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@kandev/ui/tooltip"; import { Popover, PopoverContent, PopoverTrigger } from "@kandev/ui/popover"; import { Button } from "@kandev/ui/button"; import type { WorkflowSnapshotData } from "@/lib/state/slices/kanban/types"; import type { AgentProfileOption } from "@/lib/state/slices"; import { AgentLogo } from "@/components/agent-logo"; type StepItem = { id: string; title: string; color: string; position: number; agent_profile_id?: string; is_start_step?: boolean; }; function InlineSteps({ steps, agentProfiles, }: { steps: StepItem[]; agentProfiles: AgentProfileOption[]; }) { if (steps.length === 0) return null; return (
{steps.map((s, i) => { const stepProfile = s.agent_profile_id ? agentProfiles.find((p) => p.id === s.agent_profile_id) : null; return ( {i > 0 && {"\u2192"}} {s.title} {s.is_start_step && ( * Start step )} {stepProfile && ( {stepProfile.label} )} ); })}
); } type WorkflowSelectorRowProps = { workflows: Array<{ id: string; name: string; description?: string | null; agent_profile_id?: string; }>; snapshots: Record; selectedWorkflowId: string | null; onWorkflowChange: (workflowId: string) => void; lastUsedWorkflowId?: string | null; agentProfiles: AgentProfileOption[]; }; export const WorkflowSelectorRow = memo(function WorkflowSelectorRow({ workflows, snapshots, selectedWorkflowId, onWorkflowChange, lastUsedWorkflowId, agentProfiles, }: WorkflowSelectorRowProps) { const [open, setOpen] = useState(false); const selectedWorkflow = useMemo( () => workflows.find((w) => w.id === selectedWorkflowId), [workflows, selectedWorkflowId], ); // Sort workflows: last-used first, then original order (which is already by sort_order) const sortedWorkflows = useMemo(() => { if (!lastUsedWorkflowId) return workflows; return [...workflows].sort((a, b) => { if (a.id === lastUsedWorkflowId) return -1; if (b.id === lastUsedWorkflowId) return 1; return 0; }); }, [workflows, lastUsedWorkflowId]); return (
Workflow
{sortedWorkflows.map((wf) => { const isSelected = wf.id === selectedWorkflowId; const snapshot = snapshots[wf.id]; const steps = snapshot ? [...snapshot.steps].sort((a, b) => a.position - b.position) : []; return ( ); })}
); });