From b7cc2417fb99c95e3623775d09d7520b5defedad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 7 Sep 2018 13:43:37 +0200 Subject: [PATCH 01/30] Add PrePublish panel option to the general menu tools section --- .../components/header/more-menu/index.js | 2 ++ .../header/publish-panel-toggle/index.js | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 edit-post/components/header/publish-panel-toggle/index.js diff --git a/edit-post/components/header/more-menu/index.js b/edit-post/components/header/more-menu/index.js index 17ea090a1b7106..b9f874f408b809 100644 --- a/edit-post/components/header/more-menu/index.js +++ b/edit-post/components/header/more-menu/index.js @@ -14,6 +14,7 @@ import PluginMoreMenuGroup from '../plugins-more-menu-group'; import TipsToggle from '../tips-toggle'; import KeyboardShortcutsHelpMenuItem from '../keyboard-shortcuts-help-menu-item'; import WritingMenu from '../writing-menu'; +import PublishPanelToggle from '../publish-panel-toggle'; const MoreMenu = () => ( ( { __( 'Manage All Reusable Blocks' ) } + diff --git a/edit-post/components/header/publish-panel-toggle/index.js b/edit-post/components/header/publish-panel-toggle/index.js new file mode 100644 index 00000000000000..6e8bc997c39a9e --- /dev/null +++ b/edit-post/components/header/publish-panel-toggle/index.js @@ -0,0 +1,20 @@ +/** + * WordPress Dependencies + */ +import { __ } from '@wordpress/i18n'; +import { MenuItem } from '@wordpress/components'; + +const PublishPanelToggle = function( { onToggle, isActive } ) { + return ( + + { __( 'PrePublish Panel' ) } + + ); +} + +export default PublishPanelToggle; From e3f0c24138b010995767cb619073c47ccf2bb47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 7 Sep 2018 13:44:25 +0200 Subject: [PATCH 02/30] Add data API --- .../header/publish-panel-toggle/index.js | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/edit-post/components/header/publish-panel-toggle/index.js b/edit-post/components/header/publish-panel-toggle/index.js index 6e8bc997c39a9e..3c666a3a00e954 100644 --- a/edit-post/components/header/publish-panel-toggle/index.js +++ b/edit-post/components/header/publish-panel-toggle/index.js @@ -3,18 +3,35 @@ */ import { __ } from '@wordpress/i18n'; import { MenuItem } from '@wordpress/components'; +import { compose } from '@wordpress/compose'; +import { withSelect, withDispatch } from '@wordpress/data'; -const PublishPanelToggle = function( { onToggle, isActive } ) { +const PublishPanelToggle = function( { onToggle, isEnabled } ) { return ( { __( 'PrePublish Panel' ) } ); -} +}; -export default PublishPanelToggle; +export default compose( [ + withSelect( ( select ) => ( { + isEnabled: select( 'core/nux' ).isPrePublishPanelEnabled(), + } ) ), + withDispatch( ( dispatch, ownProps ) => ( { + onToggle() { + const { disablePrePublishPanel, enablePrePublishPanel } = dispatch( 'core/nux' ); + if ( ownProps.isActive ) { + disablePrePublishPanel(); + } else { + enablePrePublishPanel(); + } + ownProps.onToggle(); + }, + } ) ), +] )( PublishPanelToggle ); From 85edadcc7713949e02b2065b00307e3059eb80c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 7 Sep 2018 13:45:11 +0200 Subject: [PATCH 03/30] Rename PublishPanel to PrePublishPanel --- edit-post/components/header/more-menu/index.js | 4 ++-- .../index.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename edit-post/components/header/{publish-panel-toggle => pre-publish-panel-toggle}/index.js (89%) diff --git a/edit-post/components/header/more-menu/index.js b/edit-post/components/header/more-menu/index.js index b9f874f408b809..a198351aa133bf 100644 --- a/edit-post/components/header/more-menu/index.js +++ b/edit-post/components/header/more-menu/index.js @@ -14,7 +14,7 @@ import PluginMoreMenuGroup from '../plugins-more-menu-group'; import TipsToggle from '../tips-toggle'; import KeyboardShortcutsHelpMenuItem from '../keyboard-shortcuts-help-menu-item'; import WritingMenu from '../writing-menu'; -import PublishPanelToggle from '../publish-panel-toggle'; +import PrePublishPanelToggle from '../pre-publish-panel-toggle'; const MoreMenu = () => ( ( { __( 'Manage All Reusable Blocks' ) } - + diff --git a/edit-post/components/header/publish-panel-toggle/index.js b/edit-post/components/header/pre-publish-panel-toggle/index.js similarity index 89% rename from edit-post/components/header/publish-panel-toggle/index.js rename to edit-post/components/header/pre-publish-panel-toggle/index.js index 3c666a3a00e954..28dfea2b6628f4 100644 --- a/edit-post/components/header/publish-panel-toggle/index.js +++ b/edit-post/components/header/pre-publish-panel-toggle/index.js @@ -6,7 +6,7 @@ import { MenuItem } from '@wordpress/components'; import { compose } from '@wordpress/compose'; import { withSelect, withDispatch } from '@wordpress/data'; -const PublishPanelToggle = function( { onToggle, isEnabled } ) { +const PrePublishPanelToggle = function( { onToggle, isEnabled } ) { return ( Date: Mon, 10 Sep 2018 18:01:24 +0200 Subject: [PATCH 04/30] Implement core/edit-post actions and selector --- .../components/header/more-menu/index.js | 2 +- .../header/pre-publish-panel-toggle/index.js | 16 +++++++------- edit-post/store/actions.js | 22 +++++++++++++++++++ edit-post/store/reducer.js | 9 ++++++++ edit-post/store/selectors.js | 12 ++++++++++ 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/edit-post/components/header/more-menu/index.js b/edit-post/components/header/more-menu/index.js index a198351aa133bf..13b214f13024b1 100644 --- a/edit-post/components/header/more-menu/index.js +++ b/edit-post/components/header/more-menu/index.js @@ -45,7 +45,7 @@ const MoreMenu = () => ( { __( 'Manage All Reusable Blocks' ) } - + diff --git a/edit-post/components/header/pre-publish-panel-toggle/index.js b/edit-post/components/header/pre-publish-panel-toggle/index.js index 28dfea2b6628f4..485deb7c909add 100644 --- a/edit-post/components/header/pre-publish-panel-toggle/index.js +++ b/edit-post/components/header/pre-publish-panel-toggle/index.js @@ -6,7 +6,7 @@ import { MenuItem } from '@wordpress/components'; import { compose } from '@wordpress/compose'; import { withSelect, withDispatch } from '@wordpress/data'; -const PrePublishPanelToggle = function( { onToggle, isEnabled } ) { +const PublishSidebarToggle = function( { onToggle, isEnabled } ) { return ( - { __( 'PrePublish Panel' ) } + { __( 'Publish Sidebar' ) } ); }; export default compose( [ withSelect( ( select ) => ( { - isEnabled: select( 'core/nux' ).isPrePublishPanelEnabled(), + isEnabled: select( 'core/edit-post' ).isPublishSidebarEnabled(), } ) ), withDispatch( ( dispatch, ownProps ) => ( { onToggle() { - const { disablePrePublishPanel, enablePrePublishPanel } = dispatch( 'core/nux' ); - if ( ownProps.isActive ) { - disablePrePublishPanel(); + const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/edit-post' ); + if ( ownProps.isEnabled ) { + disablePublishSidebar(); } else { - enablePrePublishPanel(); + enablePublishSidebar(); } ownProps.onToggle(); }, } ) ), -] )( PrePublishPanelToggle ); +] )( PublishSidebarToggle ); diff --git a/edit-post/store/actions.js b/edit-post/store/actions.js index 2a58739addd93f..ce50b0789ab494 100644 --- a/edit-post/store/actions.js +++ b/edit-post/store/actions.js @@ -83,6 +83,28 @@ export function togglePublishSidebar() { }; } +/** + * Returns an action object used in signalling that the user has enabled the publish sidebar. + * + * @return {Object} Action object + */ +export function enablePublishSidebar() { + return { + type: 'ENABLE_PUBLISH_SIDEBAR', + }; +} + +/** + * Returns an action object used in signalling that the user has disabled the publish sidebar. + * + * @return {Object} Action object + */ +export function disablePublishSidebar() { + return { + type: 'DISABLE_PUBLISH_SIDEBAR', + }; +} + /** * Returns an action object used in signalling that use toggled a panel in the editor. * diff --git a/edit-post/store/reducer.js b/edit-post/store/reducer.js index 0b9ad2683a9002..988e42f847787b 100644 --- a/edit-post/store/reducer.js +++ b/edit-post/store/reducer.js @@ -49,6 +49,15 @@ export const preferences = combineReducers( { return state; }, + isPublishSidebarEnabled( state = true, action ) { + switch ( action.type ) { + case 'ENABLE_PUBLISH_SIDEBAR': + case 'DISABLE_PUBLISH_SIDEBAR': + return action.type === 'ENABLE_PUBLISH_SIDEBAR'; + } + + return state; + }, panels( state = PREFERENCES_DEFAULTS.panels, action ) { if ( action.type === 'TOGGLE_GENERAL_SIDEBAR_EDITOR_PANEL' ) { return { diff --git a/edit-post/store/selectors.js b/edit-post/store/selectors.js index 628f00a7497652..77599468ef1110 100644 --- a/edit-post/store/selectors.js +++ b/edit-post/store/selectors.js @@ -15,6 +15,18 @@ export function getEditorMode( state ) { return getPreference( state, 'editorMode', 'visual' ); } +/** + * Returns whether the pre-publish panel show be shown + * or hidden on publish. + * + * @param {Object} state Global application state. + * + * @return {boolean} Whether the pre-publish panel should be shown or not. + */ +export function isPublishSidebarEnabled( state ) { + return getPreference( state, 'isPublishSidebarEnabled', true ); +} + /** * Returns true if the editor sidebar is opened. * From 14ea423c8d99ac2ea98f8979b9ae24037d236fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Mon, 10 Sep 2018 18:02:45 +0200 Subject: [PATCH 05/30] Rename pre-publish-panel-toggle to publish-sidebar-toggle --- edit-post/components/header/more-menu/index.js | 4 ++-- .../index.js | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename edit-post/components/header/{pre-publish-panel-toggle => publish-sidebar-toggle}/index.js (100%) diff --git a/edit-post/components/header/more-menu/index.js b/edit-post/components/header/more-menu/index.js index 13b214f13024b1..60f4a9225b52d5 100644 --- a/edit-post/components/header/more-menu/index.js +++ b/edit-post/components/header/more-menu/index.js @@ -14,7 +14,7 @@ import PluginMoreMenuGroup from '../plugins-more-menu-group'; import TipsToggle from '../tips-toggle'; import KeyboardShortcutsHelpMenuItem from '../keyboard-shortcuts-help-menu-item'; import WritingMenu from '../writing-menu'; -import PrePublishPanelToggle from '../pre-publish-panel-toggle'; +import PublishSidebarToggle from '../publish-sidebar-toggle'; const MoreMenu = () => ( ( { __( 'Manage All Reusable Blocks' ) } - + diff --git a/edit-post/components/header/pre-publish-panel-toggle/index.js b/edit-post/components/header/publish-sidebar-toggle/index.js similarity index 100% rename from edit-post/components/header/pre-publish-panel-toggle/index.js rename to edit-post/components/header/publish-sidebar-toggle/index.js From f4c237e010a1b3792a2edc80f746b8d1e14b0b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Mon, 10 Sep 2018 19:12:54 +0200 Subject: [PATCH 06/30] Connect the dots: publish toggles publish sidebar or publish directly --- edit-post/components/header/index.js | 9 ++++--- .../components/header/publish-button/index.js | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 edit-post/components/header/publish-button/index.js diff --git a/edit-post/components/header/index.js b/edit-post/components/header/index.js index 9fcafc7b325825..c43f2512438764 100644 --- a/edit-post/components/header/index.js +++ b/edit-post/components/header/index.js @@ -6,7 +6,6 @@ import { IconButton } from '@wordpress/components'; import { PostPreviewButton, PostSavedState, - PostPublishPanelToggle, } from '@wordpress/editor'; import { withDispatch, withSelect } from '@wordpress/data'; import { compose } from '@wordpress/compose'; @@ -19,6 +18,7 @@ import './style.scss'; import MoreMenu from './more-menu'; import HeaderToolbar from './header-toolbar'; import PinnedPlugins from './pinned-plugins'; +import PublishButton from './publish-button'; import shortcuts from '../../keyboard-shortcuts'; function Header( { @@ -26,6 +26,7 @@ function Header( { openGeneralSidebar, closeGeneralSidebar, isPublishSidebarOpened, + isPublishSidebarEnabled, togglePublishSidebar, hasActiveMetaboxes, isSaving, @@ -48,8 +49,9 @@ function Header( { forceIsSaving={ isSaving } /> - ( { isEditorSidebarOpened: select( 'core/edit-post' ).isEditorSidebarOpened(), isPublishSidebarOpened: select( 'core/edit-post' ).isPublishSidebarOpened(), + isPublishSidebarEnabled: select( 'core/edit-post' ).isPublishSidebarEnabled(), hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(), isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(), hasBlockSelection: !! select( 'core/editor' ).getBlockSelectionStart(), diff --git a/edit-post/components/header/publish-button/index.js b/edit-post/components/header/publish-button/index.js new file mode 100644 index 00000000000000..20978eaa4c918b --- /dev/null +++ b/edit-post/components/header/publish-button/index.js @@ -0,0 +1,25 @@ +import { PostPublishPanelToggle, PostPublishButton } from '@wordpress/editor'; + +const PublishButton = function( { + isSidebarOpen, + isSidebarEnabled, + onToggle, + forceIsDirty, + forceIsSaving } ) { + if ( isSidebarEnabled ) { + return ( + + ); + } + return ; +}; + +export default PublishButton; From 1a00c13ddae38a1af95fa1e3257a8f59351d8cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 11 Sep 2018 12:01:57 +0200 Subject: [PATCH 07/30] Update test for isPublishSidebarEnable preference --- edit-post/store/test/reducer.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/edit-post/store/test/reducer.js b/edit-post/store/test/reducer.js index eefd38bd2a94cc..415d2c6a7957e9 100644 --- a/edit-post/store/test/reducer.js +++ b/edit-post/store/test/reducer.js @@ -23,6 +23,7 @@ describe( 'state', () => { expect( state ).toEqual( { editorMode: 'visual', isGeneralSidebarDismissed: false, + isPublishSidebarEnabled: true, panels: { 'post-status': true }, features: { fixedToolbar: false }, pinnedPluginItems: {}, @@ -51,6 +52,24 @@ describe( 'state', () => { expect( state.isGeneralSidebarDismissed ).toBe( true ); } ); + it( 'should disable the publish sidebar', () => { + const original = deepFreeze( preferences( undefined, { } ) ); + const state = preferences( original, { + type: 'DISABLE_PUBLISH_SIDEBAR', + } ); + + expect( state.isPublishSidebarEnabled ).toBe( false ); + } ); + + it( 'should enable the publish sidebar', () => { + const original = deepFreeze( preferences( { isPublishSidebarEnabled: false }, { } ) ); + const state = preferences( original, { + type: 'ENABLE_PUBLISH_SIDEBAR', + } ); + + expect( state.isPublishSidebarEnabled ).toBe( true ); + } ); + it( 'should set the sidebar panel open flag to true if unset', () => { const state = preferences( deepFreeze( { panels: {} } ), { type: 'TOGGLE_GENERAL_SIDEBAR_EDITOR_PANEL', From c6595294aabcd064b0ca8aa15501d787910ba9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 11 Sep 2018 12:34:38 +0200 Subject: [PATCH 08/30] Expose dismissing option as a checkbox in the sidebar --- .../components/post-publish-panel/index.js | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/post-publish-panel/index.js b/packages/editor/src/components/post-publish-panel/index.js index 93a21c18b84c46..64f9de47e65909 100644 --- a/packages/editor/src/components/post-publish-panel/index.js +++ b/packages/editor/src/components/post-publish-panel/index.js @@ -8,8 +8,8 @@ import { get } from 'lodash'; */ import { __ } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; -import { IconButton, Spinner } from '@wordpress/components'; -import { withSelect } from '@wordpress/data'; +import { IconButton, Spinner, CheckboxControl } from '@wordpress/components'; +import { withSelect, withDispatch } from '@wordpress/data'; import { compose } from '@wordpress/compose'; /** @@ -62,7 +62,7 @@ class PostPublishPanel extends Component { } render() { - const { isScheduled, onClose, forceIsDirty, forceIsSaving, PrePublishExtension, PostPublishExtension, ...additionalProps } = this.props; + const { isScheduled, isPublishSidebarEnabled, onClose, onTogglePublishSidebar, forceIsDirty, forceIsSaving, PrePublishExtension, PostPublishExtension, ...additionalProps } = this.props; const { loading, submitted } = this.state; return (
@@ -96,6 +96,11 @@ class PostPublishPanel extends Component { { PostPublishExtension && } ) } +
); @@ -112,6 +117,7 @@ export default compose( [ isSavingPost, isEditedPostDirty, } = select( 'core/editor' ); + const { isPublishSidebarEnabled } = select( 'core/edit-post' ); return { postType: getCurrentPostType(), hasPublishAction: get( getCurrentPost(), [ '_links', 'wp:action-publish' ], false ), @@ -119,6 +125,19 @@ export default compose( [ isScheduled: isCurrentPostScheduled(), isSaving: isSavingPost(), isDirty: isEditedPostDirty(), + isPublishSidebarEnabled: isPublishSidebarEnabled(), + }; + } ), + withDispatch( ( dispatch, { isPublishSidebarEnabled } ) => { + const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/edit-post' ); + return { + onTogglePublishSidebar: ( ) => { + if ( isPublishSidebarEnabled ) { + disablePublishSidebar(); + } else { + enablePublishSidebar(); + } + }, }; } ), ] )( PostPublishPanel ); From e888220a79501e9e140ac3f6f13240309c3c079e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 11 Sep 2018 14:28:13 +0200 Subject: [PATCH 09/30] Move publish sidebar logic to core/editor store This logic is used by the PostPublishPanel, which lives in editor. We don't want editor to depend on anything from edit-post. An alternative approach could be to keep the logic in edit-post and use the the PrePublish and PostPublish extensions. In my view, those are meant for allowing plugins to inject their own panels into the PublishPanel. Dismissing the panel is a core action and using the extensions to circumvent the editor/edit-post separation would be a convoluted way to add support for dismissing the panel. --- edit-post/components/header/index.js | 2 +- .../header/publish-sidebar-toggle/index.js | 4 ++-- edit-post/store/actions.js | 22 ------------------- edit-post/store/reducer.js | 9 -------- edit-post/store/selectors.js | 12 ---------- edit-post/store/test/reducer.js | 19 ---------------- .../components/post-publish-panel/index.js | 4 ++-- packages/editor/src/store/actions.js | 22 +++++++++++++++++++ packages/editor/src/store/defaults.js | 1 + packages/editor/src/store/reducer.js | 7 ++++++ packages/editor/src/store/selectors.js | 12 ++++++++++ packages/editor/src/store/test/reducer.js | 19 ++++++++++++++++ 12 files changed, 66 insertions(+), 67 deletions(-) diff --git a/edit-post/components/header/index.js b/edit-post/components/header/index.js index c43f2512438764..f5320b935c091e 100644 --- a/edit-post/components/header/index.js +++ b/edit-post/components/header/index.js @@ -81,7 +81,7 @@ export default compose( withSelect( ( select ) => ( { isEditorSidebarOpened: select( 'core/edit-post' ).isEditorSidebarOpened(), isPublishSidebarOpened: select( 'core/edit-post' ).isPublishSidebarOpened(), - isPublishSidebarEnabled: select( 'core/edit-post' ).isPublishSidebarEnabled(), + isPublishSidebarEnabled: select( 'core/editor' ).isPublishSidebarEnabled(), hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(), isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(), hasBlockSelection: !! select( 'core/editor' ).getBlockSelectionStart(), diff --git a/edit-post/components/header/publish-sidebar-toggle/index.js b/edit-post/components/header/publish-sidebar-toggle/index.js index 485deb7c909add..b86192f84dda66 100644 --- a/edit-post/components/header/publish-sidebar-toggle/index.js +++ b/edit-post/components/header/publish-sidebar-toggle/index.js @@ -21,11 +21,11 @@ const PublishSidebarToggle = function( { onToggle, isEnabled } ) { export default compose( [ withSelect( ( select ) => ( { - isEnabled: select( 'core/edit-post' ).isPublishSidebarEnabled(), + isEnabled: select( 'core/editor' ).isPublishSidebarEnabled(), } ) ), withDispatch( ( dispatch, ownProps ) => ( { onToggle() { - const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/edit-post' ); + const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/editor' ); if ( ownProps.isEnabled ) { disablePublishSidebar(); } else { diff --git a/edit-post/store/actions.js b/edit-post/store/actions.js index ce50b0789ab494..2a58739addd93f 100644 --- a/edit-post/store/actions.js +++ b/edit-post/store/actions.js @@ -83,28 +83,6 @@ export function togglePublishSidebar() { }; } -/** - * Returns an action object used in signalling that the user has enabled the publish sidebar. - * - * @return {Object} Action object - */ -export function enablePublishSidebar() { - return { - type: 'ENABLE_PUBLISH_SIDEBAR', - }; -} - -/** - * Returns an action object used in signalling that the user has disabled the publish sidebar. - * - * @return {Object} Action object - */ -export function disablePublishSidebar() { - return { - type: 'DISABLE_PUBLISH_SIDEBAR', - }; -} - /** * Returns an action object used in signalling that use toggled a panel in the editor. * diff --git a/edit-post/store/reducer.js b/edit-post/store/reducer.js index 988e42f847787b..0b9ad2683a9002 100644 --- a/edit-post/store/reducer.js +++ b/edit-post/store/reducer.js @@ -49,15 +49,6 @@ export const preferences = combineReducers( { return state; }, - isPublishSidebarEnabled( state = true, action ) { - switch ( action.type ) { - case 'ENABLE_PUBLISH_SIDEBAR': - case 'DISABLE_PUBLISH_SIDEBAR': - return action.type === 'ENABLE_PUBLISH_SIDEBAR'; - } - - return state; - }, panels( state = PREFERENCES_DEFAULTS.panels, action ) { if ( action.type === 'TOGGLE_GENERAL_SIDEBAR_EDITOR_PANEL' ) { return { diff --git a/edit-post/store/selectors.js b/edit-post/store/selectors.js index 77599468ef1110..628f00a7497652 100644 --- a/edit-post/store/selectors.js +++ b/edit-post/store/selectors.js @@ -15,18 +15,6 @@ export function getEditorMode( state ) { return getPreference( state, 'editorMode', 'visual' ); } -/** - * Returns whether the pre-publish panel show be shown - * or hidden on publish. - * - * @param {Object} state Global application state. - * - * @return {boolean} Whether the pre-publish panel should be shown or not. - */ -export function isPublishSidebarEnabled( state ) { - return getPreference( state, 'isPublishSidebarEnabled', true ); -} - /** * Returns true if the editor sidebar is opened. * diff --git a/edit-post/store/test/reducer.js b/edit-post/store/test/reducer.js index 415d2c6a7957e9..eefd38bd2a94cc 100644 --- a/edit-post/store/test/reducer.js +++ b/edit-post/store/test/reducer.js @@ -23,7 +23,6 @@ describe( 'state', () => { expect( state ).toEqual( { editorMode: 'visual', isGeneralSidebarDismissed: false, - isPublishSidebarEnabled: true, panels: { 'post-status': true }, features: { fixedToolbar: false }, pinnedPluginItems: {}, @@ -52,24 +51,6 @@ describe( 'state', () => { expect( state.isGeneralSidebarDismissed ).toBe( true ); } ); - it( 'should disable the publish sidebar', () => { - const original = deepFreeze( preferences( undefined, { } ) ); - const state = preferences( original, { - type: 'DISABLE_PUBLISH_SIDEBAR', - } ); - - expect( state.isPublishSidebarEnabled ).toBe( false ); - } ); - - it( 'should enable the publish sidebar', () => { - const original = deepFreeze( preferences( { isPublishSidebarEnabled: false }, { } ) ); - const state = preferences( original, { - type: 'ENABLE_PUBLISH_SIDEBAR', - } ); - - expect( state.isPublishSidebarEnabled ).toBe( true ); - } ); - it( 'should set the sidebar panel open flag to true if unset', () => { const state = preferences( deepFreeze( { panels: {} } ), { type: 'TOGGLE_GENERAL_SIDEBAR_EDITOR_PANEL', diff --git a/packages/editor/src/components/post-publish-panel/index.js b/packages/editor/src/components/post-publish-panel/index.js index 64f9de47e65909..9257cdaf6fe12d 100644 --- a/packages/editor/src/components/post-publish-panel/index.js +++ b/packages/editor/src/components/post-publish-panel/index.js @@ -117,7 +117,7 @@ export default compose( [ isSavingPost, isEditedPostDirty, } = select( 'core/editor' ); - const { isPublishSidebarEnabled } = select( 'core/edit-post' ); + const { isPublishSidebarEnabled } = select( 'core/editor' ); return { postType: getCurrentPostType(), hasPublishAction: get( getCurrentPost(), [ '_links', 'wp:action-publish' ], false ), @@ -129,7 +129,7 @@ export default compose( [ }; } ), withDispatch( ( dispatch, { isPublishSidebarEnabled } ) => { - const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/edit-post' ); + const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/editor' ); return { onTogglePublishSidebar: ( ) => { if ( isPublishSidebarEnabled ) { diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js index d9d4e3186b73cf..4d81471a6fa4f9 100644 --- a/packages/editor/src/store/actions.js +++ b/packages/editor/src/store/actions.js @@ -763,3 +763,25 @@ export function unregisterToken( name ) { name, }; } + +/** + * Returns an action object used in signalling that the user has enabled the publish sidebar. + * + * @return {Object} Action object + */ +export function enablePublishSidebar() { + return { + type: 'ENABLE_PUBLISH_SIDEBAR', + }; +} + +/** + * Returns an action object used in signalling that the user has disabled the publish sidebar. + * + * @return {Object} Action object + */ +export function disablePublishSidebar() { + return { + type: 'DISABLE_PUBLISH_SIDEBAR', + }; +} diff --git a/packages/editor/src/store/defaults.js b/packages/editor/src/store/defaults.js index bc4be6692059b6..1118028ccd2d9b 100644 --- a/packages/editor/src/store/defaults.js +++ b/packages/editor/src/store/defaults.js @@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n'; export const PREFERENCES_DEFAULTS = { insertUsage: {}, + isPublishSidebarEnabled: true, }; /** diff --git a/packages/editor/src/store/reducer.js b/packages/editor/src/store/reducer.js index 09d58a57be956f..98e9fb8a58484b 100644 --- a/packages/editor/src/store/reducer.js +++ b/packages/editor/src/store/reducer.js @@ -810,6 +810,13 @@ export function preferences( state = PREFERENCES_DEFAULTS, action ) { ...state, insertUsage: omitBy( state.insertUsage, ( { insert } ) => insert.ref === action.id ), }; + + case 'ENABLE_PUBLISH_SIDEBAR': + case 'DISABLE_PUBLISH_SIDEBAR': + return { + ...state, + isPublishSidebarEnabled: action.type === 'ENABLE_PUBLISH_SIDEBAR', + }; } return state; diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index 81bc282d774e65..0b9299b47e1248 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1879,3 +1879,15 @@ export function getTokenSettings( state, name ) { export function canUserUseUnfilteredHTML( state ) { return has( getCurrentPost( state ), [ '_links', 'wp:action-unfiltered_html' ] ); } + +/** + * Returns whether the pre-publish panel should be shown + * or hidden on publish. + * + * @param {Object} state Global application state. + * + * @return {boolean} Whether the pre-publish panel should be shown or not. + */ +export function isPublishSidebarEnabled( state ) { + return state.preferences.isPublishSidebarEnabled; +} diff --git a/packages/editor/src/store/test/reducer.js b/packages/editor/src/store/test/reducer.js index 9445b32a11e7ca..9913daf213ec2d 100644 --- a/packages/editor/src/store/test/reducer.js +++ b/packages/editor/src/store/test/reducer.js @@ -1580,9 +1580,28 @@ describe( 'state', () => { expect( state ).toEqual( { insertUsage: {}, + isPublishSidebarEnabled: true, } ); } ); + it( 'should disable the publish sidebar', () => { + const original = deepFreeze( preferences( undefined, { } ) ); + const state = preferences( original, { + type: 'DISABLE_PUBLISH_SIDEBAR', + } ); + + expect( state.isPublishSidebarEnabled ).toBe( false ); + } ); + + it( 'should enable the publish sidebar', () => { + const original = deepFreeze( preferences( { isPublishSidebarEnabled: false }, { } ) ); + const state = preferences( original, { + type: 'ENABLE_PUBLISH_SIDEBAR', + } ); + + expect( state.isPublishSidebarEnabled ).toBe( true ); + } ); + it( 'should record recently used blocks', () => { const state = preferences( deepFreeze( { insertUsage: {} } ), { type: 'INSERT_BLOCKS', From b3e9fa888b5b706ebd7019b41bec0db07aac7b22 Mon Sep 17 00:00:00 2001 From: Matthew Riley MacPherson Date: Tue, 11 Sep 2018 14:13:37 +0100 Subject: [PATCH 10/30] docs: tweak comment on isPublishSidebarEnabled --- packages/editor/src/store/selectors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index 0b9299b47e1248..d4169ec9f4721d 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1882,7 +1882,7 @@ export function canUserUseUnfilteredHTML( state ) { /** * Returns whether the pre-publish panel should be shown - * or hidden on publish. + * or skipped when the user clicks the "publish" button. * * @param {Object} state Global application state. * From f78a332fdab8f0626741b2e1604ef466a65c913e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 11 Sep 2018 19:18:11 +0200 Subject: [PATCH 11/30] Use arrow function instead of traditional function --- edit-post/components/header/publish-button/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/edit-post/components/header/publish-button/index.js b/edit-post/components/header/publish-button/index.js index 20978eaa4c918b..02b7a9160950de 100644 --- a/edit-post/components/header/publish-button/index.js +++ b/edit-post/components/header/publish-button/index.js @@ -1,11 +1,11 @@ import { PostPublishPanelToggle, PostPublishButton } from '@wordpress/editor'; -const PublishButton = function( { +const PublishButton = ( { isSidebarOpen, isSidebarEnabled, onToggle, forceIsDirty, - forceIsSaving } ) { + forceIsSaving } ) => { if ( isSidebarEnabled ) { return ( Date: Tue, 11 Sep 2018 19:20:25 +0200 Subject: [PATCH 12/30] Fix linting issue that went undetected by eslint --- edit-post/components/header/publish-button/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/edit-post/components/header/publish-button/index.js b/edit-post/components/header/publish-button/index.js index 02b7a9160950de..27fa499d9dac81 100644 --- a/edit-post/components/header/publish-button/index.js +++ b/edit-post/components/header/publish-button/index.js @@ -5,7 +5,8 @@ const PublishButton = ( { isSidebarEnabled, onToggle, forceIsDirty, - forceIsSaving } ) => { + forceIsSaving, +} ) => { if ( isSidebarEnabled ) { return ( Date: Tue, 11 Sep 2018 19:34:43 +0200 Subject: [PATCH 13/30] Use english apostrophe, not single commas --- packages/editor/src/components/post-publish-panel/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/components/post-publish-panel/index.js b/packages/editor/src/components/post-publish-panel/index.js index 9257cdaf6fe12d..a3cb5bf8242033 100644 --- a/packages/editor/src/components/post-publish-panel/index.js +++ b/packages/editor/src/components/post-publish-panel/index.js @@ -97,7 +97,7 @@ class PostPublishPanel extends Component { ) } From ea5dc6a2ec8cee836fb5cba4dbd8a5a91b8b51cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 11 Sep 2018 19:35:01 +0200 Subject: [PATCH 14/30] Make enable/disable actions more obvious --- packages/editor/src/store/reducer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/store/reducer.js b/packages/editor/src/store/reducer.js index 98e9fb8a58484b..bc0de8e1cb572d 100644 --- a/packages/editor/src/store/reducer.js +++ b/packages/editor/src/store/reducer.js @@ -812,10 +812,15 @@ export function preferences( state = PREFERENCES_DEFAULTS, action ) { }; case 'ENABLE_PUBLISH_SIDEBAR': + return { + ...state, + isPublishSidebarEnabled: true, + }; + case 'DISABLE_PUBLISH_SIDEBAR': return { ...state, - isPublishSidebarEnabled: action.type === 'ENABLE_PUBLISH_SIDEBAR', + isPublishSidebarEnabled: false, }; } From afae18daaa1b52a7a09543fdcff919c173069334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 11 Sep 2018 19:41:02 +0200 Subject: [PATCH 15/30] Inline PostPublish button / toggle logic --- edit-post/components/header/index.js | 22 ++++++++++------ .../components/header/publish-button/index.js | 26 ------------------- 2 files changed, 14 insertions(+), 34 deletions(-) delete mode 100644 edit-post/components/header/publish-button/index.js diff --git a/edit-post/components/header/index.js b/edit-post/components/header/index.js index f5320b935c091e..5e3ec6843ef116 100644 --- a/edit-post/components/header/index.js +++ b/edit-post/components/header/index.js @@ -6,6 +6,8 @@ import { IconButton } from '@wordpress/components'; import { PostPreviewButton, PostSavedState, + PostPublishPanelToggle, + PostPublishButton, } from '@wordpress/editor'; import { withDispatch, withSelect } from '@wordpress/data'; import { compose } from '@wordpress/compose'; @@ -18,7 +20,6 @@ import './style.scss'; import MoreMenu from './more-menu'; import HeaderToolbar from './header-toolbar'; import PinnedPlugins from './pinned-plugins'; -import PublishButton from './publish-button'; import shortcuts from '../../keyboard-shortcuts'; function Header( { @@ -49,13 +50,18 @@ function Header( { forceIsSaving={ isSaving } /> - + { isPublishSidebarEnabled ? + ( ) : + ( ) + }
{ - if ( isSidebarEnabled ) { - return ( - - ); - } - return ; -}; - -export default PublishButton; From 2f45e2006d4e44014f7f2887517f6c30a24380fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 11 Sep 2018 20:03:34 +0200 Subject: [PATCH 16/30] Add padding to align and give it space --- packages/editor/src/components/post-publish-panel/index.js | 2 ++ packages/editor/src/components/post-publish-panel/style.scss | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/packages/editor/src/components/post-publish-panel/index.js b/packages/editor/src/components/post-publish-panel/index.js index a3cb5bf8242033..d53a207165643c 100644 --- a/packages/editor/src/components/post-publish-panel/index.js +++ b/packages/editor/src/components/post-publish-panel/index.js @@ -96,6 +96,8 @@ class PostPublishPanel extends Component { { PostPublishExtension && } ) } +
+
Date: Tue, 11 Sep 2018 20:09:50 +0200 Subject: [PATCH 17/30] Align to bottom --- packages/editor/src/components/post-publish-panel/style.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/editor/src/components/post-publish-panel/style.scss b/packages/editor/src/components/post-publish-panel/style.scss index 010b3badaabfaf..137fc6876793f6 100644 --- a/packages/editor/src/components/post-publish-panel/style.scss +++ b/packages/editor/src/components/post-publish-panel/style.scss @@ -32,6 +32,8 @@ .editor-post-publish-panel__footer { padding: 16px; + position: absolute; + bottom: 0; } .components-button.editor-post-publish-panel__toggle.is-primary { From c65ea7c310d558c29c47a6d8d7a74c52026930db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 11 Sep 2018 20:19:24 +0200 Subject: [PATCH 18/30] Update wording --- edit-post/components/header/publish-sidebar-toggle/index.js | 2 +- packages/editor/src/components/post-publish-panel/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/edit-post/components/header/publish-sidebar-toggle/index.js b/edit-post/components/header/publish-sidebar-toggle/index.js index b86192f84dda66..5effd7a654b4a9 100644 --- a/edit-post/components/header/publish-sidebar-toggle/index.js +++ b/edit-post/components/header/publish-sidebar-toggle/index.js @@ -14,7 +14,7 @@ const PublishSidebarToggle = function( { onToggle, isEnabled } ) { role="menuitemcheckbox" onClick={ onToggle } > - { __( 'Publish Sidebar' ) } + { __( 'Show publish confirmation' ) } ); }; diff --git a/packages/editor/src/components/post-publish-panel/index.js b/packages/editor/src/components/post-publish-panel/index.js index d53a207165643c..edd623011dadc2 100644 --- a/packages/editor/src/components/post-publish-panel/index.js +++ b/packages/editor/src/components/post-publish-panel/index.js @@ -99,8 +99,8 @@ class PostPublishPanel extends Component {
From 18036e2f9efca230f402dbfd7e9a3be770951fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 12 Sep 2018 09:32:04 +0200 Subject: [PATCH 19/30] Update copy --- edit-post/components/header/publish-sidebar-toggle/index.js | 2 +- packages/editor/src/components/post-publish-panel/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/edit-post/components/header/publish-sidebar-toggle/index.js b/edit-post/components/header/publish-sidebar-toggle/index.js index 5effd7a654b4a9..4bc32288e2d850 100644 --- a/edit-post/components/header/publish-sidebar-toggle/index.js +++ b/edit-post/components/header/publish-sidebar-toggle/index.js @@ -14,7 +14,7 @@ const PublishSidebarToggle = function( { onToggle, isEnabled } ) { role="menuitemcheckbox" onClick={ onToggle } > - { __( 'Show publish confirmation' ) } + { __( 'Enable pre-publish checks' ) } ); }; diff --git a/packages/editor/src/components/post-publish-panel/index.js b/packages/editor/src/components/post-publish-panel/index.js index edd623011dadc2..3fe5d07c49c6b0 100644 --- a/packages/editor/src/components/post-publish-panel/index.js +++ b/packages/editor/src/components/post-publish-panel/index.js @@ -99,7 +99,7 @@ class PostPublishPanel extends Component {
From c37b6a871de3bacd028e93c75a236acfa5b770c9 Mon Sep 17 00:00:00 2001 From: sarah Date: Wed, 12 Sep 2018 08:40:42 +0100 Subject: [PATCH 20/30] Tweak microcopy for pre-publish checks. --- edit-post/components/header/publish-sidebar-toggle/index.js | 2 +- packages/editor/src/components/post-publish-panel/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/edit-post/components/header/publish-sidebar-toggle/index.js b/edit-post/components/header/publish-sidebar-toggle/index.js index 4bc32288e2d850..49b3c36ab8356f 100644 --- a/edit-post/components/header/publish-sidebar-toggle/index.js +++ b/edit-post/components/header/publish-sidebar-toggle/index.js @@ -14,7 +14,7 @@ const PublishSidebarToggle = function( { onToggle, isEnabled } ) { role="menuitemcheckbox" onClick={ onToggle } > - { __( 'Enable pre-publish checks' ) } + { __( 'Enable Pre-publish Checks' ) } ); }; diff --git a/packages/editor/src/components/post-publish-panel/index.js b/packages/editor/src/components/post-publish-panel/index.js index 3fe5d07c49c6b0..f4b7248d8a7154 100644 --- a/packages/editor/src/components/post-publish-panel/index.js +++ b/packages/editor/src/components/post-publish-panel/index.js @@ -99,7 +99,7 @@ class PostPublishPanel extends Component {
From d1c69c52c57d7bcd76b3932e437fe3a16ad608cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Thu, 13 Sep 2018 09:53:06 +0200 Subject: [PATCH 21/30] Remove outdated docs These data has been moved to edit-post store as per https://github.com/WordPress/gutenberg/pull/4661 --- packages/editor/src/store/reducer.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/editor/src/store/reducer.js b/packages/editor/src/store/reducer.js index bc0de8e1cb572d..fbca6f70ad976d 100644 --- a/packages/editor/src/store/reducer.js +++ b/packages/editor/src/store/reducer.js @@ -773,9 +773,6 @@ export function settings( state = EDITOR_SETTINGS_DEFAULTS, action ) { * Reducer returning the user preferences. * * @param {Object} state Current state. - * @param {string} state.mode Current editor mode, either "visual" or "text". - * @param {boolean} state.isSidebarOpened Whether the sidebar is opened or closed. - * @param {Object} state.panels The state of the different sidebar panels. * @param {Object} action Dispatched action. * * @return {string} Updated state. From 1be0b54b96d2db57d1b9ff09d845e418d0d78a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 14 Sep 2018 18:32:15 +0200 Subject: [PATCH 22/30] Preventive measure In theory, isPublishSidebarEnabled shouldn't be ever undefined in the preferences object, so this shouldn't be necessary. In practice, we use a localStorage mechanism to persist parts of the state in between sessions (like whether the user has already seen the tips or not). For the core/editor store we persist the preferences key, which contains an object. This is the problem: the localStorage mechanism doesn't check whether the cached preferences object and the state preferences object have the same shape, it just overwrites the current state, so new added keys are deleted. While this bug is not fixed and deployed, we want this preventive measure in place. --- packages/editor/src/store/selectors.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index d4169ec9f4721d..dda8574cd2e82d 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -27,6 +27,11 @@ import { serialize, getBlockType, getBlockTypes, hasBlockSupport, hasChildBlocks import { moment } from '@wordpress/date'; import { removep } from '@wordpress/autop'; +/** + * Dependencies + */ +import { PREFERENCES_DEFAULTS } from './defaults'; + /*** * Module constants */ @@ -1889,5 +1894,5 @@ export function canUserUseUnfilteredHTML( state ) { * @return {boolean} Whether the pre-publish panel should be shown or not. */ export function isPublishSidebarEnabled( state ) { - return state.preferences.isPublishSidebarEnabled; + return state.preferences.isPublishSidebarEnabled || PREFERENCES_DEFAULTS.isPublishSidebarEnabled; } From 79ced0118af7bf3358ff4249b0d1f680996590a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 14 Sep 2018 19:04:21 +0200 Subject: [PATCH 23/30] Fix and add tests --- packages/editor/src/store/selectors.js | 5 +++- packages/editor/src/store/test/selectors.js | 29 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index dda8574cd2e82d..10068aadf3609f 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1894,5 +1894,8 @@ export function canUserUseUnfilteredHTML( state ) { * @return {boolean} Whether the pre-publish panel should be shown or not. */ export function isPublishSidebarEnabled( state ) { - return state.preferences.isPublishSidebarEnabled || PREFERENCES_DEFAULTS.isPublishSidebarEnabled; + if ( state.preferences.hasOwnProperty( 'isPublishSidebarEnabled' ) ) { + return state.preferences.isPublishSidebarEnabled; + } + return PREFERENCES_DEFAULTS.isPublishSidebarEnabled; } diff --git a/packages/editor/src/store/test/selectors.js b/packages/editor/src/store/test/selectors.js index 60bde150d492ab..9b88a450c763c9 100644 --- a/packages/editor/src/store/test/selectors.js +++ b/packages/editor/src/store/test/selectors.js @@ -13,6 +13,7 @@ import { moment } from '@wordpress/date'; * Internal dependencies */ import * as selectors from '../selectors'; +import { PREFERENCES_DEFAULTS } from '../defaults'; const { canUserUseUnfilteredHTML, @@ -82,6 +83,7 @@ const { getReusableBlocks, getStateBeforeOptimisticTransaction, isPublishingPost, + isPublishSidebarEnabled, canInsertBlockType, getInserterItems, isValidTemplate, @@ -3387,6 +3389,33 @@ describe( 'selectors', () => { } ); } ); + describe( 'isPublishSidebarEnabled', () => { + it( 'should return the value on state if it is thruthy', () => { + const state = { + preferences: { + isPublishSidebarEnabled: true, + }, + }; + expect( isPublishSidebarEnabled( state ) ).toBe( state.preferences.isPublishSidebarEnabled ); + } ); + + it( 'should return the value on state if it is falsy', () => { + const state = { + preferences: { + isPublishSidebarEnabled: false, + }, + }; + expect( isPublishSidebarEnabled( state ) ).toBe( state.preferences.isPublishSidebarEnabled ); + } ); + + it( 'should return the default value if there is no isPublishSidebarEnabled key on state', () => { + const state = { + preferences: { }, + }; + expect( isPublishSidebarEnabled( state ) ).toBe( PREFERENCES_DEFAULTS.isPublishSidebarEnabled ); + } ); + } ); + describe( 'isFetchingReusableBlock', () => { it( 'should return false when the block is not being fetched', () => { const state = { From 78ebeeca0d65ab72b9c3bb949665fea74af082c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Mon, 17 Sep 2018 14:05:32 +0200 Subject: [PATCH 24/30] Add e2e test --- test/e2e/specs/publishing.test.js | 42 +++++++++++++++++++++++++++++++ test/e2e/support/utils.js | 17 +++++++++++++ 2 files changed, 59 insertions(+) diff --git a/test/e2e/specs/publishing.test.js b/test/e2e/specs/publishing.test.js index 0eed46e1e4c1bb..19a7e106d8b3b3 100644 --- a/test/e2e/specs/publishing.test.js +++ b/test/e2e/specs/publishing.test.js @@ -4,6 +4,8 @@ import { newPost, publishPost, + publishPostWithoutPrePublishChecks, + disablePrePublishChecks, } from '../support/utils'; describe( 'Publishing', () => { @@ -28,6 +30,26 @@ describe( 'Publishing', () => { } ); } ); + describe( 'a post when pre-publish checks are disabled', () => { + beforeEach( async () => { + await newPost(); + await disablePrePublishChecks(); + } ); + + it( 'should publish it without opening the post-publish sidebar.', async () => { + await page.type( '.editor-post-title__input', 'E2E Test Post' ); + + // The "Publish" button should be shown instead of the "Publish..." toggle + expect( await page.$( '.editor-post-publish-panel__toggle' ) ).toBeNull(); + expect( await page.$( '.editor-post-publish-button' ) ).not.toBeNull(); + + await publishPostWithoutPrePublishChecks(); + + // The post-publishing panel should have been not shown. + expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull(); + } ); + } ); + describe( 'a page', () => { beforeEach( async () => { await newPost( 'page' ); @@ -48,4 +70,24 @@ describe( 'Publishing', () => { expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull(); } ); } ); + + describe( 'a page when pre-publish checks are disabled', () => { + beforeEach( async () => { + await newPost( 'page' ); + await disablePrePublishChecks(); + } ); + + it( 'should publish it without opening the post-publish sidebar', async () => { + await page.type( '.editor-post-title__input', 'E2E Test Page' ); + + // The "Publish" button should be shown instead of the "Publish..." toggle + expect( await page.$( '.editor-post-publish-panel__toggle' ) ).toBeNull(); + expect( await page.$( '.editor-post-publish-button' ) ).not.toBeNull(); + + await publishPostWithoutPrePublishChecks(); + + // The post-publishing panel should have been not shown. + expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull(); + } ); + } ); } ); diff --git a/test/e2e/support/utils.js b/test/e2e/support/utils.js index ea162ed86df7fb..ef0b572f645d01 100644 --- a/test/e2e/support/utils.js +++ b/test/e2e/support/utils.js @@ -136,6 +136,12 @@ export async function newPost( { postType, enableTips = false } = {} ) { } } +export async function disablePrePublishChecks( ) { + await page.click( '.edit-post-more-menu' ); + await page.waitForSelector( '.components-popover__content' ); + await page.click( '.components-popover__content > .components-menu-group:nth-child(3) button:nth-child(3)' ); +} + export async function setViewport( type ) { const allowedDimensions = { large: { width: 960, height: 700 }, @@ -294,6 +300,17 @@ export async function publishPost() { return page.waitForSelector( '.components-notice.is-success' ); } +/** + * Publishes the post without the pre-publish checks, + * resolving once the request is complete (once a notice is displayed). + * + * @return {Promise} Promise resolving when publish is complete. + */ +export async function publishPostWithoutPrePublishChecks() { + await page.click( '.editor-post-publish-button' ); + return page.waitForSelector( '.components-notice.is-success' ); +} + /** * Saves the post as a draft, resolving once the request is complete (once the * "Saved" indicator is displayed). From 87b372d08c2d5ae5bc31e21eda5e6704702be46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Mon, 17 Sep 2018 14:15:43 +0200 Subject: [PATCH 25/30] Refactor code to avoid duplication --- test/e2e/specs/publishing.test.js | 97 ++++++++++--------------------- 1 file changed, 30 insertions(+), 67 deletions(-) diff --git a/test/e2e/specs/publishing.test.js b/test/e2e/specs/publishing.test.js index 19a7e106d8b3b3..e628ef87075844 100644 --- a/test/e2e/specs/publishing.test.js +++ b/test/e2e/specs/publishing.test.js @@ -9,85 +9,48 @@ import { } from '../support/utils'; describe( 'Publishing', () => { - describe( 'a post', () => { - beforeEach( async () => { - await newPost(); - } ); - - it( 'should publish a post and close the panel once we start editing again', async () => { - await page.type( '.editor-post-title__input', 'E2E Test Post' ); - - await publishPost(); - - // The post-publishing panel is visible. - expect( await page.$( '.editor-post-publish-panel' ) ).not.toBeNull(); - - // Start editing again. - await page.type( '.editor-post-title__input', ' (Updated)' ); + [ 'post', 'page' ].forEach( ( postType ) => { + describe( `a ${ postType }`, () => { + beforeEach( async () => { + await newPost( postType ); + } ); - // The post-publishing panel is not visible anymore. - expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull(); - } ); - } ); + it( `should publish the ${ postType } and close the panel once we start editing again.`, async () => { + await page.type( '.editor-post-title__input', 'E2E Test Post' ); - describe( 'a post when pre-publish checks are disabled', () => { - beforeEach( async () => { - await newPost(); - await disablePrePublishChecks(); - } ); + await publishPost(); - it( 'should publish it without opening the post-publish sidebar.', async () => { - await page.type( '.editor-post-title__input', 'E2E Test Post' ); + // The post-publishing panel is visible. + expect( await page.$( '.editor-post-publish-panel' ) ).not.toBeNull(); - // The "Publish" button should be shown instead of the "Publish..." toggle - expect( await page.$( '.editor-post-publish-panel__toggle' ) ).toBeNull(); - expect( await page.$( '.editor-post-publish-button' ) ).not.toBeNull(); + // Start editing again. + await page.type( '.editor-post-title__input', ' (Updated)' ); - await publishPostWithoutPrePublishChecks(); - - // The post-publishing panel should have been not shown. - expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull(); + // The post-publishing panel is not visible anymore. + expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull(); + } ); } ); } ); - describe( 'a page', () => { - beforeEach( async () => { - await newPost( 'page' ); - } ); - - it( 'should publish a page and close the panel once we start editing again', async () => { - await page.type( '.editor-post-title__input', 'E2E Test Page' ); - - await publishPost(); - - // The post-publishing panel is visible. - expect( await page.$( '.editor-post-publish-panel' ) ).not.toBeNull(); - - // Start editing the page again. - await page.type( '.editor-post-title__input', ' (Updated)' ); - - // The post-publishing panel is not visible anymore. - expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull(); - } ); - } ); - - describe( 'a page when pre-publish checks are disabled', () => { - beforeEach( async () => { - await newPost( 'page' ); - await disablePrePublishChecks(); - } ); + [ 'post', 'page' ].forEach( ( postType ) => { + describe( `a ${ postType } with pre-publish checks disabled`, () => { + beforeEach( async () => { + await newPost( postType ); + await disablePrePublishChecks(); + } ); - it( 'should publish it without opening the post-publish sidebar', async () => { - await page.type( '.editor-post-title__input', 'E2E Test Page' ); + it( `should publish the ${ postType } without opening the post-publish sidebar.`, async () => { + await page.type( '.editor-post-title__input', 'E2E Test Post' ); - // The "Publish" button should be shown instead of the "Publish..." toggle - expect( await page.$( '.editor-post-publish-panel__toggle' ) ).toBeNull(); - expect( await page.$( '.editor-post-publish-button' ) ).not.toBeNull(); + // The "Publish" button should be shown instead of the "Publish..." toggle + expect( await page.$( '.editor-post-publish-panel__toggle' ) ).toBeNull(); + expect( await page.$( '.editor-post-publish-button' ) ).not.toBeNull(); - await publishPostWithoutPrePublishChecks(); + await publishPostWithoutPrePublishChecks(); - // The post-publishing panel should have been not shown. - expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull(); + // The post-publishing panel should have been not shown. + expect( await page.$( '.editor-post-publish-panel' ) ).toBeNull(); + } ); } ); } ); } ); From acffe703e601b6efcec6b499f2cdb2765928cb63 Mon Sep 17 00:00:00 2001 From: Matthew Riley MacPherson Date: Tue, 18 Sep 2018 18:18:25 +0100 Subject: [PATCH 26/30] chore: Tweak styles --- edit-post/components/header/index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/edit-post/components/header/index.js b/edit-post/components/header/index.js index 5e3ec6843ef116..8c74fda38e9ced 100644 --- a/edit-post/components/header/index.js +++ b/edit-post/components/header/index.js @@ -50,18 +50,19 @@ function Header( { forceIsSaving={ isSaving } /> - { isPublishSidebarEnabled ? - ( ) : - ( + ) : ( + ) - } + /> + ) }
Date: Wed, 19 Sep 2018 10:01:50 +0200 Subject: [PATCH 27/30] Disable pre-publish checks after test --- test/e2e/specs/publishing.test.js | 8 ++++++-- test/e2e/support/utils.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/e2e/specs/publishing.test.js b/test/e2e/specs/publishing.test.js index e628ef87075844..860de7ed9237d9 100644 --- a/test/e2e/specs/publishing.test.js +++ b/test/e2e/specs/publishing.test.js @@ -5,7 +5,7 @@ import { newPost, publishPost, publishPostWithoutPrePublishChecks, - disablePrePublishChecks, + togglePrePublishChecks, } from '../support/utils'; describe( 'Publishing', () => { @@ -36,7 +36,11 @@ describe( 'Publishing', () => { describe( `a ${ postType } with pre-publish checks disabled`, () => { beforeEach( async () => { await newPost( postType ); - await disablePrePublishChecks(); + await togglePrePublishChecks(); + } ); + + afterEach( async () => { + await togglePrePublishChecks(); } ); it( `should publish the ${ postType } without opening the post-publish sidebar.`, async () => { diff --git a/test/e2e/support/utils.js b/test/e2e/support/utils.js index ef0b572f645d01..5539ba1f8ed793 100644 --- a/test/e2e/support/utils.js +++ b/test/e2e/support/utils.js @@ -136,7 +136,7 @@ export async function newPost( { postType, enableTips = false } = {} ) { } } -export async function disablePrePublishChecks( ) { +export async function togglePrePublishChecks( ) { await page.click( '.edit-post-more-menu' ); await page.waitForSelector( '.components-popover__content' ); await page.click( '.components-popover__content > .components-menu-group:nth-child(3) button:nth-child(3)' ); From 6637b7e59ca4014d4fe57ad8101dbc5f6a6edc69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 19 Sep 2018 10:33:10 +0200 Subject: [PATCH 28/30] Add enable/disable functions --- test/e2e/specs/publishing.test.js | 12 +++++++++--- test/e2e/support/utils.js | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/test/e2e/specs/publishing.test.js b/test/e2e/specs/publishing.test.js index 860de7ed9237d9..b2caee790d27b4 100644 --- a/test/e2e/specs/publishing.test.js +++ b/test/e2e/specs/publishing.test.js @@ -5,7 +5,8 @@ import { newPost, publishPost, publishPostWithoutPrePublishChecks, - togglePrePublishChecks, + enablePrePublishChecks, + disablePrePublishChecks, } from '../support/utils'; describe( 'Publishing', () => { @@ -13,6 +14,11 @@ describe( 'Publishing', () => { describe( `a ${ postType }`, () => { beforeEach( async () => { await newPost( postType ); + await enablePrePublishChecks(); + } ); + + afterEach( async () => { + await disablePrePublishChecks(); } ); it( `should publish the ${ postType } and close the panel once we start editing again.`, async () => { @@ -36,11 +42,11 @@ describe( 'Publishing', () => { describe( `a ${ postType } with pre-publish checks disabled`, () => { beforeEach( async () => { await newPost( postType ); - await togglePrePublishChecks(); + await disablePrePublishChecks(); } ); afterEach( async () => { - await togglePrePublishChecks(); + await enablePrePublishChecks(); } ); it( `should publish the ${ postType } without opening the post-publish sidebar.`, async () => { diff --git a/test/e2e/support/utils.js b/test/e2e/support/utils.js index 5539ba1f8ed793..7814ac13251259 100644 --- a/test/e2e/support/utils.js +++ b/test/e2e/support/utils.js @@ -142,6 +142,22 @@ export async function togglePrePublishChecks( ) { await page.click( '.components-popover__content > .components-menu-group:nth-child(3) button:nth-child(3)' ); } +export async function arePrePublishChecksEnabled( ) { + return page.evaluate( () => window.wp.data.select( 'core/editor' ).isPublishSidebarEnabled() ); +} + +export async function enablePrePublishChecks( ) { + if ( ! await arePrePublishChecksEnabled( ) ) { + await togglePrePublishChecks(); + } +} + +export async function disablePrePublishChecks( ) { + if ( await arePrePublishChecksEnabled( ) ) { + await togglePrePublishChecks(); + } +} + export async function setViewport( type ) { const allowedDimensions = { large: { width: 960, height: 700 }, From d7c715149a703aceb228404cebf039f8b56392d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 19 Sep 2018 11:11:24 +0200 Subject: [PATCH 29/30] Use specific selector to target pre-publish checks menu item --- edit-post/components/header/publish-sidebar-toggle/index.js | 1 + test/e2e/support/utils.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/edit-post/components/header/publish-sidebar-toggle/index.js b/edit-post/components/header/publish-sidebar-toggle/index.js index 49b3c36ab8356f..b3949ec866b954 100644 --- a/edit-post/components/header/publish-sidebar-toggle/index.js +++ b/edit-post/components/header/publish-sidebar-toggle/index.js @@ -9,6 +9,7 @@ import { withSelect, withDispatch } from '@wordpress/data'; const PublishSidebarToggle = function( { onToggle, isEnabled } ) { return ( .components-menu-group:nth-child(3) button:nth-child(3)' ); + await page.click( '.edit-post__pre-publish-checks' ); } export async function arePrePublishChecksEnabled( ) { From b50ca1de85ac57e4f4f09075ef21a616bbabeeb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 19 Sep 2018 11:27:47 +0200 Subject: [PATCH 30/30] Do not make assumptions about previous states --- test/e2e/specs/publishing.test.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/test/e2e/specs/publishing.test.js b/test/e2e/specs/publishing.test.js index b2caee790d27b4..31265b35ece7a1 100644 --- a/test/e2e/specs/publishing.test.js +++ b/test/e2e/specs/publishing.test.js @@ -7,18 +7,25 @@ import { publishPostWithoutPrePublishChecks, enablePrePublishChecks, disablePrePublishChecks, + arePrePublishChecksEnabled, } from '../support/utils'; describe( 'Publishing', () => { [ 'post', 'page' ].forEach( ( postType ) => { + let werePrePublishChecksEnabled; describe( `a ${ postType }`, () => { beforeEach( async () => { await newPost( postType ); - await enablePrePublishChecks(); + werePrePublishChecksEnabled = await arePrePublishChecksEnabled(); + if ( ! werePrePublishChecksEnabled ) { + await enablePrePublishChecks(); + } } ); afterEach( async () => { - await disablePrePublishChecks(); + if ( ! werePrePublishChecksEnabled ) { + await disablePrePublishChecks(); + } } ); it( `should publish the ${ postType } and close the panel once we start editing again.`, async () => { @@ -39,14 +46,20 @@ describe( 'Publishing', () => { } ); [ 'post', 'page' ].forEach( ( postType ) => { + let werePrePublishChecksEnabled; describe( `a ${ postType } with pre-publish checks disabled`, () => { beforeEach( async () => { await newPost( postType ); - await disablePrePublishChecks(); + werePrePublishChecksEnabled = await arePrePublishChecksEnabled(); + if ( werePrePublishChecksEnabled ) { + await disablePrePublishChecks(); + } } ); afterEach( async () => { - await enablePrePublishChecks(); + if ( werePrePublishChecksEnabled ) { + await enablePrePublishChecks(); + } } ); it( `should publish the ${ postType } without opening the post-publish sidebar.`, async () => {