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

Bug fix in update selector func #152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

flamingoalexander
Copy link
Contributor

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

Copy link
Member

@mxsnq mxsnq left a 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()) {
Copy link
Member

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.

Comment on lines +160 to +169
//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;
Copy link
Member

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.

@mxsnq mxsnq mentioned this pull request Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants