new save function to prevent break with large files

This commit is contained in:
anovazzi1 2023-05-30 00:40:50 -03:00
commit 82a8b633a6

View file

@ -19,6 +19,7 @@ import { typesContext } from "./typesContext";
import { APITemplateType, TemplateVariableType } from "../types/api"; import { APITemplateType, TemplateVariableType } from "../types/api";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import { addEdge } from "reactflow"; import { addEdge } from "reactflow";
import _ from "lodash";
const TabsContextInitialValue: TabsContextType = { const TabsContextInitialValue: TabsContextType = {
save: () => {}, save: () => {},
@ -58,25 +59,30 @@ export function TabsProvider({ children }: { children: ReactNode }) {
return newNodeId.current; return newNodeId.current;
} }
function save() { function save() {
let Saveflows = [...flows]; // added clone deep to avoid mutating the original object
if (Saveflows.length !== 0) { let Saveflows = _.cloneDeep(flows);
if (Saveflows.length !== 0){
Saveflows.forEach((flow) => { Saveflows.forEach((flow) => {
if (flow.data && flow.data?.nodes) if(flow.data && flow.data?.nodes) flow.data?.nodes.forEach((node) => {
flow.data?.nodes.forEach((node) => { console.log(node.data.type)
Object.keys(node.data.node.template).forEach((key) => { //looking for file fields to prevent saving the content and breaking the flow for exceeding the the data limite for local storage
if (node.data.node.template[key].type === "file") { Object.keys(node.data.node.template).forEach((key) => {
// ! Commenting this out for now, as it is causing issues with the file upload console.log(node.data.node.template[key].type)
// node.data.node.template[key].content = ""; 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( window.localStorage.setItem(
"tabsData", "tabsData",
JSON.stringify({ tabIndex, flows: Saveflows, id }) JSON.stringify({ tabIndex, flows:Saveflows, id})
); );
} }
} }
useEffect(() => { useEffect(() => {
//save tabs locally //save tabs locally
save(); save();