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

View file

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