diff --git a/src/frontend/src/components/IOview/index.tsx b/src/frontend/src/components/IOview/index.tsx index b0eb16547..d745ca1b4 100644 --- a/src/frontend/src/components/IOview/index.tsx +++ b/src/frontend/src/components/IOview/index.tsx @@ -4,7 +4,6 @@ import { CHAT_FORM_DIALOG_SUBTITLE } from "../../constants/constants"; import BaseModal from "../../modals/baseModal"; import useAlertStore from "../../stores/alertStore"; import useFlowStore from "../../stores/flowStore"; -import { validateNodes } from "../../utils/reactflowUtils"; import { cn } from "../../utils/utils"; import AccordionComponent from "../AccordionComponent"; import IOInputField from "../IOInputField"; @@ -51,8 +50,6 @@ export default function IOView({ children, open, setOpen }): JSX.Element { async function sendMessage(count = 1): Promise { if (isBuilding) return; const { nodes, edges } = getFlow(); - let nodeValidationErrors = validateNodes(nodes, edges); - if (nodeValidationErrors.length === 0) { setIsBuilding(true); setLockChat(true); setChatValue(""); @@ -70,14 +67,6 @@ export default function IOView({ children, open, setOpen }): JSX.Element { } setLockChat(false); - //set chat message in the flow and run build - //@ts-ignore - } else { - setErrorData({ - title: "Oops! Looks like you missed some required information:", - list: nodeValidationErrors, - }); - } } useEffect(() => { diff --git a/src/frontend/src/stores/flowStore.ts b/src/frontend/src/stores/flowStore.ts index f1e5c85ea..c1b2f7547 100644 --- a/src/frontend/src/stores/flowStore.ts +++ b/src/frontend/src/stores/flowStore.ts @@ -26,6 +26,7 @@ import { getNodeId, scapeJSONParse, scapedJSONStringfy, + validateNodes, } from "../utils/reactflowUtils"; import { getInputsAndOutputs } from "../utils/storeUtils"; import useAlertStore from "./alertStore"; @@ -377,6 +378,17 @@ const useFlowStore = create((set, get) => ({ const setSuccessData = useAlertStore.getState().setSuccessData; const setErrorData = useAlertStore.getState().setErrorData; const setNoticeData = useAlertStore.getState().setNoticeData; + function validateSubgraph(nodes:string[]){ + const errors = validateNodes(get().nodes.filter(node=>nodes.includes(node.id)), get().edges); + if (errors.length > 0) { + setErrorData({ + title: "Oops! Looks like you missed something", + list: errors, + }); + get().setIsBuilding(false); + throw new Error("Invalid nodes"); + } + } function handleBuildUpdate( vertexBuildData: VertexBuildTypeAPI, status: BuildStatus @@ -422,6 +434,7 @@ const useFlowStore = create((set, get) => ({ onBuildStart: (idList) => { useFlowStore.getState().updateBuildStatus(idList, BuildStatus.BUILDING); }, + validateNodes: validateSubgraph, }); get().revertBuiltStatusFromBuilding(); }, diff --git a/src/frontend/src/utils/buildUtils.ts b/src/frontend/src/utils/buildUtils.ts index fd87ccd4e..87d431770 100644 --- a/src/frontend/src/utils/buildUtils.ts +++ b/src/frontend/src/utils/buildUtils.ts @@ -12,6 +12,7 @@ type BuildVerticesParams = { onBuildComplete?: (allNodesValid: boolean) => void; onBuildError?: (title, list, idList: string[]) => void; onBuildStart?: (idList: string[]) => void; + validateNodes?: (nodes:string[])=>void; }; function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI { @@ -40,12 +41,19 @@ export async function buildVertices({ onBuildComplete, onBuildError, onBuildStart, + validateNodes }: BuildVerticesParams) { let orderResponse = await getVerticesOrder(flowId, nodeId); let verticesOrder: Array> = orderResponse.data.ids; let vertices_layers: Array> = []; let stop = false; - + if(validateNodes){ + try{ + validateNodes(verticesOrder.flatMap(id=>id)) + } catch(e){ + return; + } + } if (nodeId) { for (let i = 0; i < verticesOrder.length; i += 1) { const innerArray = verticesOrder[i];