From 5f0cd43ec593de7e8cd551e46082c779b3f76074 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Wed, 24 Jan 2024 17:17:55 -0300 Subject: [PATCH] Refactor buildVertices function to use flowId instead of flow object --- src/frontend/src/controllers/API/index.ts | 7 ++----- src/frontend/src/stores/flowStore.ts | 17 ++++------------- src/frontend/src/utils/buildUtils.ts | 9 ++++----- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index 90a9cda3d..f414db1eb 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -861,11 +861,8 @@ export async function getVerticesOrder( } export async function postBuildVertex( - flow: FlowType, + flowId: string, vertexId: string ): Promise> { - return await api.post( - `${BASE_URL_API}build/${flow.id}/vertices/${vertexId}`, - flow - ); + return await api.post(`${BASE_URL_API}build/${flowId}/vertices/${vertexId}`); } diff --git a/src/frontend/src/stores/flowStore.ts b/src/frontend/src/stores/flowStore.ts index 4127de910..e2691f742 100644 --- a/src/frontend/src/stores/flowStore.ts +++ b/src/frontend/src/stores/flowStore.ts @@ -330,23 +330,14 @@ const useFlowStore = create((set, get) => ({ }); }, buildFlow: async (nodeId?: string) => { - function handleBuildUpdate(data: any) { - get().addDataToFlowPool(data.data[data.id], data.id); - } const currentFlow = useFlowsManagerStore((state) => state.currentFlow); const setSuccessData = useAlertStore((state) => state.setSuccessData); const setErrorData = useAlertStore((state) => state.setErrorData); + function handleBuildUpdate(data: any) { + get().addDataToFlowPool(data.data[data.id], data.id); + } return buildVertices({ - flow: { - data: { - edges: get().edges, - nodes: get().nodes, - viewport: get().reactFlowInstance?.getViewport()!, - }, - description: currentFlow?.description!, - id: currentFlow?.id!, - name: currentFlow?.name!, - }, + flowId: currentFlow!.id, nodeId, onBuildComplete: () => { if (nodeId) { diff --git a/src/frontend/src/utils/buildUtils.ts b/src/frontend/src/utils/buildUtils.ts index 9ffcfc955..60fb1a0b6 100644 --- a/src/frontend/src/utils/buildUtils.ts +++ b/src/frontend/src/utils/buildUtils.ts @@ -1,10 +1,9 @@ import { AxiosError } from "axios"; import { getVerticesOrder, postBuildVertex } from "../controllers/API"; import { VertexBuildTypeAPI } from "../types/api"; -import { FlowType } from "../types/flow"; type BuildVerticesParams = { - flow: FlowType; // 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 onProgressUpdate?: (progress: number) => void; // Replace number with the actual type if it's not a number onBuildUpdate?: (data: any) => void; // Replace any with the actual type of data @@ -13,14 +12,14 @@ type BuildVerticesParams = { }; export async function buildVertices({ - flow, + flowId, nodeId = null, onProgressUpdate, onBuildUpdate, onBuildComplete, onBuildError, }: BuildVerticesParams) { - let orderResponse = await getVerticesOrder(flow.id); + let orderResponse = await getVerticesOrder(flowId); let verticesOrder: Array> = orderResponse.data.ids; let vertices: Array> = []; if (nodeId) { @@ -45,7 +44,7 @@ export async function buildVertices({ await Promise.all( vertices[i].map(async (id) => { try { - const buildRes = await postBuildVertex(flow, id); + const buildRes = await postBuildVertex(flowId, id); const buildData: VertexBuildTypeAPI = buildRes.data; if (onBuildUpdate) { let data = {};