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 BaseModal from "../../modals/baseModal";
|
||||||
import useAlertStore from "../../stores/alertStore";
|
import useAlertStore from "../../stores/alertStore";
|
||||||
import useFlowStore from "../../stores/flowStore";
|
import useFlowStore from "../../stores/flowStore";
|
||||||
import { validateNodes } from "../../utils/reactflowUtils";
|
|
||||||
import { cn } from "../../utils/utils";
|
import { cn } from "../../utils/utils";
|
||||||
import AccordionComponent from "../AccordionComponent";
|
import AccordionComponent from "../AccordionComponent";
|
||||||
import IOInputField from "../IOInputField";
|
import IOInputField from "../IOInputField";
|
||||||
|
|
@ -51,8 +50,6 @@ export default function IOView({ children, open, setOpen }): JSX.Element {
|
||||||
async function sendMessage(count = 1): Promise<void> {
|
async function sendMessage(count = 1): Promise<void> {
|
||||||
if (isBuilding) return;
|
if (isBuilding) return;
|
||||||
const { nodes, edges } = getFlow();
|
const { nodes, edges } = getFlow();
|
||||||
let nodeValidationErrors = validateNodes(nodes, edges);
|
|
||||||
if (nodeValidationErrors.length === 0) {
|
|
||||||
setIsBuilding(true);
|
setIsBuilding(true);
|
||||||
setLockChat(true);
|
setLockChat(true);
|
||||||
setChatValue("");
|
setChatValue("");
|
||||||
|
|
@ -70,14 +67,6 @@ export default function IOView({ children, open, setOpen }): JSX.Element {
|
||||||
}
|
}
|
||||||
setLockChat(false);
|
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(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import {
|
||||||
getNodeId,
|
getNodeId,
|
||||||
scapeJSONParse,
|
scapeJSONParse,
|
||||||
scapedJSONStringfy,
|
scapedJSONStringfy,
|
||||||
|
validateNodes,
|
||||||
} from "../utils/reactflowUtils";
|
} from "../utils/reactflowUtils";
|
||||||
import { getInputsAndOutputs } from "../utils/storeUtils";
|
import { getInputsAndOutputs } from "../utils/storeUtils";
|
||||||
import useAlertStore from "./alertStore";
|
import useAlertStore from "./alertStore";
|
||||||
|
|
@ -377,6 +378,17 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
const setSuccessData = useAlertStore.getState().setSuccessData;
|
const setSuccessData = useAlertStore.getState().setSuccessData;
|
||||||
const setErrorData = useAlertStore.getState().setErrorData;
|
const setErrorData = useAlertStore.getState().setErrorData;
|
||||||
const setNoticeData = useAlertStore.getState().setNoticeData;
|
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(
|
function handleBuildUpdate(
|
||||||
vertexBuildData: VertexBuildTypeAPI,
|
vertexBuildData: VertexBuildTypeAPI,
|
||||||
status: BuildStatus
|
status: BuildStatus
|
||||||
|
|
@ -422,6 +434,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
onBuildStart: (idList) => {
|
onBuildStart: (idList) => {
|
||||||
useFlowStore.getState().updateBuildStatus(idList, BuildStatus.BUILDING);
|
useFlowStore.getState().updateBuildStatus(idList, BuildStatus.BUILDING);
|
||||||
},
|
},
|
||||||
|
validateNodes: validateSubgraph,
|
||||||
});
|
});
|
||||||
get().revertBuiltStatusFromBuilding();
|
get().revertBuiltStatusFromBuilding();
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ type BuildVerticesParams = {
|
||||||
onBuildComplete?: (allNodesValid: boolean) => void;
|
onBuildComplete?: (allNodesValid: boolean) => void;
|
||||||
onBuildError?: (title, list, idList: string[]) => void;
|
onBuildError?: (title, list, idList: string[]) => void;
|
||||||
onBuildStart?: (idList: string[]) => void;
|
onBuildStart?: (idList: string[]) => void;
|
||||||
|
validateNodes?: (nodes:string[])=>void;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI {
|
function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI {
|
||||||
|
|
@ -40,12 +41,19 @@ export async function buildVertices({
|
||||||
onBuildComplete,
|
onBuildComplete,
|
||||||
onBuildError,
|
onBuildError,
|
||||||
onBuildStart,
|
onBuildStart,
|
||||||
|
validateNodes
|
||||||
}: BuildVerticesParams) {
|
}: BuildVerticesParams) {
|
||||||
let orderResponse = await getVerticesOrder(flowId, nodeId);
|
let orderResponse = await getVerticesOrder(flowId, nodeId);
|
||||||
let verticesOrder: Array<Array<string>> = orderResponse.data.ids;
|
let verticesOrder: Array<Array<string>> = orderResponse.data.ids;
|
||||||
let vertices_layers: Array<Array<string>> = [];
|
let vertices_layers: Array<Array<string>> = [];
|
||||||
let stop = false;
|
let stop = false;
|
||||||
|
if(validateNodes){
|
||||||
|
try{
|
||||||
|
validateNodes(verticesOrder.flatMap(id=>id))
|
||||||
|
} catch(e){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (nodeId) {
|
if (nodeId) {
|
||||||
for (let i = 0; i < verticesOrder.length; i += 1) {
|
for (let i = 0; i < verticesOrder.length; i += 1) {
|
||||||
const innerArray = verticesOrder[i];
|
const innerArray = verticesOrder[i];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue