Refactor buildVertices function and add getInactiveVertexData function
This commit is contained in:
parent
6acace790e
commit
7c15593d85
1 changed files with 28 additions and 11 deletions
|
|
@ -8,12 +8,30 @@ 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
|
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: 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI {
|
||||||
|
// Build VertexBuildTypeAPI
|
||||||
|
let inactiveData = {
|
||||||
|
results: {},
|
||||||
|
artifacts: { repr: "Inactive" },
|
||||||
|
};
|
||||||
|
let inactiveVertexData = {
|
||||||
|
id: vertexId,
|
||||||
|
data: inactiveData,
|
||||||
|
params: "Inactive",
|
||||||
|
inactive_vertices: null,
|
||||||
|
valid: false,
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
return inactiveVertexData;
|
||||||
|
}
|
||||||
|
|
||||||
export async function buildVertices({
|
export async function buildVertices({
|
||||||
flowId,
|
flowId,
|
||||||
nodeId = null,
|
nodeId = null,
|
||||||
|
|
@ -57,11 +75,13 @@ export async function buildVertices({
|
||||||
if (onBuildStart) onBuildStart(layer);
|
if (onBuildStart) onBuildStart(layer);
|
||||||
for (const id of layer) {
|
for (const id of layer) {
|
||||||
// Check if id is in the list of inactive nodes
|
// Check if id is in the list of inactive nodes
|
||||||
if (useFlowStore.getState().inactiveNodes.includes(id)) {
|
if (
|
||||||
// If it is, skip building
|
!useFlowStore.getState().verticesBuild.includes(id) &&
|
||||||
// it should be true because it did
|
onBuildUpdate
|
||||||
// what it was supposed to do
|
) {
|
||||||
buildResults.push(true);
|
// If it is, skip building and set the state to inactive
|
||||||
|
onBuildUpdate(getInactiveVertexData(id), BuildStatus.INACTIVE);
|
||||||
|
buildResults.push(false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
await buildVertex({
|
await buildVertex({
|
||||||
|
|
@ -88,7 +108,6 @@ export async function buildVertices({
|
||||||
const allNodesValid = buildResults.every((result) => result);
|
const allNodesValid = buildResults.every((result) => result);
|
||||||
onBuildComplete(allNodesValid);
|
onBuildComplete(allNodesValid);
|
||||||
useFlowStore.getState().setIsBuilding(false);
|
useFlowStore.getState().setIsBuilding(false);
|
||||||
useFlowStore.getState().setInactiveNodes([]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,7 +122,7 @@ async function buildVertex({
|
||||||
}: {
|
}: {
|
||||||
flowId: string;
|
flowId: string;
|
||||||
id: string;
|
id: string;
|
||||||
onBuildUpdate?: (data: any) => void;
|
onBuildUpdate?: (data: any, status: BuildStatus) => void;
|
||||||
onBuildError?: (title, list, idList: string[]) => void;
|
onBuildError?: (title, list, idList: string[]) => void;
|
||||||
verticesIds: string[];
|
verticesIds: string[];
|
||||||
buildResults: boolean[];
|
buildResults: boolean[];
|
||||||
|
|
@ -113,7 +132,6 @@ async function buildVertex({
|
||||||
const buildRes = await postBuildVertex(flowId, id);
|
const buildRes = await postBuildVertex(flowId, id);
|
||||||
const buildData: VertexBuildTypeAPI = buildRes.data;
|
const buildData: VertexBuildTypeAPI = buildRes.data;
|
||||||
if (onBuildUpdate) {
|
if (onBuildUpdate) {
|
||||||
let data = {};
|
|
||||||
if (!buildData.valid) {
|
if (!buildData.valid) {
|
||||||
onBuildError!(
|
onBuildError!(
|
||||||
"Error Building Component",
|
"Error Building Component",
|
||||||
|
|
@ -122,8 +140,7 @@ async function buildVertex({
|
||||||
);
|
);
|
||||||
stopBuild();
|
stopBuild();
|
||||||
}
|
}
|
||||||
data[buildData.id] = buildData;
|
onBuildUpdate(buildData, BuildStatus.BUILT);
|
||||||
onBuildUpdate({ data, id: buildData.id });
|
|
||||||
}
|
}
|
||||||
buildResults.push(buildData.valid);
|
buildResults.push(buildData.valid);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue