fix: updateObject order was incorrect

Fixes Tool nodes are not loaded correctly. #228
This commit is contained in:
Gabriel Almeida 2023-05-02 17:24:08 -03:00
commit e27f6d5d7d

View file

@ -12,7 +12,7 @@ import { normalCaseToSnakeCase, updateObject } from "../utils";
import { alertContext } from "./alertContext"; import { alertContext } from "./alertContext";
import { typesContext } from "./typesContext"; import { typesContext } from "./typesContext";
import { TemplateVariableType } from "../types/api"; import { TemplateVariableType } from "../types/api";
const { v4: uuidv4 } = require('uuid'); const { v4: uuidv4 } = require("uuid");
const TabsContextInitialValue: TabsContextType = { const TabsContextInitialValue: TabsContextType = {
save: () => {}, save: () => {},
@ -63,12 +63,13 @@ export function TabsProvider({ children }: { children: ReactNode }) {
let cookieObject: LangFlowState = JSON.parse(cookie); let cookieObject: LangFlowState = JSON.parse(cookie);
cookieObject.flows.forEach((flow) => { cookieObject.flows.forEach((flow) => {
flow.data.nodes.forEach((node) => { flow.data.nodes.forEach((node) => {
if (Object.keys(templates[node.data.type]["template"]).length>0) { if (Object.keys(templates[node.data.type]["template"]).length > 0) {
node.data.node.template = updateObject( node.data.node.template = updateObject(
node.data.node.template as TemplateVariableType,
templates[node.data.type][ templates[node.data.type][
"template" "template"
] as unknown as TemplateVariableType ] as unknown as TemplateVariableType,
node.data.node.template as TemplateVariableType
); );
} }
}); });
@ -127,12 +128,12 @@ export function TabsProvider({ children }: { children: ReactNode }) {
// parse the text into a JSON object // parse the text into a JSON object
let flow: FlowType = JSON.parse(text); let flow: FlowType = JSON.parse(text);
flow.data.nodes.forEach((node) => { flow.data.nodes.forEach((node) => {
if (Object.keys(templates[node.data.type]["template"]).length>0) { if (Object.keys(templates[node.data.type]["template"]).length > 0) {
node.data.node.template = updateObject( node.data.node.template = updateObject(
node.data.node.template as TemplateVariableType,
templates[node.data.type][ templates[node.data.type][
"template" "template"
] as unknown as TemplateVariableType ] as unknown as TemplateVariableType,
node.data.node.template as TemplateVariableType
); );
} }
}); });