Refactor vertices order handling

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-01 19:08:23 -03:00
commit 5300549b61

View file

@ -61,11 +61,12 @@ export async function updateVerticesOrder(
useFlowStore.getState().setIsBuilding(false); useFlowStore.getState().setIsBuilding(false);
throw new Error("Invalid nodes"); throw new Error("Invalid nodes");
} }
let verticesLayers: Array<Array<string>> = orderResponse.data.ids; let verticesOrder: Array<Array<string>> = orderResponse.data.ids;
let verticesLayers: Array<Array<string>> = [];
const runId = orderResponse.data.run_id; const runId = orderResponse.data.run_id;
if (nodeId) { if (nodeId) {
for (let i = 0; i < verticesLayers.length; i += 1) { for (let i = 0; i < verticesOrder.length; i += 1) {
const innerArray = verticesLayers[i]; const innerArray = verticesOrder[i];
const idIndex = innerArray.indexOf(nodeId); const idIndex = innerArray.indexOf(nodeId);
if (idIndex !== -1) { if (idIndex !== -1) {
// If there's a nodeId, we want to run just that component and not the entire layer // If there's a nodeId, we want to run just that component and not the entire layer
@ -78,7 +79,7 @@ export async function updateVerticesOrder(
verticesLayers.push(innerArray); verticesLayers.push(innerArray);
} }
} }
const verticesIds = verticesLayers.flat(); const verticesIds = verticesOrder.flat();
useFlowStore.getState().updateVerticesBuild({ useFlowStore.getState().updateVerticesBuild({
verticesLayers, verticesLayers,
verticesIds, verticesIds,
@ -183,9 +184,8 @@ async function buildVertex({
stopBuild: () => void; stopBuild: () => void;
}) { }) {
try { try {
console.log("Building vertex", id);
const buildRes = await postBuildVertex(flowId, id, input_value); const buildRes = await postBuildVertex(flowId, id, input_value);
console.log(buildRes);
const buildData: VertexBuildTypeAPI = buildRes.data; const buildData: VertexBuildTypeAPI = buildRes.data;
if (onBuildUpdate) { if (onBuildUpdate) {
if (!buildData.valid) { if (!buildData.valid) {