'use client'; import { useMemo } from 'react'; import { Hash, User, StickyNote, Boxes } from 'lucide-react'; import { cn } from '../../lib/utils'; import { Badge } from '../ui/badge'; /** * Minimal, in-package shape of a workflow version. Mirrors the subset of the * backend version record the history view actually reads — kept local so the * component carries no app type coupling. */ export interface WorkflowVersion { uuid: string; versionNumber: number; timestamp: string; isPublished?: boolean; versionNote?: string | null; createdBy?: { firstName?: string | null; lastName?: string | null; email: string; } | null; /** Opaque workflow definition; only `nodes.length` is read for display. */ workflowData?: Record | null; } export interface WorkflowVersionHistoryProps { versions: WorkflowVersion[]; /** * Formats a version's ISO timestamp for display. Supplied by the consumer * so this component stays free of date/locale dependencies. Defaults to the * raw timestamp string when omitted. */ formatTimestamp?: (timestamp: string) => string; className?: string; } export function WorkflowVersionHistory({ versions, formatTimestamp, className, }: WorkflowVersionHistoryProps) { const sorted = useMemo( () => [...versions].sort((a, b) => b.versionNumber - a.versionNumber), [versions] ); if (versions.length === 0) { return (

No Versions Yet

No versions published yet. Use the canvas toolbar to publish a version.

); } const formatTime = formatTimestamp ?? ((t: string) => t); return (
    {sorted.map((version, index) => { const label = version.versionNote ? `v${version.versionNumber} — ${version.versionNote}` : `v${version.versionNumber}`; const nodeCount = version.workflowData && Array.isArray( (version.workflowData as Record).nodes ) ? ( (version.workflowData as Record) .nodes as unknown[] ).length : null; const isLast = index === sorted.length - 1; return (
  1. {/* Timeline rail + dot */} {!isLast && (
  2. ); })}
); }