diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx
index 5be56e31c..3bb92d34e 100644
--- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx
+++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx
@@ -27,8 +27,6 @@ import { typesContext } from "../../../../contexts/typesContext";
import { ParameterComponentType } from "../../../../types/components";
import { TabsState } from "../../../../types/tabs";
import {
- convertArrayToObj,
- convertObjToArray,
hasDuplicateKeys,
isValidConnection,
} from "../../../../utils/reactflowUtils";
@@ -113,10 +111,9 @@ export default function ParameterComponent({
});
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
- const [dict, setDict] = useState({
- yourKey: "yourValue",
- } as {});
- const [dictArr, setDictArr] = useState([] as string[]);
+ const [dictArr, setDictArr] = useState([
+ { yourKey: "yourValue" },
+ ] as Object[]);
useEffect(() => {
if (name === "openai_api_base") console.log(info);
@@ -384,18 +381,21 @@ export default function ParameterComponent({
disabled={disabled}
editNode={false}
value={
- convertObjToArray(data.node!.template[name].value).length === 0
- ? convertObjToArray(dict)
- : convertObjToArray(data.node!.template[name].value)
+ data.node!.template[name].value?.length === 0 ||
+ !data.node!.template[name].value
+ ? dictArr
+ : data.node!.template[name].value
}
duplicateKey={errorDuplicateKey}
- onChange={(newValue: string[]) => {
+ onChange={(newValue) => {
setErrorDuplicateKey(hasDuplicateKeys(newValue));
if (hasDuplicateKeys(newValue)) {
setDictArr(newValue);
} else {
- setDict(convertArrayToObj(newValue));
- data.node!.template[name].value = convertArrayToObj(newValue);
+ setDictArr(newValue);
+ console.log(newValue);
+
+ data.node!.template[name].value = newValue;
}
}}
/>
diff --git a/src/frontend/src/components/keypairListComponent/index.tsx b/src/frontend/src/components/keypairListComponent/index.tsx
index f33c3aa2b..580de2cfd 100644
--- a/src/frontend/src/components/keypairListComponent/index.tsx
+++ b/src/frontend/src/components/keypairListComponent/index.tsx
@@ -37,11 +37,11 @@ export default function KeypairListComponent({
return (
1 && editNode ? "my-1" : "",
+ value?.length > 1 && editNode ? "my-1" : "",
"flex flex-col gap-3"
)}
>
- {value.map((obj, index) => {
+ {value?.map((obj, index) => {
return Object.keys(obj).map((key, idx) => {
return (
diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx
index abc9e0aff..390904ef4 100644
--- a/src/frontend/src/modals/EditNodeModal/index.tsx
+++ b/src/frontend/src/modals/EditNodeModal/index.tsx
@@ -28,11 +28,7 @@ import { TabsContext } from "../../contexts/tabsContext";
import { typesContext } from "../../contexts/typesContext";
import { NodeDataType } from "../../types/flow";
import { TabsState } from "../../types/tabs";
-import {
- convertArrayToObj,
- convertObjToArray,
- hasDuplicateKeys,
-} from "../../utils/reactflowUtils";
+import { hasDuplicateKeys } from "../../utils/reactflowUtils";
import { classNames } from "../../utils/utils";
import BaseModal from "../baseModal";
@@ -100,14 +96,9 @@ const EditNodeModal = forwardRef(
});
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
- const [dict, setDict] = useState({
- yourKey: "yourValue",
- } as {});
- const [dictArr, setDictArr] = useState([] as string[]);
-
- useEffect(() => {
- setDictArr(convertObjToArray(dict));
- }, [dict]);
+ const [dictArr, setDictArr] = useState([
+ { yourKey: "yourValue" },
+ ] as Object[]);
return (
@@ -214,19 +205,29 @@ const EditNodeModal = forwardRef(
{
+ onChange={(newValue) => {
setErrorDuplicateKey(
hasDuplicateKeys(newValue)
);
if (hasDuplicateKeys(newValue)) {
setDictArr(newValue);
} else {
- setDict(
- convertArrayToObj(newValue)
- );
+ setDictArr(newValue);
+ myData.node!.template[
+ templateParam
+ ].value = newValue;
}
}}
/>
diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts
index e63a21482..3749a80c7 100644
--- a/src/frontend/src/types/components/index.ts
+++ b/src/frontend/src/types/components/index.ts
@@ -56,7 +56,7 @@ export type InputListComponentType = {
export type KeyPairListComponentType = {
value: any;
- onChange: (value: string[]) => void;
+ onChange: (value: Object[]) => void;
disabled: boolean;
editNode?: boolean;
duplicateKey?: boolean;
@@ -123,18 +123,18 @@ export type TooltipComponentType = {
children: ReactElement;
title: string | ReactElement;
placement?:
- | "bottom-end"
- | "bottom-start"
- | "bottom"
- | "left-end"
- | "left-start"
- | "left"
- | "right-end"
- | "right-start"
- | "right"
- | "top-end"
- | "top-start"
- | "top";
+ | "bottom-end"
+ | "bottom-start"
+ | "bottom"
+ | "left-end"
+ | "left-start"
+ | "left"
+ | "right-end"
+ | "right-start"
+ | "right"
+ | "top-end"
+ | "top-start"
+ | "top";
};
export type ProgressBarType = {
diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts
index 250ce4054..07f289132 100644
--- a/src/frontend/src/utils/reactflowUtils.ts
+++ b/src/frontend/src/utils/reactflowUtils.ts
@@ -298,23 +298,9 @@ export function convertObjToArray(singleObject) {
arrConverted.push(newObj);
}
}
-
return arrConverted;
}
-export function convertArrayToObj(newValue) {
- const flattenedObject = {};
- for (const obj of newValue) {
- for (const key in obj) {
- if (obj.hasOwnProperty(key)) {
- flattenedObject[key] = obj[key]; //added space to dont order when add new keys to object
- }
- }
- }
- let newData = _.cloneDeep(flattenedObject);
- return newData;
-}
-
export function hasDuplicateKeys(array) {
const keys = {};
for (const obj of array) {