From 2ab1a9f109450ee39f02c491f8c8b7d4143ec9a3 Mon Sep 17 00:00:00 2001 From: William Earnhardt Date: Tue, 31 Jul 2018 14:27:47 -0400 Subject: [PATCH] Allow transitioning status from scheduled to draft --- .../src/components/post-saved-state/index.js | 6 ++++-- .../post-switch-to-draft-button/index.js | 15 +++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/editor/src/components/post-saved-state/index.js b/packages/editor/src/components/post-saved-state/index.js index d72c0def526bc7..42eed5d28736ba 100644 --- a/packages/editor/src/components/post-saved-state/index.js +++ b/packages/editor/src/components/post-saved-state/index.js @@ -41,7 +41,7 @@ export class PostSavedState extends Component { } render() { - const { isNew, isPublished, isDirty, isSaving, isSaveable, onSave, isAutosaving } = this.props; + const { isNew, isScheduled, isPublished, isDirty, isSaving, isSaveable, onSave, isAutosaving } = this.props; const { forceSavedMessage } = this.state; if ( isSaving ) { // TODO: Classes generation should be common across all return @@ -59,7 +59,7 @@ export class PostSavedState extends Component { ); } - if ( isPublished ) { + if ( isPublished || isScheduled ) { return ; } @@ -94,6 +94,7 @@ export default compose( [ const { isEditedPostNew, isCurrentPostPublished, + isCurrentPostScheduled, isEditedPostDirty, isSavingPost, isEditedPostSaveable, @@ -104,6 +105,7 @@ export default compose( [ post: getCurrentPost(), isNew: isEditedPostNew(), isPublished: isCurrentPostPublished(), + isScheduled: isCurrentPostScheduled(), isDirty: forceIsDirty || isEditedPostDirty(), isSaving: forceIsSaving || isSavingPost(), isSaveable: isEditedPostSaveable(), diff --git a/packages/editor/src/components/post-switch-to-draft-button/index.js b/packages/editor/src/components/post-switch-to-draft-button/index.js index 8ea77f0f8a0d38..93895cb831f54b 100644 --- a/packages/editor/src/components/post-switch-to-draft-button/index.js +++ b/packages/editor/src/components/post-switch-to-draft-button/index.js @@ -6,14 +6,20 @@ import { __ } from '@wordpress/i18n'; import { withSelect, withDispatch } from '@wordpress/data'; import { compose } from '@wordpress/compose'; -function PostSwitchToDraftButton( { isSaving, isPublished, onClick } ) { - if ( ! isPublished ) { +function PostSwitchToDraftButton( { isSaving, isPublished, isScheduled, onClick } ) { + if ( ! isPublished && ! isScheduled ) { return null; } const onSwitch = () => { + let alertMessage; + if ( isPublished ) { + alertMessage = __( 'Are you sure you want to unpublish this post?' ); + } else if ( isScheduled ) { + alertMessage = __( 'Are you sure you want to unschedule this post?' ); + } // eslint-disable-next-line no-alert - if ( window.confirm( __( 'Are you sure you want to unpublish this post?' ) ) ) { + if ( window.confirm( alertMessage ) ) { onClick(); } }; @@ -32,10 +38,11 @@ function PostSwitchToDraftButton( { isSaving, isPublished, onClick } ) { export default compose( [ withSelect( ( select ) => { - const { isSavingPost, isCurrentPostPublished } = select( 'core/editor' ); + const { isSavingPost, isCurrentPostPublished, isCurrentPostScheduled } = select( 'core/editor' ); return { isSaving: isSavingPost(), isPublished: isCurrentPostPublished(), + isScheduled: isCurrentPostScheduled(), }; } ), withDispatch( ( dispatch ) => {