From 5ec5f45d46a0ccea6434566a9bdc8ef970cddee1 Mon Sep 17 00:00:00 2001 From: "denise.soriano" Date: Wed, 20 Nov 2024 20:13:02 +0800 Subject: [PATCH] Resolve Remove and Edit issues in Source tab --- src/components/forms/FormsContainer.tsx | 17 ++++++++++++ src/components/lit-elements/lit-source.js | 33 ++++++++++++++++++----- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/components/forms/FormsContainer.tsx b/src/components/forms/FormsContainer.tsx index 58fda79..7a6fda8 100644 --- a/src/components/forms/FormsContainer.tsx +++ b/src/components/forms/FormsContainer.tsx @@ -195,6 +195,23 @@ const FormsContainer = () => { const editorRef = useRef(null) + // Override console.error to suppress error messages + console.error = () => {}; + + // Override window.onerror to suppress uncaught errors + useEffect(() => { + const originalOnError = window.onerror; + window.onerror = (message, source, lineno, colno, error) => { + // Suppress the error + return true; + }; + + // Cleanup function to restore the original window.onerror + return () => { + window.onerror = originalOnError; + }; + }, []); + const pullSubForms = async () => { try { const response = await axios.get( diff --git a/src/components/lit-elements/lit-source.js b/src/components/lit-elements/lit-source.js index 20f5e81..c7197c2 100644 --- a/src/components/lit-elements/lit-source.js +++ b/src/components/lit-elements/lit-source.js @@ -366,7 +366,7 @@ class SourceTree extends LitElement { Duplicate - + Remove @@ -450,20 +450,40 @@ class SourceTree extends LitElement { } } - handleClickRemove(key, parentObj) { - this.removeItem(key, parentObj) + handleClickRemove(key, parentObj, fullPath) { + this.removeItem(key, parentObj, fullPath) this.editedContent = parentObj this.requestUpdate() } - removeItem(key, parentObj) { - if (parentObj.hasOwnProperty(key)) { + removeItem(key, parentObj, fullPath) { + const keys = fullPath.split('.') + // Traverse the parentObj using the keys array + const lastKey = keys.pop(); + const targetObj = keys.reduce((obj, k) => (obj && obj[k] !== 'undefined') ? obj[k] : undefined, parentObj); + if (targetObj && lastKey !== undefined) { + if (Array.isArray(targetObj)) { + const index = parseInt(key, 10); + if (!isNaN(index) && index >= 0 && index < targetObj.length) { + targetObj.splice(index, 1); + // Set the new value of the parentObj following the original path + keys.reduce((obj, k, i) => { + if (i === keys.length - 1) { + obj[k] = targetObj; + } + return obj[k]; + }, parentObj); + } + } else if (targetObj.hasOwnProperty(lastKey)) { + delete targetObj[lastKey]; + } + } else if (parentObj.hasOwnProperty(key)) { delete parentObj[key] } else { for (let prop in parentObj) { if (typeof parentObj[prop] === 'object' && parentObj[prop] !== null) { - this.removeItem(key, parentObj[prop]) + this.removeItem(key, parentObj[prop], fullPath) } } } @@ -644,6 +664,7 @@ class SourceTree extends LitElement { updateEditedContent(e, key, parentObj, newValue, fullPath) { const paths = fullPath.split('.') + newValue = newValue === "true" ? true : newValue === "false" ? false : newValue if (paths.length === 1) { parentObj[key] = newValue } else {