diff --git a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx index 66bc0d371..ec15b6404 100644 --- a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx +++ b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx @@ -37,7 +37,10 @@ export default function BuildTrigger({ if (isBuilding) { return; } - const errors = validateNodes(reactFlowInstance!); + const errors = validateNodes( + reactFlowInstance!.getNodes(), + reactFlowInstance!.getEdges() + ); if (errors.length > 0) { setErrorData({ title: "Oops! Looks like you missed something", diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index b76df56f2..89c7919af 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -356,7 +356,10 @@ export default function FormModal({ }, [open]); function sendMessage(): void { - let nodeValidationErrors = validateNodes(reactFlowInstance!); + let nodeValidationErrors = validateNodes( + reactFlowInstance!.getNodes(), + reactFlowInstance!.getEdges() + ); if (nodeValidationErrors.length === 0) { setLockChat(true); let inputs = tabsState[id.current].formKeysData.input_keys; diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 4b431cb22..5cb549471 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -189,10 +189,7 @@ export function buildTweaks(flow: FlowType) { }, {}); } -export function validateNode( - node: NodeType, - reactFlowInstance: ReactFlowInstance -): Array { +export function validateNode(node: NodeType, edges: Edge[]): Array { if (!node.data?.node?.template || !Object.keys(node.data.node.template)) { return [ "We've noticed a potential issue with a node in the flow. Please review it and, if necessary, submit a bug report with your exported flow file. Thank you for your help!", @@ -211,13 +208,11 @@ export function validateNode( (template[t].value === undefined || template[t].value === null || template[t].value === "") && - !reactFlowInstance - .getEdges() - .some( - (edge) => - edge.targetHandle?.split("|")[1] === t && - edge.targetHandle.split("|")[2] === node.id - ) + !edges.some( + (edge) => + edge.targetHandle?.split("|")[1] === t && + edge.targetHandle.split("|")[2] === node.id + ) ) { errors.push( `${type} is missing ${ @@ -249,15 +244,13 @@ export function validateNode( }, [] as string[]); } -export function validateNodes(reactFlowInstance: ReactFlowInstance) { - if (reactFlowInstance.getNodes().length === 0) { +export function validateNodes(nodes: Node[], edges: Edge[]) { + if (nodes.length === 0) { return [ "No nodes found in the flow. Please add at least one node to the flow.", ]; } - return reactFlowInstance - .getNodes() - .flatMap((n: NodeType) => validateNode(n, reactFlowInstance)); + return nodes.flatMap((n: NodeType) => validateNode(n, edges)); } export function addVersionToDuplicates(flow: FlowType, flows: FlowType[]) {