added clone deep to saveFlow
This commit is contained in:
parent
7e8eea5e87
commit
af2a8b743e
1 changed files with 9 additions and 6 deletions
|
|
@ -14,6 +14,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: () => {},
|
||||||
|
|
@ -50,7 +51,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
return newNodeId.current;
|
return newNodeId.current;
|
||||||
}
|
}
|
||||||
function save() {
|
function save() {
|
||||||
let Saveflows = [...flows];
|
let Saveflows = _.cloneDeep(flows);
|
||||||
if (Saveflows.length !== 0)
|
if (Saveflows.length !== 0)
|
||||||
Saveflows.forEach((flow) => {
|
Saveflows.forEach((flow) => {
|
||||||
if(flow.data && flow.data?.nodes) flow.data?.nodes.forEach((node) => {
|
if(flow.data && flow.data?.nodes) flow.data?.nodes.forEach((node) => {
|
||||||
|
|
@ -69,15 +70,11 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
JSON.stringify({ tabIndex, flows:Saveflows, id})
|
JSON.stringify({ tabIndex, flows:Saveflows, id})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
|
||||||
//save tabs locally
|
|
||||||
// console.log(id)
|
|
||||||
save();
|
|
||||||
}, [flows, id, tabIndex, newNodeId]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
//get tabs locally saved
|
//get tabs locally saved
|
||||||
let cookie = window.localStorage.getItem("tabsData");
|
let cookie = window.localStorage.getItem("tabsData");
|
||||||
|
console.log(cookie)
|
||||||
if (cookie && Object.keys(templates).length > 0) {
|
if (cookie && Object.keys(templates).length > 0) {
|
||||||
let cookieObject: LangFlowState = JSON.parse(cookie);
|
let cookieObject: LangFlowState = JSON.parse(cookie);
|
||||||
cookieObject.flows.forEach((flow) => {
|
cookieObject.flows.forEach((flow) => {
|
||||||
|
|
@ -99,6 +96,12 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
}
|
}
|
||||||
}, [templates]);
|
}, [templates]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
//save tabs locally
|
||||||
|
console.log(id)
|
||||||
|
save();
|
||||||
|
}, [flows, id, tabIndex, newNodeId]);
|
||||||
|
|
||||||
function hardReset() {
|
function hardReset() {
|
||||||
newNodeId.current = uuidv4();
|
newNodeId.current = uuidv4();
|
||||||
setTabIndex(0);
|
setTabIndex(0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue