From 713e2b5eccaf06ad4ab2016939a47b7bec25faca Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 10 May 2022 11:22:36 +0100 Subject: [PATCH] Fixed flash of "Draft" when reverting a post to a draft no issue When reverting a post/page to a draft we were applying the model changes, saving, then closing the modal. This had the unwanted effect of updating the modal's copy whilst the save was in progress because it's all derived state and we're changing that state. - changed revert button behaviour to instantly close the modal with a return value that lets the publish management know to run the revert task once the modal has closed - added a popup notification to confirm successful revert --- .../editor-labs/modals/update-flow.hbs | 14 +++++------ .../editor-labs/modals/update-flow.js | 7 ------ .../editor-labs/publish-management.js | 24 +++++++++++++++---- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/ghost/admin/app/components/editor-labs/modals/update-flow.hbs b/ghost/admin/app/components/editor-labs/modals/update-flow.hbs index fc62988293..93a8fdecaf 100644 --- a/ghost/admin/app/components/editor-labs/modals/update-flow.hbs +++ b/ghost/admin/app/components/editor-labs/modals/update-flow.hbs @@ -68,13 +68,13 @@ @class="gh-btn gh-btn-icon gh-btn-primary gh-btn-large mr4" /> - + {{/let}} diff --git a/ghost/admin/app/components/editor-labs/modals/update-flow.js b/ghost/admin/app/components/editor-labs/modals/update-flow.js index 47085b402a..9d67882d14 100644 --- a/ghost/admin/app/components/editor-labs/modals/update-flow.js +++ b/ghost/admin/app/components/editor-labs/modals/update-flow.js @@ -14,11 +14,4 @@ export default class UpdateFlowModalComponent extends Component { this.args.close(); return true; } - - @task - *revertToDraftTask() { - yield this.args.data.revertToDraftTask.perform(); - this.args.close(); - return true; - } } diff --git a/ghost/admin/app/components/editor-labs/publish-management.js b/ghost/admin/app/components/editor-labs/publish-management.js index 61e01cc217..8b13f670ec 100644 --- a/ghost/admin/app/components/editor-labs/publish-management.js +++ b/ghost/admin/app/components/editor-labs/publish-management.js @@ -6,6 +6,7 @@ import UpdateFlowModal from './modals/update-flow'; import envConfig from 'ghost-admin/config/environment'; import moment from 'moment'; import {action, get} from '@ember/object'; +import {capitalize} from '@ember/string'; import {inject as service} from '@ember/service'; import {task, taskGroup, timeout} from 'ember-concurrency'; import {tracked} from '@glimmer/tracking'; @@ -353,6 +354,7 @@ export class PublishOptions { // PublishOptions saving. export default class PublishManagement extends Component { @service modals; + @service notifications; // ensure we get a new PublishOptions instance when @post is replaced @use publishOptions = new PublishOptionsResource(() => [this.args.post]); @@ -382,7 +384,7 @@ export default class PublishManagement extends Component { } @action - openUpdateFlow(event) { + async openUpdateFlow(event) { event?.preventDefault(); this.publishFlowModal?.close(); @@ -390,9 +392,14 @@ export default class PublishManagement extends Component { if (!this.updateFlowModal || this.updateFlowModal.isClosing) { this.updateFlowModal = this.modals.open(UpdateFlowModal, { publishOptions: this.publishOptions, - saveTask: this.publishTask, - revertToDraftTask: this.revertToDraftTask + saveTask: this.publishTask }); + + const result = await this.updateFlowModal; + + if (result?.afterTask && this[result?.afterTask]) { + this[result.afterTask].perform(); + } } } @@ -462,6 +469,15 @@ export default class PublishManagement extends Component { @task *revertToDraftTask() { - return yield this.publishTask.perform({taskName: 'revertToDraftTask'}); + try { + yield this.publishTask.perform({taskName: 'revertToDraftTask'}); + + const postType = capitalize(this.args.post.displayName); + this.notifications.showNotification(`${postType} successfully reverted to a draft.`, {type: 'success'}); + + return true; + } catch (e) { + this.notifications.showAPIError(error); + } } }