-
Notifications
You must be signed in to change notification settings - Fork 70
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
Bug fix in update selector func #152
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe not all selector types with children are interchangeable. For example, children of elements and links are applied to different pages so they are not compatible.
Ideally, I'd suggest to implement update confirmation window for such cases, similar to one that pops up when deleting selector, with options to delete children or not
@@ -156,9 +156,24 @@ export default class Sitemap { | |||
// selector is undefined when creating a new one and delete old one, if it exist | |||
if (selector === undefined || selector.type !== selectorData.type) { | |||
if (selector) { | |||
this.deleteSelector(selector); | |||
if (selector.canHaveChildSelectors()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This retains children even if new type does not support them. You should check that selectorData (or both of them) can have children.
//custom logic: we don’t delete children, but redefined them a parent | ||
const children = this.selectors.filter(selectorFromList => | ||
selectorFromList.parentSelectors.includes(selector.uuid) | ||
); | ||
const newSelector = SelectorList.createSelector(selectorData); | ||
children.forEach(child => { | ||
const parentUuidIndex = child.parentSelectors.indexOf(selector.uuid); | ||
child.parentSelectors[parentUuidIndex] = newSelector.uuid; | ||
}); | ||
selector = newSelector; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar logic is present below in // update child selectors
section, maybe it is possible to simplify it. Also I'm not sure if it is even possible to receive different selector uids here when we update existing selector.
Bug fix for a situation when we change the selector type, but its children are removed even if the new selector type supports child selectors