Skip to content
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 disable support to PostStatus settings panel #17117

Merged
merged 5 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/e2e-tests/specs/sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ describe( 'Sidebar', () => {
expect( await findSidebarPanelWithTitle( 'Featured Image' ) ).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Excerpt' ) ).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Discussion' ) ).toBeDefined();
expect( await findSidebarPanelWithTitle( 'Status & Visibility' ) ).toBeDefined();

await page.evaluate( () => {
const { removeEditorPanel } = wp.data.dispatch( 'core/edit-post' );
Expand All @@ -124,12 +125,14 @@ describe( 'Sidebar', () => {
removeEditorPanel( 'featured-image' );
noahtallen marked this conversation as resolved.
Show resolved Hide resolved
removeEditorPanel( 'post-excerpt' );
removeEditorPanel( 'discussion-panel' );
removeEditorPanel( 'post-status' );
} );

expect( await findSidebarPanelWithTitle( 'Categories' ) ).toBeUndefined();
expect( await findSidebarPanelWithTitle( 'Tags' ) ).toBeUndefined();
expect( await findSidebarPanelWithTitle( 'Featured Image' ) ).toBeUndefined();
expect( await findSidebarPanelWithTitle( 'Excerpt' ) ).toBeUndefined();
expect( await findSidebarPanelWithTitle( 'Discussion' ) ).toBeUndefined();
expect( await findSidebarPanelWithTitle( 'Status & Visibility' ) ).toBeUndefined();
} );
} );
15 changes: 11 additions & 4 deletions packages/edit-post/src/components/sidebar/post-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { __ } from '@wordpress/i18n';
import { PanelBody } from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { compose, ifCondition } from '@wordpress/compose';
noahtallen marked this conversation as resolved.
Show resolved Hide resolved

/**
* Internal dependencies
Expand Down Expand Up @@ -45,9 +45,16 @@ function PostStatus( { isOpened, onTogglePanel } ) {
}

export default compose( [
withSelect( ( select ) => ( {
isOpened: select( 'core/edit-post' ).isEditorPanelOpened( PANEL_NAME ),
} ) ),
withSelect( ( select ) => {
// We use isEditorPanelRemoved to hide the panel if it was programatically removed. We do
// not use isEditorPanelEnabled since this panel should not be disabled through the UI.
const { isEditorPanelRemoved, isEditorPanelOpened } = select( 'core/edit-post' );
return {
isRemoved: isEditorPanelRemoved( PANEL_NAME ),
isOpened: isEditorPanelOpened( PANEL_NAME ),
};
} ),
ifCondition( ( { isRemoved } ) => ! isRemoved ),
withDispatch( ( dispatch ) => ( {
onTogglePanel() {
return dispatch( 'core/edit-post' ).toggleEditorPanelOpened( PANEL_NAME );
Expand Down