From 7789948c332bb4809ac300963aa3f2c611528bee Mon Sep 17 00:00:00 2001 From: Alexander Vokin Date: Mon, 8 Jul 2024 13:58:38 +0800 Subject: [PATCH] creating a copy of the child selectors and adding them as children to the new parent --- src/scripts/Sitemap.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/scripts/Sitemap.js b/src/scripts/Sitemap.js index d71a9d6..74895d3 100644 --- a/src/scripts/Sitemap.js +++ b/src/scripts/Sitemap.js @@ -155,10 +155,20 @@ export default class Sitemap { updateSelector(selector, selectorData) { // selector is undefined when creating a new one and delete old one, if it exist if (selector === undefined || selector.type !== selectorData.type) { + var CanHaveChilds = selector.canHaveChildSelectors() if (selector) { + if (CanHaveChilds) { + var CopyOfChilds = this.selectors.filter(selectorFromList => + selectorFromList.parentSelectors.includes(selector.uuid)).map(obj => JSON.parse(JSON.stringify(obj))); + CopyOfChilds.forEach(child => child.parentSelectors.splice(child.parentSelectors.indexOf(selector.uuid), 1)) //delete old parent + } this.deleteSelector(selector); } selector = SelectorList.createSelector(selectorData); + if (CanHaveChilds){ //Since deleteSelector() also deletes all child selectors, a copy of those selectors is created and assigned to a new parent + CopyOfChilds.forEach(child => child.parentSelectors.push(selector.uuid)) + CopyOfChilds.forEach(child => this.selectors.push(child)) + } } // update child selectors