refactor: Update new output creation logic in reactflowUtils.ts

This commit is contained in:
anovazzi1 2024-05-31 16:14:09 -03:00
commit 513046caba

View file

@ -1,3 +1,4 @@
import { AxiosError } from "axios";
import { cloneDeep, debounce } from "lodash"; import { cloneDeep, debounce } from "lodash";
import { Edge, Node, Viewport, XYPosition } from "reactflow"; import { Edge, Node, Viewport, XYPosition } from "reactflow";
import { create } from "zustand"; import { create } from "zustand";
@ -84,7 +85,7 @@ const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
readFlowsFromDatabase() readFlowsFromDatabase()
.then((dbData) => { .then((dbData) => {
if (dbData) { if (dbData) {
const { data, flows } = processFlows(dbData); const { data, flows } = processFlows(dbData, false);
const examples = flows.filter( const examples = flows.filter(
(flow) => flow.folder_id === starterFolderId, (flow) => flow.folder_id === starterFolderId,
); );
@ -154,9 +155,11 @@ const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
} }
}) })
.catch((err) => { .catch((err) => {
useAlertStore.getState().setErrorData({
title: "Error while saving changes",
list: [(err as AxiosError).message],
});
reject(err); reject(err);
set({ saveLoading: false });
throw err;
}); });
}); });
}, SAVE_DEBOUNCE_TIME), }, SAVE_DEBOUNCE_TIME),
@ -229,6 +232,7 @@ const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
// addFlowToLocalState(newFlow); // addFlowToLocalState(newFlow);
return; return;
} }
console.log("folder id", folder_id);
const newFlow = createNewFlow( const newFlow = createNewFlow(
flowData!, flowData!,
flow!, flow!,
@ -267,7 +271,7 @@ const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
useFlowStore useFlowStore
.getState() .getState()
.paste( .paste(
{ nodes: flow!.data!.nodes, edges: flow!.data!.edges }, { nodes: flowData?.nodes, edges: flowData?.edges },
position ?? { x: 10, y: 10 }, position ?? { x: 10, y: 10 },
); );
} }