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,19 +179,22 @@ export default function ParameterComponent({
} }
renderTooltips(); renderTooltips();
let flow = flows.find((flow) => flow.id === tabId); let flow = flows.find((flow) => flow.id === tabId);
if (reactFlowInstance && flow && flow.data) { setTimeout(() => {
cleanEdges({ //timeout necessary because ReactFlow updates are not async
flow: { if (reactFlowInstance && flow && flow.data) {
edges: flow.data!.edges, cleanEdges({
nodes: flow.data!.nodes, flow: {
}, edges: flow.data!.edges,
updateEdge: (edge) => { nodes: flow.data!.nodes,
reactFlowInstance.setEdges(edge); },
updateNodeInternals(data.id); updateEdge: (edge) => {
}, reactFlowInstance.setEdges(edge);
}); updateNodeInternals(data.id);
updateFlow(flow); },
} });
updateFlow(flow);
}
}, 50);
}; };
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);

View file

@ -41,37 +41,35 @@ 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 = scapeJSONParse(targetHandle);
const targetHandleObject: targetHandleType = const field = targetHandleObject.fieldName;
scapeJSONParse(targetHandle); const id: targetHandleType = {
const field = targetHandleObject.fieldName; type: targetNode.data.node!.template[field]?.type,
const id: targetHandleType = { fieldName: field,
type: targetNode.data.node!.template[field]?.type, id: targetNode.data.id,
fieldName: field, inputTypes: targetNode.data.node!.template[field]?.input_types,
id: targetNode.data.id, };
inputTypes: targetNode.data.node!.template[field]?.input_types, if (targetNode.data.node!.template[field]?.proxy) {
}; id.proxy = targetNode.data.node!.template[field]?.proxy;
if (targetNode.data.node!.template[field]?.proxy) {
id.proxy = targetNode.data.node!.template[field]?.proxy;
}
if (scapedJSONStringfy(id) !== targetHandle) {
newEdges = newEdges.filter((e) => e.id !== edge.id);
}
} }
if (sourceHandle) { if (scapedJSONStringfy(id) !== targetHandle) {
const id: sourceHandleType = { newEdges = newEdges.filter((e) => e.id !== edge.id);
id: sourceNode.data.id, }
baseClasses: sourceNode.data.node!.base_classes, }
dataType: sourceNode.data.type, if (sourceHandle) {
}; const id: sourceHandleType = {
if (scapedJSONStringfy(id) !== sourceHandle) { id: sourceNode.data.id,
newEdges = newEdges.filter((e) => e.id !== edge.id); baseClasses: sourceNode.data.node!.base_classes,
} dataType: sourceNode.data.type,
};
if (scapedJSONStringfy(id) !== sourceHandle) {
newEdges = newEdges.filter((e) => e.id !== edge.id);
} }
} }
}); });