import React, { useState } from 'react'; import { toast } from 'react-toastify'; import nodeService from '../../services/nodes'; import Modal from '../common/Modal'; import { PlayIcon, ArrowPathIcon } from '@heroicons/react/24/outline'; const NodeTester = ({ node, onClose }) => { const [inputData, setInputData] = useState('{}'); const [testResults, setTestResults] = useState(null); const [loading, setLoading] = useState(false); const [inputError, setInputError] = useState(null); // Test node configuration with provided input const handleTestNode = async () => { // Validate JSON input try { JSON.parse(inputData); setInputError(null); } catch (error) { setInputError('Invalid JSON format'); return; } try { setLoading(true); const parsedInput = JSON.parse(inputData); const response = await nodeService.testNodeConfig( node.data.nodeType, node.data.config || {}, parsedInput ); setTestResults(response.data); toast.success('Node test completed successfully'); } catch (error) { console.error('Error testing node:', error); toast.error('Failed to test node configuration'); // If we have error details from the API if (error.response?.data?.error) { setTestResults({ success: false, error: error.response.data.error, output: null }); } else { setTestResults({ success: false, error: error.message || 'An unknown error occurred', output: null }); } } finally { setLoading(false); } }; // Format JSON for display const formatJSON = (json) => { try { if (typeof json === 'string') { return JSON.stringify(JSON.parse(json), null, 2); } return JSON.stringify(json, null, 2); } catch (error) { return json; } }; return (
Test this node with sample input data
Enter sample input data in JSON format to test this node
{formatJSON(testResults.output)}