checkNodes
This commit is contained in:
parent
864f74be55
commit
f1e097d052
3 changed files with 22 additions and 12 deletions
|
|
@ -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<void> {
|
||||
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(() => {
|
||||
|
|
|
|||
|
|
@ -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<FlowStoreType>((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<FlowStoreType>((set, get) => ({
|
|||
onBuildStart: (idList) => {
|
||||
useFlowStore.getState().updateBuildStatus(idList, BuildStatus.BUILDING);
|
||||
},
|
||||
validateNodes: validateSubgraph,
|
||||
});
|
||||
get().revertBuiltStatusFromBuilding();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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<Array<string>> = orderResponse.data.ids;
|
||||
let vertices_layers: Array<Array<string>> = [];
|
||||
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];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue