Refactor buildVertices function to use flowId instead of flow object
This commit is contained in:
parent
7c28f0e7cb
commit
5f0cd43ec5
3 changed files with 10 additions and 23 deletions
|
|
@ -861,11 +861,8 @@ export async function getVerticesOrder(
|
|||
}
|
||||
|
||||
export async function postBuildVertex(
|
||||
flow: FlowType,
|
||||
flowId: string,
|
||||
vertexId: string
|
||||
): Promise<AxiosResponse<VertexBuildTypeAPI>> {
|
||||
return await api.post(
|
||||
`${BASE_URL_API}build/${flow.id}/vertices/${vertexId}`,
|
||||
flow
|
||||
);
|
||||
return await api.post(`${BASE_URL_API}build/${flowId}/vertices/${vertexId}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -330,23 +330,14 @@ const useFlowStore = create<FlowStoreType>((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) {
|
||||
|
|
|
|||
|
|
@ -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<Array<string>> = orderResponse.data.ids;
|
||||
let vertices: Array<Array<string>> = [];
|
||||
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 = {};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue