diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index 4daac7b71..a5e3aead6 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -25,6 +25,7 @@ import { const uid = new ShortUniqueId({ length: 5 }); const TabsContextInitialValue: TabsContextType = { + save: () => {}, tabId: "", setTabId: (index: string) => {}, flows: [], @@ -69,6 +70,32 @@ export function TabsProvider({ children }: { children: ReactNode }) { return newNodeId.current; } + function save() { + // 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) => { + // 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({ tabId, flows: Saveflows, id }) + ); + } + } + // function loadCookie(cookie: string) { // if (cookie && Object.keys(templates).length > 0) { // let cookieObject: LangFlowState = JSON.parse(cookie); @@ -543,6 +570,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { tabId, setTabId, flows, + save, incrementNodeId, removeFlow, addFlow,