From af2a8b743e529a5c06d024bbce21ac569b7f6233 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Sun, 28 May 2023 10:34:39 -0300 Subject: [PATCH 1/3] added clone deep to saveFlow --- src/frontend/src/contexts/tabsContext.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index f34e1bc7a..f6b62a2b3 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -14,6 +14,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: () => {}, @@ -50,7 +51,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { return newNodeId.current; } function save() { - let Saveflows = [...flows]; + let Saveflows = _.cloneDeep(flows); if (Saveflows.length !== 0) Saveflows.forEach((flow) => { 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}) ); } - useEffect(() => { - //save tabs locally - // console.log(id) - save(); - }, [flows, id, tabIndex, newNodeId]); useEffect(() => { //get tabs locally saved let cookie = window.localStorage.getItem("tabsData"); + console.log(cookie) if (cookie && Object.keys(templates).length > 0) { let cookieObject: LangFlowState = JSON.parse(cookie); cookieObject.flows.forEach((flow) => { @@ -99,6 +96,12 @@ export function TabsProvider({ children }: { children: ReactNode }) { } }, [templates]); + useEffect(() => { + //save tabs locally + console.log(id) + save(); + }, [flows, id, tabIndex, newNodeId]); + function hardReset() { newNodeId.current = uuidv4(); setTabIndex(0); From 129088d61ee7c475281669fce20311731ed1e12d Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Sun, 28 May 2023 10:49:23 -0300 Subject: [PATCH 2/3] hotfix for file nodes and save on localStorage --- .../src/CustomNodes/GenericNode/index.tsx | 1 + src/frontend/src/contexts/tabsContext.tsx | 34 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/index.tsx b/src/frontend/src/CustomNodes/GenericNode/index.tsx index 059fdfb81..8005a8a30 100644 --- a/src/frontend/src/CustomNodes/GenericNode/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/index.tsx @@ -86,6 +86,7 @@ export default function GenericNode({ deleteNode(data.id); return; } + console.log(data) return (
{ - if(flow.data && flow.data?.nodes) flow.data?.nodes.forEach((node) => { - console.log(node.data.type) - 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 = ""; - } - }) - }) - }) - window.localStorage.setItem( + 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({ tabIndex, flows:Saveflows, id}) ); + } } useEffect(() => { //get tabs locally saved let cookie = window.localStorage.getItem("tabsData"); - console.log(cookie) if (cookie && Object.keys(templates).length > 0) { let cookieObject: LangFlowState = JSON.parse(cookie); cookieObject.flows.forEach((flow) => { From c4159f3af40322a144c1dff0d13a925538f9e371 Mon Sep 17 00:00:00 2001 From: Gabriel Almeida Date: Sun, 28 May 2023 11:55:00 -0300 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=9B=20fix(utilities.py):=20use=20a?= =?UTF-8?q?st.literal=5Feval=20instead=20of=20eval=20to=20improve=20securi?= =?UTF-8?q?ty=20=F0=9F=90=9B=20fix(GenericNode):=20add=20semicolon=20to=20?= =?UTF-8?q?console.log=20statement=20The=20use=20of=20eval=20in=20the=20co?= =?UTF-8?q?de=20can=20be=20a=20security=20risk=20as=20it=20can=20execute?= =?UTF-8?q?=20arbitrary=20code.=20Using=20ast.literal=5Feval=20instead=20o?= =?UTF-8?q?f=20eval=20is=20a=20safer=20alternative=20as=20it=20only=20eval?= =?UTF-8?q?uates=20a=20subset=20of=20Python=20expressions.=20The=20semicol?= =?UTF-8?q?on=20was=20added=20to=20the=20console.log=20statement=20to=20im?= =?UTF-8?q?prove=20code=20consistency.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/template/frontend_node/utilities.py | 3 ++- src/frontend/src/CustomNodes/GenericNode/index.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/template/frontend_node/utilities.py b/src/backend/langflow/template/frontend_node/utilities.py index 77d01a23e..615d7d12f 100644 --- a/src/backend/langflow/template/frontend_node/utilities.py +++ b/src/backend/langflow/template/frontend_node/utilities.py @@ -1,3 +1,4 @@ +import ast import json from typing import Optional @@ -12,7 +13,7 @@ class UtilitiesFrontendNode(FrontendNode): # field.field_type could be "Literal['news', 'search', 'places', 'images'] # we need to convert it to a list if "Literal" in field.field_type: - field.options = eval(field.field_type.replace("Literal", "")) + field.options = ast.literal_eval(field.field_type.replace("Literal", "")) field.is_list = True field.field_type = "str" diff --git a/src/frontend/src/CustomNodes/GenericNode/index.tsx b/src/frontend/src/CustomNodes/GenericNode/index.tsx index 3409f8d9e..1427d1a76 100644 --- a/src/frontend/src/CustomNodes/GenericNode/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/index.tsx @@ -85,7 +85,7 @@ export default function GenericNode({ deleteNode(data.id); return; } - console.log(data) + console.log(data); return (