Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | /** * Workflow Toolbar Component * * Toolbar with actions for the workflow builder. */ import { useState } from 'react'; import type { ValidationResult } from '../../lib/workflow-builder/types'; import { canvasToYaml } from '../../lib/workflow-builder/yaml-converter'; import { useWorkflowBuilderStore } from '../../store/workflowBuilderStore'; interface WorkflowToolbarProps { workflowName: string; isDirty: boolean; validation: ValidationResult | null; onSave: () => void; onValidate: () => ValidationResult; } export function WorkflowToolbar({ workflowName, isDirty, validation, onSave, onValidate, }: WorkflowToolbarProps) { const [isPreviewOpen, setIsPreviewOpen] = useState(false); const [yamlPreview, setYamlPreview] = useState(''); const canvas = useWorkflowBuilderStore(state => state.canvas); const handlePreviewYaml = () => { if (canvas) { const yaml = canvasToYaml(canvas); setYamlPreview(yaml); setIsPreviewOpen(true); } }; const handleCopyYaml = async () => { try { await navigator.clipboard.writeText(yamlPreview); alert('YAML copied to clipboard!'); } catch (err) { console.error('Failed to copy:', err); } }; const handleDownloadYaml = () => { const blob = new Blob([yamlPreview], { type: 'text/yaml' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `${workflowName.replace(/\s+/g, '-').toLowerCase()}.yaml`; a.click(); URL.revokeObjectURL(url); }; return ( <> <div className="flex items-center justify-between px-4 py-2 bg-white border-b border-gray-200"> {/* Left: Workflow Name */} <div className="flex items-center gap-3"> <h1 className="font-semibold text-gray-800">{workflowName}</h1> {isDirty && ( <span className="text-sm text-amber-600 flex items-center gap-1"> <span className="w-2 h-2 bg-amber-400 rounded-full animate-pulse" /> Unsaved </span> )} </div> {/* Center: Validation Status */} {validation && ( <div className="flex items-center gap-2"> {validation.valid ? ( <span className="text-sm text-green-600 flex items-center gap-1"> ✓ Valid </span> ) : ( <span className="text-sm text-red-600 flex items-center gap-1"> ✕ {validation.errors.length} error(s) </span> )} {validation.warnings.length > 0 && ( <span className="text-sm text-amber-600"> {validation.warnings.length} warning(s) </span> )} </div> )} {/* Right: Actions */} <div className="flex items-center gap-2"> <button onClick={onValidate} className="px-3 py-1.5 text-sm text-gray-600 hover:text-gray-800 hover:bg-gray-100 rounded-lg" > Validate </button> <button onClick={handlePreviewYaml} className="px-3 py-1.5 text-sm text-gray-600 hover:text-gray-800 hover:bg-gray-100 rounded-lg" > Preview YAML </button> <button onClick={onSave} disabled={!isDirty} className={` px-4 py-1.5 text-sm rounded-lg font-medium ${isDirty ? 'bg-blue-500 text-white hover:bg-blue-600' : 'bg-gray-100 text-gray-400 cursor-not-allowed' } `} > Save </button> </div> </div> {/* YAML Preview Modal */} {isPreviewOpen && ( <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50"> <div className="bg-white rounded-xl shadow-xl w-[800px] max-h-[80vh] overflow-hidden"> {/* Modal Header */} <div className="flex items-center justify-between px-4 py-3 border-b border-gray-200"> <h2 className="font-semibold text-gray-800">Pipeline YAML</h2> <div className="flex items-center gap-2"> <button onClick={handleCopyYaml} className="px-3 py-1.5 text-sm text-gray-600 hover:bg-gray-100 rounded-lg" > Copy </button> <button onClick={handleDownloadYaml} className="px-3 py-1.5 text-sm text-gray-600 hover:bg-gray-100 rounded-lg" > Download </button> <button onClick={() => setIsPreviewOpen(false)} className="px-3 py-1.5 text-sm text-gray-400 hover:text-gray-600" > ✕ </button> </div> </div> {/* YAML Content */} <div className="p-4 overflow-y-auto max-h-[60vh]"> <pre className="text-sm font-mono text-gray-800 whitespace-pre-wrap"> {yamlPreview} </pre> </div> </div> </div> )} </> ); } export default WorkflowToolbar; |