From c53e4f9cd733ffc80c58bb12cc34b26c773e1290 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 10 Dec 2019 12:18:20 +0000 Subject: [PATCH] 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 --- ghost/admin/app/controllers/tag.js | 20 +++----------------- ghost/admin/app/routes/tag.js | 6 +++--- ghost/admin/app/templates/tag.hbs | 9 ++++++--- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/ghost/admin/app/controllers/tag.js b/ghost/admin/app/controllers/tag.js index fddc15253f..03af43dfeb 100644 --- a/ghost/admin/app/controllers/tag.js +++ b/ghost/admin/app/controllers/tag.js @@ -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'}); } }); diff --git a/ghost/admin/app/routes/tag.js b/ghost/admin/app/routes/tag.js index ee958e84ce..dba03dc7b4 100644 --- a/ghost/admin/app/routes/tag.js +++ b/ghost/admin/app/routes/tag.js @@ -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; } } } - }); diff --git a/ghost/admin/app/templates/tag.hbs b/ghost/admin/app/templates/tag.hbs index 1a63c6d346..8e21a17b95 100644 --- a/ghost/admin/app/templates/tag.hbs +++ b/ghost/admin/app/templates/tag.hbs @@ -14,9 +14,12 @@ setProperty=(action "setProperty") showDeleteTagModal=(action "toggleDeleteTagModal")}} - + + {{#unless this.tag.isNew}} + + {{/unless}} {{#if showUnsavedChangesModal}}