-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to skip PublishSidebar on publishing #9760
Changes from 26 commits
b7cc241
e3f0c24
85edadc
0488595
14ea423
f4c237e
1a00c13
c659529
e888220
b3e9fa8
f78a332
3e2877f
dbd6090
ea5dc6a
afae18d
2f45e20
7bfc2a5
c65ea7c
18036e2
c37b6a8
d1c69c5
1be0b54
79ced01
78ebeec
87b372d
acffe70
37900cc
6637b7e
d7c7151
b50ca1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { MenuItem } from '@wordpress/components'; | ||
import { compose } from '@wordpress/compose'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
|
||
const PublishSidebarToggle = function( { onToggle, isEnabled } ) { | ||
return ( | ||
<MenuItem | ||
icon={ isEnabled && 'yes' } | ||
tofumatt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isSelected={ isEnabled } | ||
role="menuitemcheckbox" | ||
onClick={ onToggle } | ||
> | ||
{ __( 'Enable Pre-publish Checks' ) } | ||
</MenuItem> | ||
); | ||
}; | ||
|
||
export default compose( [ | ||
withSelect( ( select ) => ( { | ||
isEnabled: select( 'core/editor' ).isPublishSidebarEnabled(), | ||
} ) ), | ||
withDispatch( ( dispatch, ownProps ) => ( { | ||
onToggle() { | ||
const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/editor' ); | ||
if ( ownProps.isEnabled ) { | ||
disablePublishSidebar(); | ||
} else { | ||
enablePublishSidebar(); | ||
} | ||
ownProps.onToggle(); | ||
}, | ||
} ) ), | ||
] )( PublishSidebarToggle ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ( | ||
<div className="editor-post-publish-panel" { ...additionalProps }> | ||
|
@@ -97,6 +97,13 @@ class PostPublishPanel extends Component { | |
</PostPublishPanelPostpublish> | ||
) } | ||
</div> | ||
<div className="editor-post-publish-panel__footer"> | ||
<CheckboxControl | ||
label={ __( 'Always show pre-publish checks.' ) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Putting the word "this" inside this text might help contextualise this more.
might help users understand it more. If it doesn't look too cramped I say go with that, but if it's already a tight space feel free to leave it as-is. |
||
checked={ isPublishSidebarEnabled } | ||
onChange={ onTogglePublishSidebar } | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
@@ -112,13 +119,27 @@ export default compose( [ | |
isSavingPost, | ||
isEditedPostDirty, | ||
} = select( 'core/editor' ); | ||
const { isPublishSidebarEnabled } = select( 'core/editor' ); | ||
return { | ||
postType: getCurrentPostType(), | ||
hasPublishAction: get( getCurrentPost(), [ '_links', 'wp:action-publish' ], false ), | ||
isPublished: isCurrentPostPublished(), | ||
isScheduled: isCurrentPostScheduled(), | ||
isSaving: isSavingPost(), | ||
isDirty: isEditedPostDirty(), | ||
isPublishSidebarEnabled: isPublishSidebarEnabled(), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, { isPublishSidebarEnabled } ) => { | ||
const { disablePublishSidebar, enablePublishSidebar } = dispatch( 'core/editor' ); | ||
return { | ||
onTogglePublishSidebar: ( ) => { | ||
if ( isPublishSidebarEnabled ) { | ||
disablePublishSidebar(); | ||
} else { | ||
enablePublishSidebar(); | ||
} | ||
}, | ||
}; | ||
} ), | ||
] )( PostPublishPanel ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I originally added the enable/disable logic to the An alternative approach could have been to keep the logic in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there another alternative to consider where the publish panel makes more sense in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wish we'd taken a more generalized approach akin to |
||
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', | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -810,6 +807,18 @@ export function preferences( state = PREFERENCES_DEFAULTS, action ) { | |
...state, | ||
insertUsage: omitBy( state.insertUsage, ( { insert } ) => insert.ref === action.id ), | ||
}; | ||
|
||
case 'ENABLE_PUBLISH_SIDEBAR': | ||
return { | ||
...state, | ||
isPublishSidebarEnabled: true, | ||
}; | ||
|
||
case 'DISABLE_PUBLISH_SIDEBAR': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get that this is technically less code but I think it's nicer to have each action type return its own object. It's easier to grok what's happening that way–this code made sense to me but only after I looked at it for probably ten seconds; I was wondering why case 'ENABLE_PUBLISH_SIDEBAR':
return {
...state,
isPublishSidebarEnabled: true,
};
case 'DISABLE_PUBLISH_SIDEBAR':
return {
…state,
isPublishSidebarEnabled: false,
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for keeping us obvious. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return { | ||
...state, | ||
isPublishSidebarEnabled: false, | ||
}; | ||
} | ||
|
||
return state; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1580,9 +1580,28 @@ describe( 'state', () => { | |
|
||
expect( state ).toEqual( { | ||
insertUsage: {}, | ||
isPublishSidebarEnabled: true, | ||
} ); | ||
} ); | ||
|
||
it( 'should disable the publish sidebar', () => { | ||
const original = deepFreeze( preferences( undefined, { } ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
https://make.wordpress.org/core/handbook/best-practices/coding-standards/javascript/#spacing Need to find if possible to enforce by ESLint. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's unrelated to this PR, but the
onClose
method being used foronToggle
several times andonSelect
below makes me think it should be renamed tocloseMenu
or something. 🤷♂️