Add buildFlow function to useFlowStore
This commit is contained in:
parent
cb6636486c
commit
67b70ab5ca
2 changed files with 34 additions and 51 deletions
|
|
@ -16,6 +16,7 @@ import {
|
|||
targetHandleType,
|
||||
} from "../types/flow";
|
||||
import { FlowStoreType } from "../types/zustand/flow";
|
||||
import { buildVertices } from "../utils/buildUtils";
|
||||
import {
|
||||
cleanEdges,
|
||||
getHandleId,
|
||||
|
|
@ -25,6 +26,7 @@ import {
|
|||
scapeJSONParse,
|
||||
scapedJSONStringfy,
|
||||
} from "../utils/reactflowUtils";
|
||||
import useAlertStore from "./alertStore";
|
||||
import useFlowsManagerStore from "./flowsManagerStore";
|
||||
|
||||
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
||||
|
|
@ -393,6 +395,38 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
|||
set({ outputIds });
|
||||
return outputIds;
|
||||
},
|
||||
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);
|
||||
return buildVertices({
|
||||
flow: {
|
||||
data: {
|
||||
edges: get().edges,
|
||||
nodes: get().nodes,
|
||||
viewport: get().reactFlowInstance?.getViewport()!,
|
||||
},
|
||||
description: currentFlow?.description!,
|
||||
id: currentFlow?.id!,
|
||||
name: currentFlow?.name!,
|
||||
},
|
||||
nodeId,
|
||||
onBuildComplete: () => {
|
||||
if (nodeId) {
|
||||
setSuccessData({ title: `${nodeId} built successfully` });
|
||||
} else {
|
||||
setSuccessData({ title: `Flow built successfully` });
|
||||
}
|
||||
},
|
||||
onBuildUpdate: handleBuildUpdate,
|
||||
onBuildError: (title, list) => {
|
||||
setErrorData({ list, title });
|
||||
},
|
||||
});
|
||||
},
|
||||
}));
|
||||
|
||||
export default useFlowStore;
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
import { create } from "zustand";
|
||||
import useAlertStore from "./alertStore";
|
||||
import useFlowStore from "./flowStore";
|
||||
import useFlowsManagerStore from "./flowsManagerStore";
|
||||
/* const { getNodeId, saveFlow } = useContext(FlowsContext);
|
||||
const { setErrorData, setNoticeData } = useContext(alertContext); */
|
||||
|
||||
const { reactFlowInstance, paste } = useFlowStore();
|
||||
const { saveFlow } = useFlowsManagerStore();
|
||||
const { setErrorData, setNoticeData } = useAlertStore();
|
||||
|
||||
const useFlowIOStore = create<any>((set, get) => ({
|
||||
/* buildFlow: async (nodeId?: string) => {
|
||||
function handleBuildUpdate(data: any) {
|
||||
get().addDataToFlowPool(data.data[data.id], data.id);
|
||||
}
|
||||
console.log(
|
||||
"building flow before save",
|
||||
JSON.parse(JSON.stringify(get().actualFlow))
|
||||
);
|
||||
console.log(saveFlow);
|
||||
await saveFlow(
|
||||
{ ...get().actualFlow!, data: reactFlowInstance!.toObject()! },
|
||||
true
|
||||
);
|
||||
console.log(
|
||||
"building flow AFTER save",
|
||||
JSON.parse(JSON.stringify(get().actualFlow))
|
||||
);
|
||||
return buildVertices({
|
||||
flow: {
|
||||
data: reactFlowInstance?.toObject()!,
|
||||
description: get().actualFlow!.description,
|
||||
id: get().actualFlow!.id,
|
||||
name: get().actualFlow!.name,
|
||||
},
|
||||
nodeId,
|
||||
onBuildComplete: () => {
|
||||
if (nodeId) {
|
||||
setNoticeData({ title: `${nodeId} built successfully` });
|
||||
}
|
||||
},
|
||||
onBuildUpdate: handleBuildUpdate,
|
||||
onBuildError: (title, list) => {
|
||||
setErrorData({ list, title });
|
||||
},
|
||||
});
|
||||
}, */
|
||||
}));
|
||||
|
||||
export default useFlowIOStore;
|
||||
Loading…
Add table
Add a link
Reference in a new issue