()
| 4 | import Prism from 'prismjs'; |
| 5 | |
| 6 | const CodeViewer: React.FC = () => { |
| 7 | const { currentPipeline } = usePipelineStore(); |
| 8 | const [isExecuting, setIsExecuting] = useState(false); |
| 9 | const [executionResult, setExecutionResult] = useState<any>(null); |
| 10 | |
| 11 | useEffect(() => { |
| 12 | // Highlight code when it changes |
| 13 | Prism.highlightAll(); |
| 14 | }, [currentPipeline?.code]); |
| 15 | |
| 16 | const handleCopyCode = () => { |
| 17 | if (currentPipeline?.code) { |
| 18 | navigator.clipboard.writeText(currentPipeline.code); |
| 19 | // You could add a toast notification here |
| 20 | } |
| 21 | }; |
| 22 | |
| 23 | const handleDownloadCode = () => { |
| 24 | if (currentPipeline?.code) { |
| 25 | const blob = new Blob([currentPipeline.code], { type: 'text/plain' }); |
| 26 | const url = window.URL.createObjectURL(blob); |
| 27 | const a = document.createElement('a'); |
| 28 | a.href = url; |
| 29 | a.download = `${currentPipeline.name.replace(/\s+/g, '_')}_scraper.py`; |
| 30 | document.body.appendChild(a); |
| 31 | a.click(); |
| 32 | document.body.removeChild(a); |
| 33 | window.URL.revokeObjectURL(url); |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | const handleExecuteCode = async () => { |
| 38 | if (!currentPipeline?.code || !currentPipeline?.urls || !currentPipeline?.schema) { |
| 39 | alert('Please ensure you have URLs and a schema defined before executing.'); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | // Check for API key |
| 44 | const apiKey = localStorage.getItem('SCRAPEGRAPH_API_KEY'); |
| 45 | if (!apiKey) { |
| 46 | alert('Please configure your ScrapeGraphAI API key in Settings before executing.'); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | setIsExecuting(true); |
| 51 | setExecutionResult(null); |
| 52 | |
| 53 | try { |
| 54 | // Use the pipeline store's runPipeline function |
| 55 | await usePipelineStore.getState().runPipeline(currentPipeline.id); |
| 56 | |
| 57 | // Get the updated pipeline with results |
| 58 | const updatedPipeline = usePipelineStore.getState().currentPipeline; |
| 59 | |
| 60 | if (updatedPipeline?.status === 'completed') { |
| 61 | setExecutionResult({ |
| 62 | success: true, |
| 63 | results: updatedPipeline.results |
nothing calls this directly
no outgoing calls
no test coverage detected