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(
|
export async function postBuildVertex(
|
||||||
flow: FlowType,
|
flowId: string,
|
||||||
vertexId: string
|
vertexId: string
|
||||||
): Promise<AxiosResponse<VertexBuildTypeAPI>> {
|
): Promise<AxiosResponse<VertexBuildTypeAPI>> {
|
||||||
return await api.post(
|
return await api.post(`${BASE_URL_API}build/${flowId}/vertices/${vertexId}`);
|
||||||
`${BASE_URL_API}build/${flow.id}/vertices/${vertexId}`,
|
|
||||||
flow
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -330,23 +330,14 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
buildFlow: async (nodeId?: string) => {
|
buildFlow: async (nodeId?: string) => {
|
||||||
function handleBuildUpdate(data: any) {
|
|
||||||
get().addDataToFlowPool(data.data[data.id], data.id);
|
|
||||||
}
|
|
||||||
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
const currentFlow = useFlowsManagerStore((state) => state.currentFlow);
|
||||||
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
const setSuccessData = useAlertStore((state) => state.setSuccessData);
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
|
function handleBuildUpdate(data: any) {
|
||||||
|
get().addDataToFlowPool(data.data[data.id], data.id);
|
||||||
|
}
|
||||||
return buildVertices({
|
return buildVertices({
|
||||||
flow: {
|
flowId: currentFlow!.id,
|
||||||
data: {
|
|
||||||
edges: get().edges,
|
|
||||||
nodes: get().nodes,
|
|
||||||
viewport: get().reactFlowInstance?.getViewport()!,
|
|
||||||
},
|
|
||||||
description: currentFlow?.description!,
|
|
||||||
id: currentFlow?.id!,
|
|
||||||
name: currentFlow?.name!,
|
|
||||||
},
|
|
||||||
nodeId,
|
nodeId,
|
||||||
onBuildComplete: () => {
|
onBuildComplete: () => {
|
||||||
if (nodeId) {
|
if (nodeId) {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
import { AxiosError } from "axios";
|
import { AxiosError } from "axios";
|
||||||
import { getVerticesOrder, postBuildVertex } from "../controllers/API";
|
import { getVerticesOrder, postBuildVertex } from "../controllers/API";
|
||||||
import { VertexBuildTypeAPI } from "../types/api";
|
import { VertexBuildTypeAPI } from "../types/api";
|
||||||
import { FlowType } from "../types/flow";
|
|
||||||
|
|
||||||
type BuildVerticesParams = {
|
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
|
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
|
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
|
onBuildUpdate?: (data: any) => void; // Replace any with the actual type of data
|
||||||
|
|
@ -13,14 +12,14 @@ type BuildVerticesParams = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function buildVertices({
|
export async function buildVertices({
|
||||||
flow,
|
flowId,
|
||||||
nodeId = null,
|
nodeId = null,
|
||||||
onProgressUpdate,
|
onProgressUpdate,
|
||||||
onBuildUpdate,
|
onBuildUpdate,
|
||||||
onBuildComplete,
|
onBuildComplete,
|
||||||
onBuildError,
|
onBuildError,
|
||||||
}: BuildVerticesParams) {
|
}: BuildVerticesParams) {
|
||||||
let orderResponse = await getVerticesOrder(flow.id);
|
let orderResponse = await getVerticesOrder(flowId);
|
||||||
let verticesOrder: Array<Array<string>> = orderResponse.data.ids;
|
let verticesOrder: Array<Array<string>> = orderResponse.data.ids;
|
||||||
let vertices: Array<Array<string>> = [];
|
let vertices: Array<Array<string>> = [];
|
||||||
if (nodeId) {
|
if (nodeId) {
|
||||||
|
|
@ -45,7 +44,7 @@ export async function buildVertices({
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
vertices[i].map(async (id) => {
|
vertices[i].map(async (id) => {
|
||||||
try {
|
try {
|
||||||
const buildRes = await postBuildVertex(flow, id);
|
const buildRes = await postBuildVertex(flowId, id);
|
||||||
const buildData: VertexBuildTypeAPI = buildRes.data;
|
const buildData: VertexBuildTypeAPI = buildRes.data;
|
||||||
if (onBuildUpdate) {
|
if (onBuildUpdate) {
|
||||||
let data = {};
|
let data = {};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue