From 76def20d86f0a774caee2b74a3fe61489eb797c0 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Wed, 27 Sep 2023 10:19:49 -0300 Subject: [PATCH] fix bug when object comes as a string from backend --- .../src/CustomNodes/GenericNode/index.tsx | 1 - src/frontend/src/utils/reactflowUtils.ts | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/index.tsx b/src/frontend/src/CustomNodes/GenericNode/index.tsx index 5f3a99d47..524b54ead 100644 --- a/src/frontend/src/CustomNodes/GenericNode/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/index.tsx @@ -107,7 +107,6 @@ export default function GenericNode({ setValidationStatus(null); } }, [sseData, data.id]); - return ( <> diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index a9b157c66..4b431cb22 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -311,15 +311,20 @@ export function getConnectedNodes( return nodes.filter((node) => node.id === targetId || node.id === sourceId); } -export function convertObjToArray(singleObject) { +export function convertObjToArray(singleObject: object | string) { + if (typeof singleObject === "string") { + singleObject = JSON.parse(singleObject); + } if (Array.isArray(singleObject)) return singleObject; - let arrConverted: any = []; - for (const key in singleObject) { - if (singleObject.hasOwnProperty(key)) { - const newObj = {}; - newObj[key] = singleObject[key]; - arrConverted.push(newObj); + let arrConverted: any[] = []; + if (typeof singleObject === "object") { + for (const key in singleObject) { + if (Object.prototype.hasOwnProperty.call(singleObject, key)) { + const newObj = {}; + newObj[key] = singleObject[key]; + arrConverted.push(newObj); + } } } return arrConverted;