Pārlūkot izejas kodu

convert object values to string

AykutSarac 3 gadi atpakaļ
vecāks
revīzija
b3f2de325b
1 mainītis faili ar 15 papildinājumiem un 2 dzēšanām
  1. 15 2
      src/containers/LiveEditor/helpers.ts

+ 15 - 2
src/containers/LiveEditor/helpers.ts

@@ -1,6 +1,19 @@
 import { CanvasDirection, NodeData, EdgeData } from "reaflow";
 import { parser } from "src/utils/json-editor-parser";
 
+const toString = (value: string | object) => {
+  const isObject = value instanceof Object;
+
+  if (isObject) {
+    const entries = Object.entries(value);
+    const stringObj = entries.map((val) => [val[0], String(val[1])]);
+
+    return Object.fromEntries(stringObj);
+  }
+
+  return String(value);
+};
+
 export function getEdgeNodes(graph: any, isExpanded: boolean = true): any {
   graph = JSON.parse(graph);
   const elements = parser(graph);
@@ -21,7 +34,7 @@ export function getEdgeNodes(graph: any, isExpanded: boolean = true): any {
 
       nodes.push({
         id: el.id,
-        text: el.text,
+        text: toString(el.text),
         data: {
           isParent: el.parent,
         },
@@ -65,7 +78,7 @@ function renderText(value: string | object) {
     }
 
     entries.forEach((entry) => {
-      temp += `${entry[0]}: ${entry[1]}\n`;
+      temp += `${entry[0]}: ${String(entry[1])}\n`;
     });
 
     return temp;