added setTimeout to fix state not being updated at Prompt

This commit is contained in:
Lucas Oliveira 2023-12-10 01:47:53 -03:00
commit 3f0b999266
2 changed files with 42 additions and 41 deletions

View file

@ -179,6 +179,8 @@ export default function ParameterComponent({
} }
renderTooltips(); renderTooltips();
let flow = flows.find((flow) => flow.id === tabId); let flow = flows.find((flow) => flow.id === tabId);
setTimeout(() => {
//timeout necessary because ReactFlow updates are not async
if (reactFlowInstance && flow && flow.data) { if (reactFlowInstance && flow && flow.data) {
cleanEdges({ cleanEdges({
flow: { flow: {
@ -192,6 +194,7 @@ export default function ParameterComponent({
}); });
updateFlow(flow); updateFlow(flow);
} }
}, 50);
}; };
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);

View file

@ -41,14 +41,13 @@ export function cleanEdges({
const targetNode = nodes.find((node) => node.id === edge.target); const targetNode = nodes.find((node) => node.id === edge.target);
if (!sourceNode || !targetNode) { if (!sourceNode || !targetNode) {
newEdges = newEdges.filter((edg) => edg.id !== edge.id); newEdges = newEdges.filter((edg) => edg.id !== edge.id);
return;
} }
// check if the source and target handle still exists // check if the source and target handle still exists
if (sourceNode && targetNode) {
const sourceHandle = edge.sourceHandle; //right const sourceHandle = edge.sourceHandle; //right
const targetHandle = edge.targetHandle; //left const targetHandle = edge.targetHandle; //left
if (targetHandle) { if (targetHandle) {
const targetHandleObject: targetHandleType = const targetHandleObject: targetHandleType = scapeJSONParse(targetHandle);
scapeJSONParse(targetHandle);
const field = targetHandleObject.fieldName; const field = targetHandleObject.fieldName;
const id: targetHandleType = { const id: targetHandleType = {
type: targetNode.data.node!.template[field]?.type, type: targetNode.data.node!.template[field]?.type,
@ -73,7 +72,6 @@ export function cleanEdges({
newEdges = newEdges.filter((e) => e.id !== edge.id); newEdges = newEdges.filter((e) => e.id !== edge.id);
} }
} }
}
}); });
updateEdge(newEdges); updateEdge(newEdges);
} }