diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 68c975764..6968d6472 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -424,9 +424,11 @@ export default function ParameterComponent({ disabled={disabled} editNode={false} value={ - data.node!.template[name].value ?? { - yourkey: "value", - } + data.node!.template[name].value.toString() === "{}" + ? { + yourkey: "value", + } + : data.node!.template[name].value } onChange={(newValue) => { data.node!.template[name].value = newValue; diff --git a/src/frontend/src/components/codeTabsComponent/index.tsx b/src/frontend/src/components/codeTabsComponent/index.tsx index 5500de48e..b304518c2 100644 --- a/src/frontend/src/components/codeTabsComponent/index.tsx +++ b/src/frontend/src/components/codeTabsComponent/index.tsx @@ -832,9 +832,15 @@ export default function CodeTabsComponent({ value={ node.data.node!.template[ templateField - ].value ?? { - yourkey: "value", - } + ].value.toString() === + "{}" + ? { + yourkey: "value", + } + : node.data.node! + .template[ + templateField + ].value } onChange={(target) => { setData((old) => { diff --git a/src/frontend/src/modals/ApiModal/index.tsx b/src/frontend/src/modals/ApiModal/index.tsx index 49962500a..35a8e2134 100644 --- a/src/frontend/src/modals/ApiModal/index.tsx +++ b/src/frontend/src/modals/ApiModal/index.tsx @@ -83,7 +83,7 @@ const ApiModal = forwardRef( filterNodes(); if (Object.keys(tweaksCode).length > 0) { - setActiveTab("0"); + // setActiveTab("0"); setTabs(tabsArray(codesArray, 1)); } else { setTabs(tabsArray(codesArray, 1)); @@ -137,6 +137,10 @@ const ApiModal = forwardRef( changes = convertArrayToObj(changes); } + if (template.type === "NestedDict") { + changes = JSON.stringify(changes); + } + const existingTweak = tweak.current.find((element) => element.hasOwnProperty(tw) ); diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx index fe1fe8f6d..be21feda9 100644 --- a/src/frontend/src/modals/EditNodeModal/index.tsx +++ b/src/frontend/src/modals/EditNodeModal/index.tsx @@ -1,5 +1,12 @@ import { cloneDeep } from "lodash"; -import { ReactNode, forwardRef, useContext, useEffect, useRef, useState } from "react"; +import { + ReactNode, + forwardRef, + useContext, + useEffect, + useRef, + useState, +} from "react"; import CodeAreaComponent from "../../components/codeAreaComponent"; import DictComponent from "../../components/dictComponent"; import Dropdown from "../../components/dropdownComponent"; @@ -59,7 +66,6 @@ const EditNodeModal = forwardRef( const myData = useRef(data); - const { setTabsState, tabId } = useContext(TabsContext); const { reactFlowInstance } = useContext(typesContext); let disabled = @@ -68,7 +74,8 @@ const EditNodeModal = forwardRef( .some((edge) => edge.targetHandle === data.id) ?? false; function changeAdvanced(n) { - myData.current.node!.template[n].advanced = !myData.current.node!.template[n].advanced; + myData.current.node!.template[n].advanced = + !myData.current.node!.template[n].advanced; } const handleOnNewValue = (newValue: any, name) => { @@ -76,7 +83,7 @@ const EditNodeModal = forwardRef( }; useEffect(() => { - myData.current = data // reset data to what it is on node when opening modal + myData.current = data; // reset data to what it is on node when opening modal onClose!(modalOpen); }, [modalOpen]); @@ -132,63 +139,71 @@ const EditNodeModal = forwardRef( (templateParam) => templateParam.charAt(0) !== "_" && myData.current.node?.template[templateParam].show && - (myData.current.node.template[templateParam].type === - "str" || - myData.current.node.template[templateParam].type === - "bool" || - myData.current.node.template[templateParam].type === - "float" || - myData.current.node.template[templateParam].type === - "code" || - myData.current.node.template[templateParam].type === - "prompt" || - myData.current.node.template[templateParam].type === - "file" || - myData.current.node.template[templateParam].type === - "int" || - myData.current.node.template[templateParam].type === - "dict" || - myData.current.node.template[templateParam].type === - "NestedDict") + (myData.current.node.template[templateParam] + .type === "str" || + myData.current.node.template[templateParam] + .type === "bool" || + myData.current.node.template[templateParam] + .type === "float" || + myData.current.node.template[templateParam] + .type === "code" || + myData.current.node.template[templateParam] + .type === "prompt" || + myData.current.node.template[templateParam] + .type === "file" || + myData.current.node.template[templateParam] + .type === "int" || + myData.current.node.template[templateParam] + .type === "dict" || + myData.current.node.template[templateParam] + .type === "NestedDict") ) .map((templateParam, index) => ( {myData.current.node?.template[templateParam].name - ? myData.current.node.template[templateParam].name + ? myData.current.node.template[templateParam] + .name : myData.current.node?.template[templateParam] .display_name} - {myData.current.node?.template[templateParam].type === - "str" && - !myData.current.node.template[templateParam].options ? ( + {myData.current.node?.template[templateParam] + .type === "str" && + !myData.current.node.template[templateParam] + .options ? (
- {myData.current.node.template[templateParam].list ? ( + {myData.current.node.template[templateParam] + .list ? ( { handleOnNewValue(value, templateParam); }} /> - ) : myData.current.node.template[templateParam] - .multiline ? ( + ) : myData.current.node.template[ + templateParam + ].multiline ? ( { handleOnNewValue(value, templateParam); @@ -199,12 +214,14 @@ const EditNodeModal = forwardRef( editNode={true} disabled={disabled} password={ - myData.current.node.template[templateParam] - .password ?? false + myData.current.node.template[ + templateParam + ].password ?? false } value={ - myData.current.node.template[templateParam] - .value ?? "" + myData.current.node.template[ + templateParam + ].value ?? "" } onChange={(value) => { handleOnNewValue(value, templateParam); @@ -212,17 +229,22 @@ const EditNodeModal = forwardRef( /> )}
- ) : myData.current.node?.template[templateParam].type === - "NestedDict" ? ( -
+ ) : myData.current.node?.template[templateParam] + .type === "NestedDict" ? ( +
{ myData.current.node!.template[ @@ -232,21 +254,24 @@ const EditNodeModal = forwardRef( }} />
- ) : myData.current.node?.template[templateParam].type === - "dict" ? ( + ) : myData.current.node?.template[templateParam] + .type === "dict" ? (
- ) : myData.current.node?.template[templateParam].type === - "bool" ? ( + ) : myData.current.node?.template[templateParam] + .type === "bool" ? (
{" "} { handleOnNewValue( @@ -284,76 +311,84 @@ const EditNodeModal = forwardRef( size="small" />
- ) : myData.current.node?.template[templateParam].type === - "float" ? ( + ) : myData.current.node?.template[templateParam] + .type === "float" ? (
{ handleOnNewValue(value, templateParam); }} />
- ) : myData.current.node?.template[templateParam].type === - "str" && - myData.current.node.template[templateParam].options ? ( + ) : myData.current.node?.template[templateParam] + .type === "str" && + myData.current.node.template[templateParam] + .options ? (
handleOnNewValue(value, templateParam) } value={ - myData.current.node.template[templateParam] - .value ?? "Choose an option" + myData.current.node.template[ + templateParam + ].value ?? "Choose an option" } >
- ) : myData.current.node?.template[templateParam].type === - "int" ? ( + ) : myData.current.node?.template[templateParam] + .type === "int" ? (
{ handleOnNewValue(value, templateParam); }} />
- ) : myData.current.node?.template[templateParam].type === - "file" ? ( + ) : myData.current.node?.template[templateParam] + .type === "file" ? (
{ handleOnNewValue(value, templateParam); }} fileTypes={ - myData.current.node.template[templateParam] - .fileTypes + myData.current.node.template[ + templateParam + ].fileTypes } suffixes={ - myData.current.node.template[templateParam] - .suffixes + myData.current.node.template[ + templateParam + ].suffixes } onFileChange={(filePath: string) => { data.node!.template[ @@ -362,8 +397,8 @@ const EditNodeModal = forwardRef( }} >
- ) : myData.current.node?.template[templateParam].type === - "prompt" ? ( + ) : myData.current.node?.template[templateParam] + .type === "prompt" ? (
{ handleOnNewValue(value, templateParam); }} />
- ) : myData.current.node?.template[templateParam].type === - "code" ? ( + ) : myData.current.node?.template[templateParam] + .type === "code" ? (
{ handleOnNewValue(value, templateParam); }} />
- ) : myData.current.node?.template[templateParam].type === - "Any" ? ( + ) : myData.current.node?.template[templateParam] + .type === "Any" ? ( "-" ) : (
@@ -416,13 +453,13 @@ const EditNodeModal = forwardRef(
{ - changeAdvanced(templateParam) - } + !myData.current.node?.template[ + templateParam + ].advanced } + setEnabled={(e) => { + changeAdvanced(templateParam); + }} disabled={disabled} size="small" />