From 82a8b633a6b3395096276ace308d96dcd945f17a Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Tue, 30 May 2023 00:40:50 -0300 Subject: [PATCH] new save function to prevent break with large files --- src/frontend/src/contexts/tabsContext.tsx | 38 +++++++++++++---------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index 1a95d3157..2c3103477 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -19,6 +19,7 @@ import { typesContext } from "./typesContext"; import { APITemplateType, TemplateVariableType } from "../types/api"; import { v4 as uuidv4 } from "uuid"; import { addEdge } from "reactflow"; +import _ from "lodash"; const TabsContextInitialValue: TabsContextType = { save: () => {}, @@ -58,25 +59,30 @@ export function TabsProvider({ children }: { children: ReactNode }) { return newNodeId.current; } function save() { - let Saveflows = [...flows]; - if (Saveflows.length !== 0) { + // added clone deep to avoid mutating the original object + let Saveflows = _.cloneDeep(flows); + if (Saveflows.length !== 0){ Saveflows.forEach((flow) => { - if (flow.data && flow.data?.nodes) - flow.data?.nodes.forEach((node) => { - Object.keys(node.data.node.template).forEach((key) => { - if (node.data.node.template[key].type === "file") { - // ! Commenting this out for now, as it is causing issues with the file upload - // node.data.node.template[key].content = ""; - } - }); - }); - }); + if(flow.data && flow.data?.nodes) flow.data?.nodes.forEach((node) => { + console.log(node.data.type) + //looking for file fields to prevent saving the content and breaking the flow for exceeding the the data limite for local storage + Object.keys(node.data.node.template).forEach((key) => { + console.log(node.data.node.template[key].type) + if(node.data.node.template[key].type==="file"){ + console.log(node.data.node.template[key]) + node.data.node.template[key].content = null; + node.data.node.template[key].value = ""; + + } + }) + }) + }) window.localStorage.setItem( - "tabsData", - JSON.stringify({ tabIndex, flows: Saveflows, id }) - ); + "tabsData", + JSON.stringify({ tabIndex, flows:Saveflows, id}) + ); } - } + } useEffect(() => { //save tabs locally save();