From 77f702cf55a76066eaada51701f50adea9cfbb47 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Thu, 27 Sep 2018 17:27:32 +0100 Subject: [PATCH] Implements an Options modal - Adds a basic Options modal to the More menu. - Moves the 'Enable Pre-publish Checks' and 'Show Tips' toggles to the new modal. - Allows the user to turn Document panels on or off. --- .../components/header/more-menu/index.js | 7 +- .../header/options-menu-item/index.js | 33 ++++ edit-post/components/layout/index.js | 2 + edit-post/components/options-modal/index.js | 179 ++++++++++++++++++ edit-post/components/options-modal/style.scss | 36 ++++ .../test/__snapshots__/index.js.snap | 58 ++++++ .../components/options-modal/test/index.js | 31 +++ .../sidebar/discussion-panel/index.js | 7 +- .../sidebar/featured-image/index.js | 9 +- .../components/sidebar/post-excerpt/index.js | 7 +- .../components/sidebar/post-status/index.js | 7 +- .../sidebar/post-taxonomies/taxonomy-panel.js | 10 +- edit-post/plugins/index.js | 4 - .../publish-sidebar-toggle-menu-item/index.js | 38 ---- .../plugins/tips-toggle-menu-item/index.js | 37 ---- edit-post/store/actions.js | 30 +++ edit-post/store/defaults.js | 1 + edit-post/store/reducer.js | 18 +- edit-post/store/selectors.js | 14 ++ edit-post/store/test/actions.js | 20 ++ edit-post/store/test/reducer.js | 33 ++++ edit-post/store/test/selectors.js | 25 +++ 22 files changed, 518 insertions(+), 88 deletions(-) create mode 100644 edit-post/components/header/options-menu-item/index.js create mode 100644 edit-post/components/options-modal/index.js create mode 100644 edit-post/components/options-modal/style.scss create mode 100644 edit-post/components/options-modal/test/__snapshots__/index.js.snap create mode 100644 edit-post/components/options-modal/test/index.js delete mode 100644 edit-post/plugins/publish-sidebar-toggle-menu-item/index.js delete mode 100644 edit-post/plugins/tips-toggle-menu-item/index.js diff --git a/edit-post/components/header/more-menu/index.js b/edit-post/components/header/more-menu/index.js index 3a3c7d10ba09bb..bf78fff1b4e82b 100644 --- a/edit-post/components/header/more-menu/index.js +++ b/edit-post/components/header/more-menu/index.js @@ -2,7 +2,7 @@ * WordPress dependencies */ import { _x } from '@wordpress/i18n'; -import { IconButton, Dropdown } from '@wordpress/components'; +import { IconButton, Dropdown, MenuGroup } from '@wordpress/components'; import { Fragment } from '@wordpress/element'; /** @@ -12,7 +12,7 @@ import './style.scss'; import ModeSwitcher from '../mode-switcher'; import PluginMoreMenuGroup from '../plugins-more-menu-group'; import ToolsMoreMenuGroup from '../tools-more-menu-group'; - +import OptionsMenuItem from '../options-menu-item'; import WritingMenu from '../writing-menu'; const MoreMenu = () => ( @@ -34,6 +34,9 @@ const MoreMenu = () => ( + + + ) } /> diff --git a/edit-post/components/header/options-menu-item/index.js b/edit-post/components/header/options-menu-item/index.js new file mode 100644 index 00000000000000..a9c246e770b43c --- /dev/null +++ b/edit-post/components/header/options-menu-item/index.js @@ -0,0 +1,33 @@ +/** + * WordPress Dependencies + */ +import { withDispatch } from '@wordpress/data'; + +/** + * WordPress Dependencies + */ +import { __ } from '@wordpress/i18n'; +import { MenuItem } from '@wordpress/components'; + +export function OptionsMenuItem( { openModal, onSelect } ) { + return ( + { + onSelect(); + openModal( 'edit-post/options' ); + } } + > + { __( 'Options' ) } + + ); +} + +export default withDispatch( ( dispatch, ) => { + const { + openModal, + } = dispatch( 'core/edit-post' ); + + return { + openModal, + }; +} )( OptionsMenuItem ); diff --git a/edit-post/components/layout/index.js b/edit-post/components/layout/index.js index 70a71b0898ead5..7be6f784d1cf15 100644 --- a/edit-post/components/layout/index.js +++ b/edit-post/components/layout/index.js @@ -34,6 +34,7 @@ import TextEditor from '../text-editor'; import VisualEditor from '../visual-editor'; import EditorModeKeyboardShortcuts from '../keyboard-shortcuts'; import KeyboardShortcutHelpModal from '../keyboard-shortcut-help-modal'; +import OptionsModal from '../options-modal'; import MetaBoxes from '../meta-boxes'; import { getMetaBoxContainer } from '../../utils/meta-boxes'; import Sidebar from '../sidebar'; @@ -90,6 +91,7 @@ function Layout( { + { mode === 'text' && } { mode === 'visual' && }
diff --git a/edit-post/components/options-modal/index.js b/edit-post/components/options-modal/index.js new file mode 100644 index 00000000000000..18dff6b90b444f --- /dev/null +++ b/edit-post/components/options-modal/index.js @@ -0,0 +1,179 @@ +/** + * WordPress dependencies + */ +import { Modal, CheckboxControl } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; +import { withSelect, withDispatch } from '@wordpress/data'; +import { compose } from '@wordpress/compose'; + +/** + * Internal dependencies + */ +import './style.scss'; + +const MODAL_NAME = 'edit-post/options'; + +const Section = ( { title, children } ) => ( +
+

+ { title } +

+ { children } +
+); + +export function OptionsModal( { + isModalActive, + toggleModal, + isPublishSidebarEnabled, + setIsPublishSidebarEnabled, + areTipsEnabled, + setAreTipsEnabled, + isStatusPanelEnabled, + setIsStatusPanelEnabled, + isCategoriesPanelEnabled, + setIsCategoriesPanelEnabled, + isTagsPanelEnabled, + setIsTagsPanelEnabled, + isFeaturedImagePanelEnabled, + setIsFeaturedImagePanelEnabled, + isExcerptPanelEnabled, + setIsExcerptPanelEnabled, + isDiscussionPanelEnabled, + setIsDiscussionPanelEnabled, +} ) { + if ( ! isModalActive ) { + return null; + } + + const title = ( + + { __( 'Options' ) } + + ); + + return ( + +
+ + +
+
+ + + + + + +
+
+ ); +} + +export default compose( [ + withSelect( ( select ) => { + const { isModalActive, isEditorSidebarPanelEnabled } = select( 'core/edit-post' ); + const { isPublishSidebarEnabled } = select( 'core/editor' ); + const { areTipsEnabled } = select( 'core/nux' ); + + return { + isModalActive: isModalActive( MODAL_NAME ), + isPublishSidebarEnabled: isPublishSidebarEnabled(), + areTipsEnabled: areTipsEnabled(), + isStatusPanelEnabled: isEditorSidebarPanelEnabled( 'post-status' ), + isCategoriesPanelEnabled: isEditorSidebarPanelEnabled( 'taxonomy-panel-category' ), + isTagsPanelEnabled: isEditorSidebarPanelEnabled( 'taxonomy-panel-post_tag' ), + isFeaturedImagePanelEnabled: isEditorSidebarPanelEnabled( 'featured-image' ), + isExcerptPanelEnabled: isEditorSidebarPanelEnabled( 'post-excerpt' ), + isDiscussionPanelEnabled: isEditorSidebarPanelEnabled( 'discussion-panel' ), + }; + } ), + withDispatch( ( dispatch, { isModalActive } ) => { + const { openModal, closeModal, enablePanel, disablePanel } = dispatch( 'core/edit-post' ); + const { enablePublishSidebar, disablePublishSidebar } = dispatch( 'core/editor' ); + const { enableTips, disableTips } = dispatch( 'core/nux' ); + + const buildSetIsPanelEnabled = ( panel ) => ( isEnabled ) => { + if ( isEnabled ) { + enablePanel( panel ); + } else { + disablePanel( panel ); + } + }; + + return { + toggleModal() { + if ( isModalActive ) { + closeModal(); + } else { + openModal( MODAL_NAME ); + } + }, + setIsPublishSidebarEnabled( isEnabled ) { + if ( isEnabled ) { + enablePublishSidebar(); + } else { + disablePublishSidebar(); + } + }, + setAreTipsEnabled( isEnabled ) { + if ( isEnabled ) { + enableTips(); + } else { + disableTips(); + } + }, + setIsStatusPanelEnabled: buildSetIsPanelEnabled( 'post-status' ), + setIsCategoriesPanelEnabled: buildSetIsPanelEnabled( 'taxonomy-panel-category' ), + setIsTagsPanelEnabled: buildSetIsPanelEnabled( 'taxonomy-panel-post_tag' ), + setIsFeaturedImagePanelEnabled: buildSetIsPanelEnabled( 'featured-image' ), + setIsExcerptPanelEnabled: buildSetIsPanelEnabled( 'post-excerpt' ), + setIsDiscussionPanelEnabled: buildSetIsPanelEnabled( 'discussion-panel' ), + }; + } ), +] )( OptionsModal ); diff --git a/edit-post/components/options-modal/style.scss b/edit-post/components/options-modal/style.scss new file mode 100644 index 00000000000000..0830f0281ed7d7 --- /dev/null +++ b/edit-post/components/options-modal/style.scss @@ -0,0 +1,36 @@ +.edit-post-options { + min-width: 450px; + + &__title { + font-size: 1rem; + font-weight: bold; + } + + &__section { + margin: 0 0 2rem 0; + } + + &__section-title { + font-size: 0.9rem; + font-weight: bold; + } + + &__option { + display: flex; + align-items: center; + padding: 0.6rem 0; + border-top: 1px solid $light-gray-500; + + &:last-child { + border-bottom: 1px solid $light-gray-500; + } + + .components-base-control__field { + margin: 0; + } + + .components-checkbox-control__input { + margin-right: 10px; + } + } +} diff --git a/edit-post/components/options-modal/test/__snapshots__/index.js.snap b/edit-post/components/options-modal/test/__snapshots__/index.js.snap new file mode 100644 index 00000000000000..8d43f44305ec96 --- /dev/null +++ b/edit-post/components/options-modal/test/__snapshots__/index.js.snap @@ -0,0 +1,58 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`OptionsModal should match snapshot when the modal is active 1`] = ` + + Options + + } +> +
+ + +
+
+ + + + + + +
+
+`; + +exports[`OptionsModal should match snapshot when the modal is not active 1`] = `""`; diff --git a/edit-post/components/options-modal/test/index.js b/edit-post/components/options-modal/test/index.js new file mode 100644 index 00000000000000..2abc5879ae897c --- /dev/null +++ b/edit-post/components/options-modal/test/index.js @@ -0,0 +1,31 @@ +/** + * External dependencies + */ +import { shallow } from 'enzyme'; + +/** + * Internal dependencies + */ +import { OptionsModal } from '../'; + +describe( 'OptionsModal', () => { + it( 'should match snapshot when the modal is active', () => { + const wrapper = shallow( + + ); + + expect( wrapper ).toMatchSnapshot(); + } ); + + it( 'should match snapshot when the modal is not active', () => { + const wrapper = shallow( + + ); + + expect( wrapper ).toMatchSnapshot(); + } ); +} ); diff --git a/edit-post/components/sidebar/discussion-panel/index.js b/edit-post/components/sidebar/discussion-panel/index.js index 27bd6e04b2cb73..5d2388033d83e8 100644 --- a/edit-post/components/sidebar/discussion-panel/index.js +++ b/edit-post/components/sidebar/discussion-panel/index.js @@ -12,7 +12,11 @@ import { withSelect, withDispatch } from '@wordpress/data'; */ const PANEL_NAME = 'discussion-panel'; -function DiscussionPanel( { isOpened, onTogglePanel } ) { +function DiscussionPanel( { isEnabled, isOpened, onTogglePanel } ) { + if ( ! isEnabled ) { + return null; + } + return ( @@ -35,6 +39,7 @@ function DiscussionPanel( { isOpened, onTogglePanel } ) { export default compose( [ withSelect( ( select ) => { return { + isEnabled: select( 'core/edit-post' ).isEditorSidebarPanelEnabled( PANEL_NAME ), isOpened: select( 'core/edit-post' ).isEditorSidebarPanelOpened( PANEL_NAME ), }; } ), diff --git a/edit-post/components/sidebar/featured-image/index.js b/edit-post/components/sidebar/featured-image/index.js index a5e8aeb3b2e964..6fc751adcdc827 100644 --- a/edit-post/components/sidebar/featured-image/index.js +++ b/edit-post/components/sidebar/featured-image/index.js @@ -17,7 +17,11 @@ import { withSelect, withDispatch } from '@wordpress/data'; */ const PANEL_NAME = 'featured-image'; -function FeaturedImage( { isOpened, postType, onTogglePanel } ) { +function FeaturedImage( { isEnabled, isOpened, postType, onTogglePanel } ) { + if ( ! isEnabled ) { + return null; + } + return ( { const { getEditedPostAttribute } = select( 'core/editor' ); const { getPostType } = select( 'core' ); - const { isEditorSidebarPanelOpened } = select( 'core/edit-post' ); + const { isEditorSidebarPanelEnabled, isEditorSidebarPanelOpened } = select( 'core/edit-post' ); return { postType: getPostType( getEditedPostAttribute( 'type' ) ), + isEnabled: isEditorSidebarPanelEnabled( PANEL_NAME ), isOpened: isEditorSidebarPanelOpened( PANEL_NAME ), }; } ); diff --git a/edit-post/components/sidebar/post-excerpt/index.js b/edit-post/components/sidebar/post-excerpt/index.js index 0a603f58b7a6ba..df451cd7d5dc21 100644 --- a/edit-post/components/sidebar/post-excerpt/index.js +++ b/edit-post/components/sidebar/post-excerpt/index.js @@ -12,7 +12,11 @@ import { withSelect, withDispatch } from '@wordpress/data'; */ const PANEL_NAME = 'post-excerpt'; -function PostExcerpt( { isOpened, onTogglePanel } ) { +function PostExcerpt( { isEnabled, isOpened, onTogglePanel } ) { + if ( ! isEnabled ) { + return null; + } + return ( @@ -25,6 +29,7 @@ function PostExcerpt( { isOpened, onTogglePanel } ) { export default compose( [ withSelect( ( select ) => { return { + isEnabled: select( 'core/edit-post' ).isEditorSidebarPanelEnabled( PANEL_NAME ), isOpened: select( 'core/edit-post' ).isEditorSidebarPanelOpened( PANEL_NAME ), }; } ), diff --git a/edit-post/components/sidebar/post-status/index.js b/edit-post/components/sidebar/post-status/index.js index 3b11c2d78de0cb..c803474bbddda9 100644 --- a/edit-post/components/sidebar/post-status/index.js +++ b/edit-post/components/sidebar/post-status/index.js @@ -25,7 +25,11 @@ import PluginPostStatusInfo from '../plugin-post-status-info'; */ const PANEL_NAME = 'post-status'; -function PostStatus( { isOpened, onTogglePanel } ) { +function PostStatus( { isEnabled, isOpened, onTogglePanel } ) { + if ( ! isEnabled ) { + return null; + } + return ( @@ -48,6 +52,7 @@ function PostStatus( { isOpened, onTogglePanel } ) { export default compose( [ withSelect( ( select ) => ( { + isEnabled: select( 'core/edit-post' ).isEditorSidebarPanelEnabled( PANEL_NAME ), isOpened: select( 'core/edit-post' ).isEditorSidebarPanelOpened( PANEL_NAME ), } ) ), withDispatch( ( dispatch ) => ( { diff --git a/edit-post/components/sidebar/post-taxonomies/taxonomy-panel.js b/edit-post/components/sidebar/post-taxonomies/taxonomy-panel.js index d8d9ed58c35714..00d9ecb9a307d6 100644 --- a/edit-post/components/sidebar/post-taxonomies/taxonomy-panel.js +++ b/edit-post/components/sidebar/post-taxonomies/taxonomy-panel.js @@ -10,11 +10,16 @@ import { compose } from '@wordpress/compose'; import { PanelBody } from '@wordpress/components'; import { withSelect, withDispatch } from '@wordpress/data'; -function TaxonomyPanel( { taxonomy, isOpened, onTogglePanel, children } ) { +function TaxonomyPanel( { isEnabled, taxonomy, isOpened, onTogglePanel, children } ) { + if ( ! isEnabled ) { + return null; + } + const taxonomyMenuName = get( taxonomy, [ 'labels', 'menu_name' ] ); if ( ! taxonomyMenuName ) { return null; } + return ( { __( 'Manage All Reusable Blocks' ) } - - diff --git a/edit-post/plugins/publish-sidebar-toggle-menu-item/index.js b/edit-post/plugins/publish-sidebar-toggle-menu-item/index.js deleted file mode 100644 index 9b4e514279bb74..00000000000000 --- a/edit-post/plugins/publish-sidebar-toggle-menu-item/index.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * WordPress Dependencies - */ -import { __ } from '@wordpress/i18n'; -import { MenuItem } from '@wordpress/components'; -import { compose } from '@wordpress/compose'; -import { withSelect, withDispatch } from '@wordpress/data'; - -const PublishSidebarToggleMenuItem = function( { onToggle, isEnabled } ) { - return ( - - { __( 'Enable Pre-publish Checks' ) } - - ); -}; - -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(); - }, - } ) ), -] )( PublishSidebarToggleMenuItem ); diff --git a/edit-post/plugins/tips-toggle-menu-item/index.js b/edit-post/plugins/tips-toggle-menu-item/index.js deleted file mode 100644 index 778f9ae8a8ddbc..00000000000000 --- a/edit-post/plugins/tips-toggle-menu-item/index.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * WordPress Dependencies - */ -import { withSelect, withDispatch } from '@wordpress/data'; -import { __ } from '@wordpress/i18n'; -import { compose } from '@wordpress/compose'; -import { MenuItem } from '@wordpress/components'; - -function TipsToggleMenuItem( { onToggle, isActive } ) { - return ( - - { __( 'Show Tips' ) } - - ); -} - -export default compose( [ - withSelect( ( select ) => ( { - isActive: select( 'core/nux' ).areTipsEnabled(), - } ) ), - withDispatch( ( dispatch, ownProps ) => ( { - onToggle() { - const { disableTips, enableTips } = dispatch( 'core/nux' ); - if ( ownProps.isActive ) { - disableTips(); - } else { - enableTips(); - } - ownProps.onToggle(); - }, - } ) ), -] )( TipsToggleMenuItem ); diff --git a/edit-post/store/actions.js b/edit-post/store/actions.js index 2a58739addd93f..20befcab9bdc0c 100644 --- a/edit-post/store/actions.js +++ b/edit-post/store/actions.js @@ -83,6 +83,36 @@ export function togglePublishSidebar() { }; } +/** + * Returns an action object used to enable a sidebar panel. The panel will + * re-appear in the UI. + * + * @param {string} panel A string that identifies the panel to enable. + * + * @return {Object} Action object. + */ +export function enablePanel( panel ) { + return { + type: 'ENABLE_PANEL', + panel, + }; +} + +/** + * Returns an action object used to disable a sidebar panel. The panel will be + * removed completely from the UI. + * + * @param {string} panel A string that identifies the panel to disable. + * + * @return {Object} Action object. + */ +export function disablePanel( panel ) { + return { + type: 'DISABLE_PANEL', + panel, + }; +} + /** * Returns an action object used in signalling that use toggled a panel in the editor. * diff --git a/edit-post/store/defaults.js b/edit-post/store/defaults.js index bddf18a60048ae..1744bee063e811 100644 --- a/edit-post/store/defaults.js +++ b/edit-post/store/defaults.js @@ -1,6 +1,7 @@ export const PREFERENCES_DEFAULTS = { editorMode: 'visual', isGeneralSidebarDismissed: false, + disabledPanels: {}, panels: { 'post-status': true }, features: { fixedToolbar: false, diff --git a/edit-post/store/reducer.js b/edit-post/store/reducer.js index 0b9ad2683a9002..ea1087db371c67 100644 --- a/edit-post/store/reducer.js +++ b/edit-post/store/reducer.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { get } from 'lodash'; +import { get, omit } from 'lodash'; /** * WordPress dependencies @@ -33,6 +33,8 @@ export const DEFAULT_ACTIVE_GENERAL_SIDEBAR = 'edit-post/document'; * sidebar. * @param {boolean} state.isSidebarOpened Whether the sidebar is * opened or closed. + * @param {Object} state.disabledPanels Whether a sidebar panel + * should be hidden in the UI. * @param {Object} state.panels The state of the different * sidebar panels. * @param {Object} action Dispatched action. @@ -49,6 +51,20 @@ export const preferences = combineReducers( { return state; }, + disabledPanels( state = PREFERENCES_DEFAULTS.disabledPanels, action ) { + switch ( action.type ) { + case 'ENABLE_PANEL': + return omit( state, action.panel ); + + case 'DISABLE_PANEL': + return { + ...state, + [ action.panel ]: true, + }; + } + + 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..a1de1b758b72e9 100644 --- a/edit-post/store/selectors.js +++ b/edit-post/store/selectors.js @@ -99,6 +99,20 @@ export function isPublishSidebarOpened( state ) { return state.publishSidebarActive; } +/** + * Returns true if the given sidebar panel is enabled. Panels are enabled by + * default. + * + * @param {Object} state Global application state. + * @param {string} panel A string that identifies the panel. + * + * @return {boolean} Whether or not the panel is enabled. + */ +export function isEditorSidebarPanelEnabled( state, panel ) { + const disabledPanels = getPreference( state, 'disabledPanels' ); + return disabledPanels ? ! disabledPanels[ panel ] : true; +} + /** * Returns true if the editor sidebar panel is open, or false otherwise. * diff --git a/edit-post/store/test/actions.js b/edit-post/store/test/actions.js index e50b5a5310002e..d990515fb78baa 100644 --- a/edit-post/store/test/actions.js +++ b/edit-post/store/test/actions.js @@ -14,6 +14,8 @@ import { togglePinnedPluginItem, requestMetaBoxUpdates, initializeMetaBoxState, + enablePanel, + disablePanel, } from '../actions'; describe( 'actions', () => { @@ -59,6 +61,24 @@ describe( 'actions', () => { } ); } ); + describe( 'enablePanel', () => { + it( 'should return an ENABLE_PANEL action', () => { + expect( enablePanel( 'post-status' ) ).toEqual( { + type: 'ENABLE_PANEL', + panel: 'post-status', + } ); + } ); + } ); + + describe( 'disablePanel', () => { + it( 'should return an DISABLE_PANEL action', () => { + expect( disablePanel( 'post-status' ) ).toEqual( { + type: 'DISABLE_PANEL', + panel: 'post-status', + } ); + } ); + } ); + describe( 'toggleSidebarPanel', () => { it( 'should return TOGGLE_GENERAL_SIDEBAR_EDITOR_PANEL action', () => { const panel = 'panelName'; diff --git a/edit-post/store/test/reducer.js b/edit-post/store/test/reducer.js index eefd38bd2a94cc..76b317981364fb 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, + disabledPanels: {}, panels: { 'post-status': true }, features: { fixedToolbar: false }, pinnedPluginItems: {}, @@ -51,6 +52,38 @@ describe( 'state', () => { expect( state.isGeneralSidebarDismissed ).toBe( true ); } ); + it( 'should disable panels', () => { + const original = deepFreeze( { + disabledPanels: { + 'post-excerpt': true, + }, + } ); + const state = preferences( original, { + type: 'DISABLE_PANEL', + panel: 'post-status', + } ); + expect( state.disabledPanels ).toEqual( { + 'post-excerpt': true, + 'post-status': true, + } ); + } ); + + it( 'should enable panels', () => { + const original = deepFreeze( { + disabledPanels: { + 'post-excerpt': true, + 'post-status': true, + }, + } ); + const state = preferences( original, { + type: 'ENABLE_PANEL', + panel: 'post-status', + } ); + expect( state.disabledPanels ).toEqual( { + 'post-excerpt': 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/edit-post/store/test/selectors.js b/edit-post/store/test/selectors.js index 7cda42943f30b6..a41fedb53b2fb0 100644 --- a/edit-post/store/test/selectors.js +++ b/edit-post/store/test/selectors.js @@ -15,6 +15,7 @@ import { hasMetaBoxes, isSavingMetaBoxes, getMetaBox, + isEditorSidebarPanelEnabled, } from '../selectors'; describe( 'selectors', () => { @@ -194,6 +195,30 @@ describe( 'selectors', () => { } ); } ); + describe( 'isEditorSidebarPanelEnabled', () => { + it( 'should return true by default', () => { + const state = { + preferences: { + disabledPanels: {}, + }, + }; + + expect( isEditorSidebarPanelEnabled( state, 'post-status' ) ).toBe( true ); + } ); + + it( 'should reutrn false when a panel has been disabled', () => { + const state = { + preferences: { + disabledPanels: { + 'post-status': true, + }, + }, + }; + + expect( isEditorSidebarPanelEnabled( state, 'post-status' ) ).toBe( false ); + } ); + } ); + describe( 'isEditorSidebarPanelOpened', () => { it( 'should return false if no panels preference', () => { const state = {