시나리오 에디터 수정
This commit is contained in:
@@ -169,7 +169,7 @@ const nodeTypes = {
|
|||||||
delayNode: DelayNode
|
delayNode: DelayNode
|
||||||
};
|
};
|
||||||
|
|
||||||
const DiagramArea = forwardRef(({onSave}, ref) => {
|
const DiagramArea = forwardRef(({onSave, onFlowChange, isExecuting}, ref) => {
|
||||||
const {currentFlowData} = useLoadTest();
|
const {currentFlowData} = useLoadTest();
|
||||||
const reactFlowWrapper = useRef(null);
|
const reactFlowWrapper = useRef(null);
|
||||||
const [selectedNodeId, setSelectedNodeId] = useState(null);
|
const [selectedNodeId, setSelectedNodeId] = useState(null);
|
||||||
@@ -196,6 +196,10 @@ const DiagramArea = forwardRef(({onSave}, ref) => {
|
|||||||
}
|
}
|
||||||
}, [currentFlowData, setNodes, setEdges]);
|
}, [currentFlowData, setNodes, setEdges]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onFlowChange?.(nodes, edges);
|
||||||
|
}, [nodes, edges, onFlowChange]);
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
getFlowData: () => ({
|
getFlowData: () => ({
|
||||||
nodes,
|
nodes,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import React, {useCallback, useEffect, useRef, useState} from 'react';
|
import React, {useCallback, useEffect, useRef, useState} from 'react';
|
||||||
|
|
||||||
import '@xyflow/react/dist/style.css';
|
import '@xyflow/react/dist/style.css';
|
||||||
import MonacoEditor from '@/components/shared/MonacoEditor';
|
import MonacoEditor from '@/components/shared/MonacoEditor';
|
||||||
import ScenarioMenuBar from '@/components/api-tester/ScenarioMenuBar.jsx';
|
import ScenarioMenuBar from '@/components/api-tester/ScenarioMenuBar.jsx';
|
||||||
@@ -11,7 +10,6 @@ import {Button} from '@/components/ui/button.jsx';
|
|||||||
|
|
||||||
const apiClient = new APIClient();
|
const apiClient = new APIClient();
|
||||||
|
|
||||||
// ConsoleArea Component
|
|
||||||
const ConsoleArea = ({value, isVisible}) => (
|
const ConsoleArea = ({value, isVisible}) => (
|
||||||
<div className={`${isVisible ? 'h-full' : 'hidden'}`}>
|
<div className={`${isVisible ? 'h-full' : 'hidden'}`}>
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
@@ -24,10 +22,10 @@ const ConsoleArea = ({value, isVisible}) => (
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
// Main ScenarioEditor Component
|
|
||||||
const ScenarioEditor = () => {
|
const ScenarioEditor = () => {
|
||||||
const diagramRef = useRef(null);
|
const diagramRef = useRef(null);
|
||||||
const {currentScenario, currentFlowData, updateScenario} = useLoadTest();
|
const {currentScenario, currentFlowData, updateScenario} = useLoadTest();
|
||||||
|
const [flowData, setFlowData] = useState(currentFlowData);
|
||||||
const [isExecuting, setIsExecuting] = useState(false);
|
const [isExecuting, setIsExecuting] = useState(false);
|
||||||
const [isConsoleVisible, setIsConsoleVisible] = useState(true);
|
const [isConsoleVisible, setIsConsoleVisible] = useState(true);
|
||||||
|
|
||||||
@@ -40,24 +38,33 @@ const ScenarioEditor = () => {
|
|||||||
pauseExecution,
|
pauseExecution,
|
||||||
isRunning
|
isRunning
|
||||||
} = useScenarioExecutor(
|
} = useScenarioExecutor(
|
||||||
currentFlowData?.nodes || [],
|
flowData?.nodes || [],
|
||||||
currentFlowData?.edges || [],
|
flowData?.edges || [],
|
||||||
apiClient
|
apiClient
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
setFlowData(currentFlowData);
|
||||||
resetExecutor();
|
resetExecutor();
|
||||||
clearLogs();
|
clearLogs();
|
||||||
}, [currentFlowData]);
|
}, [currentFlowData]);
|
||||||
|
|
||||||
|
|
||||||
|
const handleFlowChange = useCallback((nodes, edges) => {
|
||||||
|
setFlowData({ nodes, edges });
|
||||||
|
resetExecutor();
|
||||||
|
}, [resetExecutor]);
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
try {
|
try {
|
||||||
console.log(currentScenario);
|
|
||||||
const flowData = diagramRef.current?.getFlowData();
|
const flowData = diagramRef.current?.getFlowData();
|
||||||
|
if (flowData) {
|
||||||
|
resetExecutor();
|
||||||
await updateScenario({
|
await updateScenario({
|
||||||
...currentScenario,
|
...currentScenario,
|
||||||
scenario: JSON.stringify(flowData)
|
scenario: JSON.stringify(flowData)
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save scenario:', error);
|
console.error('Failed to save scenario:', error);
|
||||||
}
|
}
|
||||||
@@ -116,6 +123,7 @@ const ScenarioEditor = () => {
|
|||||||
initialNodes={currentFlowData?.nodes || []}
|
initialNodes={currentFlowData?.nodes || []}
|
||||||
initialEdges={currentFlowData?.edges || []}
|
initialEdges={currentFlowData?.edges || []}
|
||||||
isExecuting={isExecuting}
|
isExecuting={isExecuting}
|
||||||
|
onFlowChange={handleFlowChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={isConsoleVisible ? 'h-1/2' : 'h-auto'}>
|
<div className={isConsoleVisible ? 'h-1/2' : 'h-auto'}>
|
||||||
|
|||||||
Reference in New Issue
Block a user