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 8 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

src/scripts/Sitemap.js Outdated Show resolved Hide resolved
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can try to simplify this, after the main part of the logic is approved.

@mxsnq mxsnq mentioned this pull request Jan 16, 2025
Comment on lines 1393 to 1424
if (selector.canHaveChildSelectors()) {
const children = sitemap.selectors.filter(selectorFromList =>
selectorFromList.parentSelectors.includes(selector.uuid)
);
if (children.length > 0) {
this.initConfirmActionPanel({ action: 'update_selector' });
if (newSelector.canHaveChildSelectors()) {
const saveSelectorsBtn = $('<button/>', {
class: 'btn btn-primary',
id: 'modal-save-child-selectors',
text: Translator.getTranslationByKey(
'modal_confirm_action_submit_update_save_selector'
),
});
$('.modal-footer').append(saveSelectorsBtn);
$('#modal-title').text(
Translator.getTranslationByKey(
'modal_confirm_action_title_update_selector_can_have_child'
)
);
}
$('#modal-child-count').text(children.length);
$('#modal-message').after('<ul id="list-deleted-children"></ul>');
children.forEach(child => {
const $child = $('<li></li>');
$child.text(`#${child.uuid} ${child.id}`);
$('#list-deleted-children').append($child);
});
$('#modal-message').show();
return true;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the price of a new modal window, although the user will rarely see it.

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.

merge master into your branch

@@ -1401,7 +1407,38 @@ export default class SitemapController {
const newSelector = this.getCurrentlyEditedSelector();
const validator = this.getFormValidator();
validator.revalidateField('id');
// cancel submit if invalid form
if (selector.type !== newSelector.type) {
Copy link
Member

Choose a reason for hiding this comment

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

Modal init should be after form validation and removeCurrentContentSelector call, otherwise it is possible to create invalid selector

Comment on lines +1431 to +1438
$('#modal-child-count').text(children.length);
$('#modal-message').after('<ul id="list-deleted-children"></ul>');
children.forEach(child => {
const $child = $('<li></li>');
$child.text(`#${child.uuid} ${child.id}`);
$('#list-deleted-children').append($child);
});
$('#modal-message').show();
Copy link
Member

Choose a reason for hiding this comment

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

extract duplicated code into method

Comment on lines +1452 to +1453
}
async updateSelector(saveChildSelectors = false) {
Copy link
Member

Choose a reason for hiding this comment

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

add newlines between methods

@@ -152,13 +152,32 @@ export default class Sitemap {
return urls;
}

updateSelector(selector, selectorData) {
updateSelector(selector, selectorData, saveChildSelectors = false) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't like that the signature suggests children may be deleted even if selector type is not changed. We can think of another naming here (e.g. saveChildrenForNewType?), or implement deliberate removal - maybe it will simplify the code.

@@ -355,13 +355,25 @@
"modal_confirm_action_title_delete_selector": {
"message": "Are you sure you want to delete selector <span id='modal-selector-id'></span>?"
},
"modal_confirm_action_title_update_selector": {
"message": "The new selector type does not support additional selectors. Remove additional child selectors?"
Copy link
Member

Choose a reason for hiding this comment

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

why "additional"?

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