From 9ad8b72b83ee61adb9633cbe4363fa1b6ca07f1a Mon Sep 17 00:00:00 2001 From: Arpit Date: Fri, 7 Apr 2023 16:30:50 +0530 Subject: [PATCH] Improvement - handle resolved data structures from pyproxies (#5904) * handle resolved data structures from pyproxies * removes console.log --- frontend/src/_helpers/appUtils.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/src/_helpers/appUtils.js b/frontend/src/_helpers/appUtils.js index f660f9a375..8dc4c9d987 100644 --- a/frontend/src/_helpers/appUtils.js +++ b/frontend/src/_helpers/appUtils.js @@ -152,7 +152,7 @@ async function executeRunPycode(_ref, code, query, editorState, isPreview, mode) }; } - return pyodide.isPyProxy(result) ? result.toJs() : result; + return pyodide.isPyProxy(result) ? convertMapSet(result.toJs()) : result; }; return { data: await evaluatePythonCode(pyodide, code) }; @@ -1592,3 +1592,17 @@ const getSelectedText = () => { navigator.clipboard.writeText(window.document.selection.createRange().text); } }; + +function convertMapSet(obj) { + if (obj instanceof Map) { + return Object.fromEntries(Array.from(obj, ([key, value]) => [key, convertMapSet(value)])); + } else if (obj instanceof Set) { + return Array.from(obj).map(convertMapSet); + } else if (Array.isArray(obj)) { + return obj.map(convertMapSet); + } else if (obj !== null && typeof obj === 'object') { + return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, convertMapSet(value)])); + } else { + return obj; + } +}