-
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
//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.
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 can try to simplify this, after the main part of the logic is approved.
src/scripts/Controller.js
Outdated
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; | ||
} | ||
} |
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 is the price of a new modal window, although the user will rarely see it.
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.
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) { |
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.
Modal init should be after form validation and removeCurrentContentSelector call, otherwise it is possible to create invalid selector
$('#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(); |
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.
extract duplicated code into method
} | ||
async updateSelector(saveChildSelectors = false) { |
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.
add newlines between methods
@@ -152,13 +152,32 @@ export default class Sitemap { | |||
return urls; | |||
} | |||
|
|||
updateSelector(selector, selectorData) { | |||
updateSelector(selector, selectorData, saveChildSelectors = false) { |
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 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?" |
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.
why "additional"?
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