Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes in updateSelector() #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/scripts/Sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert the first letter to lowercase to match the camelCase
And use let or const instead of var (https://skillbox.ru/media/code/chem_razlichayutsya_var_let_i_const_v_javascript/)

if (selector) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest change this block of code (to the line 172) and move some of its parts into a separate method that will receive the ID of the old and new selectors as input, and then replace the ID of the old selector with the ID of the new selector in all direct child selectors

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
Expand Down