Skip to content

Commit

Permalink
Merge pull request #259 from HCL-TECH-SOFTWARE/task/MXOP-21208-resolv…
Browse files Browse the repository at this point in the history
…e-source-errors

Resolve Remove and Edit issues in Source tab
  • Loading branch information
rwilkins108 authored Nov 20, 2024
2 parents ecb598d + 5ec5f45 commit 3888263
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/components/forms/FormsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ const FormsContainer = () => {

const editorRef = useRef<any>(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(
Expand Down
33 changes: 27 additions & 6 deletions src/components/lit-elements/lit-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class SourceTree extends LitElement {
Duplicate
<sl-icon slot="prefix" src="${IMG_DIR}/shoelace/copy.svg"></sl-icon>
</sl-menu-item>
<sl-menu-item @click="${() => this.handleClickRemove(key, this.editedContent)}">
<sl-menu-item @click="${() => this.handleClickRemove(key, this.editedContent, fullPath)}">
Remove
<sl-icon slot="prefix" src="${IMG_DIR}/shoelace/trash.svg"></sl-icon>
</sl-menu-item>
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3888263

Please sign in to comment.