Add VertexBuildTypeAPI import and refactor handleBuildUpdate function
This commit is contained in:
parent
70bd1d0c2a
commit
53ae82f0b9
1 changed files with 23 additions and 14 deletions
|
|
@ -11,6 +11,7 @@ import {
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { BuildStatus } from "../constants/enums";
|
import { BuildStatus } from "../constants/enums";
|
||||||
import { getFlowPool, updateFlowInDatabase } from "../controllers/API";
|
import { getFlowPool, updateFlowInDatabase } from "../controllers/API";
|
||||||
|
import { VertexBuildTypeAPI } from "../types/api";
|
||||||
import {
|
import {
|
||||||
NodeDataType,
|
NodeDataType,
|
||||||
NodeType,
|
NodeType,
|
||||||
|
|
@ -151,7 +152,6 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
? change(get().nodes.find((node) => node.id === id)!)
|
? change(get().nodes.find((node) => node.id === id)!)
|
||||||
: change;
|
: change;
|
||||||
|
|
||||||
console.log(newChange);
|
|
||||||
get().setNodes((oldNodes) =>
|
get().setNodes((oldNodes) =>
|
||||||
oldNodes.map((node) => {
|
oldNodes.map((node) => {
|
||||||
if (node.id === id) {
|
if (node.id === id) {
|
||||||
|
|
@ -375,17 +375,15 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
const setSuccessData = useAlertStore.getState().setSuccessData;
|
const setSuccessData = useAlertStore.getState().setSuccessData;
|
||||||
const setErrorData = useAlertStore.getState().setErrorData;
|
const setErrorData = useAlertStore.getState().setErrorData;
|
||||||
const setNoticeData = useAlertStore.getState().setNoticeData;
|
const setNoticeData = useAlertStore.getState().setNoticeData;
|
||||||
function handleBuildUpdate(data: any) {
|
function handleBuildUpdate(
|
||||||
const responseData = data.data[data.id];
|
vertexBuildData: VertexBuildTypeAPI,
|
||||||
// responseData MAY contain inactive_vertices or it
|
status: BuildStatus
|
||||||
// may be null, so we need to check for it
|
) {
|
||||||
if (responseData && responseData.inactive_vertices) {
|
if (vertexBuildData && vertexBuildData.inactive_vertices) {
|
||||||
useFlowStore
|
get().removeFromVerticesBuild(vertexBuildData.inactive_vertices);
|
||||||
.getState()
|
|
||||||
.setInactiveNodes(responseData.inactive_vertices);
|
|
||||||
}
|
}
|
||||||
get().addDataToFlowPool(data.data[data.id], data.id);
|
get().addDataToFlowPool(vertexBuildData, vertexBuildData.id);
|
||||||
useFlowStore.getState().updateBuildStatus([data.id], BuildStatus.BUILT);
|
useFlowStore.getState().updateBuildStatus([vertexBuildData.id], status);
|
||||||
}
|
}
|
||||||
await updateFlowInDatabase({
|
await updateFlowInDatabase({
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -418,6 +416,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
useFlowStore.getState().updateBuildStatus(idList, BuildStatus.BUILDING);
|
useFlowStore.getState().updateBuildStatus(idList, BuildStatus.BUILDING);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
get().revertAllVerticesToBuild();
|
||||||
},
|
},
|
||||||
getFlow: () => {
|
getFlow: () => {
|
||||||
return {
|
return {
|
||||||
|
|
@ -439,10 +438,20 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
set({ verticesBuild: vertices });
|
set({ verticesBuild: vertices });
|
||||||
},
|
},
|
||||||
verticesBuild: [],
|
verticesBuild: [],
|
||||||
setInactiveNodes(newState) {
|
revertAllVerticesToBuild: () => {
|
||||||
set({ inactiveNodes: newState });
|
// set all vertices to TO_BUILD
|
||||||
|
const verticesIds = get()
|
||||||
|
.nodes.filter((node) => node.data.build_status === BuildStatus.BUILDING)
|
||||||
|
.map((node) => node.id);
|
||||||
|
get().updateBuildStatus(verticesIds, BuildStatus.TO_BUILD);
|
||||||
|
},
|
||||||
|
removeFromVerticesBuild: (vertices: string[]) => {
|
||||||
|
set({
|
||||||
|
verticesBuild: get().verticesBuild.filter(
|
||||||
|
(vertex) => !vertices.includes(vertex)
|
||||||
|
),
|
||||||
|
});
|
||||||
},
|
},
|
||||||
inactiveNodes: [],
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export default useFlowStore;
|
export default useFlowStore;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue