Add onGetOrderSuccess and fix error in get vertices order
This commit is contained in:
parent
694418827d
commit
2118869e1e
2 changed files with 32 additions and 13 deletions
|
|
@ -9,6 +9,7 @@ import {
|
||||||
applyNodeChanges,
|
applyNodeChanges,
|
||||||
} from "reactflow";
|
} from "reactflow";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
import { FLOW_BUILD_SUCCESS_ALERT } from "../alerts_constants";
|
||||||
import { BuildStatus } from "../constants/enums";
|
import { BuildStatus } from "../constants/enums";
|
||||||
import { getFlowPool, updateFlowInDatabase } from "../controllers/API";
|
import { getFlowPool, updateFlowInDatabase } from "../controllers/API";
|
||||||
import { VertexBuildTypeAPI } from "../types/api";
|
import { VertexBuildTypeAPI } from "../types/api";
|
||||||
|
|
@ -32,7 +33,6 @@ import { getInputsAndOutputs } from "../utils/storeUtils";
|
||||||
import useAlertStore from "./alertStore";
|
import useAlertStore from "./alertStore";
|
||||||
import { useDarkStore } from "./darkStore";
|
import { useDarkStore } from "./darkStore";
|
||||||
import useFlowsManagerStore from "./flowsManagerStore";
|
import useFlowsManagerStore from "./flowsManagerStore";
|
||||||
import { FLOW_BUILD_SUCCESS_ALERT } from "../alerts_constants";
|
|
||||||
|
|
||||||
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
||||||
const useFlowStore = create<FlowStoreType>((set, get) => ({
|
const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
|
|
@ -378,8 +378,11 @@ 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[]){
|
function validateSubgraph(nodes: string[]) {
|
||||||
const errors = validateNodes(get().nodes.filter(node=>nodes.includes(node.id)), get().edges);
|
const errors = validateNodes(
|
||||||
|
get().nodes.filter((node) => nodes.includes(node.id)),
|
||||||
|
get().edges
|
||||||
|
);
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title: "Oops! Looks like you missed something",
|
title: "Oops! Looks like you missed something",
|
||||||
|
|
@ -409,10 +412,12 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
name: currentFlow!.name,
|
name: currentFlow!.name,
|
||||||
description: currentFlow!.description,
|
description: currentFlow!.description,
|
||||||
});
|
});
|
||||||
setNoticeData({ title: "Running components" });
|
|
||||||
await buildVertices({
|
await buildVertices({
|
||||||
flowId: currentFlow!.id,
|
flowId: currentFlow!.id,
|
||||||
nodeId,
|
nodeId,
|
||||||
|
onGetOrderSuccess: () => {
|
||||||
|
setNoticeData({ title: "Running components" });
|
||||||
|
},
|
||||||
onBuildComplete: () => {
|
onBuildComplete: () => {
|
||||||
if (nodeId) {
|
if (nodeId) {
|
||||||
setSuccessData({
|
setSuccessData({
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,19 @@
|
||||||
import { AxiosError } from "axios";
|
import { AxiosError } from "axios";
|
||||||
import { BuildStatus } from "../constants/enums";
|
import { BuildStatus } from "../constants/enums";
|
||||||
import { getVerticesOrder, postBuildVertex } from "../controllers/API";
|
import { getVerticesOrder, postBuildVertex } from "../controllers/API";
|
||||||
|
import useAlertStore from "../stores/alertStore";
|
||||||
import useFlowStore from "../stores/flowStore";
|
import useFlowStore from "../stores/flowStore";
|
||||||
import { VertexBuildTypeAPI } from "../types/api";
|
import { VertexBuildTypeAPI } from "../types/api";
|
||||||
|
|
||||||
type BuildVerticesParams = {
|
type BuildVerticesParams = {
|
||||||
flowId: string; // Assuming FlowType is the type for your flow
|
flowId: string; // Assuming FlowType is the type for your flow
|
||||||
nodeId?: string | null; // Assuming nodeId is of type string, and it's optional
|
nodeId?: string | null; // Assuming nodeId is of type string, and it's optional
|
||||||
onProgressUpdate?: (progress: number) => void; // Replace number with the actual type if it's not a number
|
onGetOrderSuccess?: () => void;
|
||||||
onBuildUpdate?: (data: VertexBuildTypeAPI, status: BuildStatus) => void; // Replace any with the actual type if it's not any
|
onBuildUpdate?: (data: VertexBuildTypeAPI, status: BuildStatus) => void; // Replace any with the actual type if it's not any
|
||||||
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;
|
validateNodes?: (nodes: string[]) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI {
|
function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI {
|
||||||
|
|
@ -36,21 +37,34 @@ function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI {
|
||||||
export async function buildVertices({
|
export async function buildVertices({
|
||||||
flowId,
|
flowId,
|
||||||
nodeId = null,
|
nodeId = null,
|
||||||
onProgressUpdate,
|
onGetOrderSuccess,
|
||||||
onBuildUpdate,
|
onBuildUpdate,
|
||||||
onBuildComplete,
|
onBuildComplete,
|
||||||
onBuildError,
|
onBuildError,
|
||||||
onBuildStart,
|
onBuildStart,
|
||||||
validateNodes
|
validateNodes,
|
||||||
}: BuildVerticesParams) {
|
}: BuildVerticesParams) {
|
||||||
let orderResponse = await getVerticesOrder(flowId, nodeId);
|
const setErrorData = useAlertStore.getState().setErrorData;
|
||||||
|
let orderResponse;
|
||||||
|
try {
|
||||||
|
orderResponse = await getVerticesOrder(flowId, nodeId);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
setErrorData({
|
||||||
|
title: "Oops! Looks like you missed something",
|
||||||
|
list: [error.response?.data?.detail ?? "Unknown Error"],
|
||||||
|
});
|
||||||
|
useFlowStore.getState().setIsBuilding(false);
|
||||||
|
throw new Error("Invalid nodes");
|
||||||
|
}
|
||||||
|
if (onGetOrderSuccess) onGetOrderSuccess();
|
||||||
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){
|
if (validateNodes) {
|
||||||
try{
|
try {
|
||||||
validateNodes(verticesOrder.flatMap(id=>id))
|
validateNodes(verticesOrder.flatMap((id) => id));
|
||||||
} catch(e){
|
} catch (e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue