Skip to content

Commit 28262d2

Browse files
committed
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.
1 parent 9351e3f commit 28262d2

File tree

12 files changed

+66
-67
lines changed

12 files changed

+66
-67
lines changed

edit-post/components/header/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default compose(
8181
withSelect( ( select ) => ( {
8282
isEditorSidebarOpened: select( 'core/edit-post' ).isEditorSidebarOpened(),
8383
isPublishSidebarOpened: select( 'core/edit-post' ).isPublishSidebarOpened(),
84-
isPublishSidebarEnabled: select( 'core/edit-post' ).isPublishSidebarEnabled(),
84+
isPublishSidebarEnabled: select( 'core/editor' ).isPublishSidebarEnabled(),
8585
hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(),
8686
isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(),
8787
hasBlockSelection: !! select( 'core/editor' ).getBlockSelectionStart(),

edit-post/components/header/publish-sidebar-toggle/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ const PublishSidebarToggle = function( { onToggle, isEnabled } ) {
2121

2222
export default compose( [
2323
withSelect( ( select ) => ( {
24-
isEnabled: select( 'core/edit-post' ).isPublishSidebarEnabled(),
24+
isEnabled: select( 'core/editor' ).isPublishSidebarEnabled(),
2525
} ) ),
2626
withDispatch( ( dispatch, ownProps ) => ( {
2727
onToggle() {
28-
const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/edit-post' );
28+
const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/editor' );
2929
if ( ownProps.isEnabled ) {
3030
disablePublishSidebar();
3131
} else {

edit-post/store/actions.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,6 @@ export function togglePublishSidebar() {
8383
};
8484
}
8585

86-
/**
87-
* Returns an action object used in signalling that the user has enabled the publish sidebar.
88-
*
89-
* @return {Object} Action object
90-
*/
91-
export function enablePublishSidebar() {
92-
return {
93-
type: 'ENABLE_PUBLISH_SIDEBAR',
94-
};
95-
}
96-
97-
/**
98-
* Returns an action object used in signalling that the user has disabled the publish sidebar.
99-
*
100-
* @return {Object} Action object
101-
*/
102-
export function disablePublishSidebar() {
103-
return {
104-
type: 'DISABLE_PUBLISH_SIDEBAR',
105-
};
106-
}
107-
10886
/**
10987
* Returns an action object used in signalling that use toggled a panel in the editor.
11088
*

edit-post/store/reducer.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,6 @@ export const preferences = combineReducers( {
4949

5050
return state;
5151
},
52-
isPublishSidebarEnabled( state = true, action ) {
53-
switch ( action.type ) {
54-
case 'ENABLE_PUBLISH_SIDEBAR':
55-
case 'DISABLE_PUBLISH_SIDEBAR':
56-
return action.type === 'ENABLE_PUBLISH_SIDEBAR';
57-
}
58-
59-
return state;
60-
},
6152
panels( state = PREFERENCES_DEFAULTS.panels, action ) {
6253
if ( action.type === 'TOGGLE_GENERAL_SIDEBAR_EDITOR_PANEL' ) {
6354
return {

edit-post/store/selectors.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@ export function getEditorMode( state ) {
1515
return getPreference( state, 'editorMode', 'visual' );
1616
}
1717

18-
/**
19-
* Returns whether the pre-publish panel show be shown
20-
* or hidden on publish.
21-
*
22-
* @param {Object} state Global application state.
23-
*
24-
* @return {boolean} Whether the pre-publish panel should be shown or not.
25-
*/
26-
export function isPublishSidebarEnabled( state ) {
27-
return getPreference( state, 'isPublishSidebarEnabled', true );
28-
}
29-
3018
/**
3119
* Returns true if the editor sidebar is opened.
3220
*

edit-post/store/test/reducer.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ describe( 'state', () => {
2323
expect( state ).toEqual( {
2424
editorMode: 'visual',
2525
isGeneralSidebarDismissed: false,
26-
isPublishSidebarEnabled: true,
2726
panels: { 'post-status': true },
2827
features: { fixedToolbar: false },
2928
pinnedPluginItems: {},
@@ -52,24 +51,6 @@ describe( 'state', () => {
5251
expect( state.isGeneralSidebarDismissed ).toBe( true );
5352
} );
5453

55-
it( 'should disable the publish sidebar', () => {
56-
const original = deepFreeze( preferences( undefined, { } ) );
57-
const state = preferences( original, {
58-
type: 'DISABLE_PUBLISH_SIDEBAR',
59-
} );
60-
61-
expect( state.isPublishSidebarEnabled ).toBe( false );
62-
} );
63-
64-
it( 'should enable the publish sidebar', () => {
65-
const original = deepFreeze( preferences( { isPublishSidebarEnabled: false }, { } ) );
66-
const state = preferences( original, {
67-
type: 'ENABLE_PUBLISH_SIDEBAR',
68-
} );
69-
70-
expect( state.isPublishSidebarEnabled ).toBe( true );
71-
} );
72-
7354
it( 'should set the sidebar panel open flag to true if unset', () => {
7455
const state = preferences( deepFreeze( { panels: {} } ), {
7556
type: 'TOGGLE_GENERAL_SIDEBAR_EDITOR_PANEL',

packages/editor/src/components/post-publish-panel/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default compose( [
117117
isSavingPost,
118118
isEditedPostDirty,
119119
} = select( 'core/editor' );
120-
const { isPublishSidebarEnabled } = select( 'core/edit-post' );
120+
const { isPublishSidebarEnabled } = select( 'core/editor' );
121121
return {
122122
postType: getCurrentPostType(),
123123
hasPublishAction: get( getCurrentPost(), [ '_links', 'wp:action-publish' ], false ),
@@ -129,7 +129,7 @@ export default compose( [
129129
};
130130
} ),
131131
withDispatch( ( dispatch, { isPublishSidebarEnabled } ) => {
132-
const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/edit-post' );
132+
const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/editor' );
133133
return {
134134
onTogglePublishSidebar: ( ) => {
135135
if ( isPublishSidebarEnabled ) {

packages/editor/src/store/actions.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,3 +763,25 @@ export function unregisterToken( name ) {
763763
name,
764764
};
765765
}
766+
767+
/**
768+
* Returns an action object used in signalling that the user has enabled the publish sidebar.
769+
*
770+
* @return {Object} Action object
771+
*/
772+
export function enablePublishSidebar() {
773+
return {
774+
type: 'ENABLE_PUBLISH_SIDEBAR',
775+
};
776+
}
777+
778+
/**
779+
* Returns an action object used in signalling that the user has disabled the publish sidebar.
780+
*
781+
* @return {Object} Action object
782+
*/
783+
export function disablePublishSidebar() {
784+
return {
785+
type: 'DISABLE_PUBLISH_SIDEBAR',
786+
};
787+
}

packages/editor/src/store/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n';
55

66
export const PREFERENCES_DEFAULTS = {
77
insertUsage: {},
8+
isPublishSidebarEnabled: true,
89
};
910

1011
/**

packages/editor/src/store/reducer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,13 @@ export function preferences( state = PREFERENCES_DEFAULTS, action ) {
810810
...state,
811811
insertUsage: omitBy( state.insertUsage, ( { insert } ) => insert.ref === action.id ),
812812
};
813+
814+
case 'ENABLE_PUBLISH_SIDEBAR':
815+
case 'DISABLE_PUBLISH_SIDEBAR':
816+
return {
817+
...state,
818+
isPublishSidebarEnabled: action.type === 'ENABLE_PUBLISH_SIDEBAR',
819+
};
813820
}
814821

815822
return state;

0 commit comments

Comments
 (0)