Fixed tag deletion

no issue

- don't show "Delete tag" button when we're displaying a new/unsaved tag
- refactor the `_deleteTag()` method to be more explicit and remove handling that is no longer required since the tag screen is not nested in the tags screen
- revised the condition in `showUnsavedChangesModal()` method so that it's body doesn't fire twice when leaving the `tag` or `tag.new` route
- revised the `showUnsavedChangesModal()` method body to look at the number of changed properties on the tag rather than relying on `tag.hasChangedAttributes` which is always `true` for new models
This commit is contained in:
Kevin Ansfield 2019-12-10 12:18:20 +00:00
parent 4496ea41c4
commit c53e4f9cd7
3 changed files with 12 additions and 23 deletions

View File

@ -126,24 +126,10 @@ export default Controller.extend({
}),
_deleteTag() {
let tag = this.tag;
return tag.destroyRecord().then(() => {
this._deleteTagSuccess();
return this.tag.destroyRecord().then(() => {
return this.transitionToRoute('tags');
}, (error) => {
this._deleteTagFailure(error);
return this.notifications.showAPIError(error, {key: 'tag.delete'});
});
},
_deleteTagSuccess() {
let currentRoute = this.router.currentRouteName || '';
if (currentRoute.match(/^tags/)) {
this.transitionToRoute('tags');
}
},
_deleteTagFailure(error) {
this.notifications.showAPIError(error, {key: 'tag.delete'});
}
});

View File

@ -38,15 +38,15 @@ export default AuthenticatedRoute.extend(CurrentUserSettings, {
},
showUnsavedChangesModal(transition) {
if (transition.from && transition.from.name.match(/^tag$|^tag\.new$/) && transition.targetName) {
if (transition.from && transition.from.name === this.routeName && transition.targetName) {
let {controller} = this;
if (!controller.tag.isDeleted && controller.tag.hasDirtyAttributes) {
// tag.changedAttributes is always true for new tags but number of changed attrs is reliable
if (!controller.tag.isDeleted && Object.keys(controller.tag.changedAttributes()).length > 0) {
transition.abort();
controller.send('toggleUnsavedChangesModal', transition);
return;
}
}
}
});

View File

@ -14,9 +14,12 @@
setProperty=(action "setProperty")
showDeleteTagModal=(action "toggleDeleteTagModal")}}
</form>
{{#unless this.tag.isNew}}
<button class="gh-btn gh-btn-red gh-btn-icon mb15" {{action "toggleDeleteTagModal"}}>
<span>Delete tag</span>
</button>
{{/unless}}
</section>
{{#if showUnsavedChangesModal}}