From 8dc4fa27f6b464c5eabab44d3e25cdecfeb237ec Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Mon, 7 May 2018 15:38:19 +0200 Subject: [PATCH] Edit Post: Add pin button for the plugin sidebar --- .../plugin-sidebar-more-menu-item/index.js | 6 +-- .../sidebar/plugin-sidebar/index.js | 43 +++++++++++++++++-- edit-post/store/test/selectors.js | 13 ++++-- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/edit-post/components/header/plugin-sidebar-more-menu-item/index.js b/edit-post/components/header/plugin-sidebar-more-menu-item/index.js index 34f0efe526793f..b98c48c8fb5a66 100644 --- a/edit-post/components/header/plugin-sidebar-more-menu-item/index.js +++ b/edit-post/components/header/plugin-sidebar-more-menu-item/index.js @@ -14,9 +14,9 @@ import PluginsMoreMenuGroup from '../plugins-more-menu-group'; const PluginSidebarMoreMenuItem = ( { children, icon, isPinned, isSelected, onClick } ) => ( - { isPinned && icon && ( + { icon && ( - { { title } + { pinnable && ( + + ) } { children } @@ -34,4 +45,28 @@ function PluginSidebar( { children, name, pluginContext, title } ) { ); } -export default withPluginContext( PluginSidebar ); +export default compose( + withPluginContext, + withSelect( ( select, { name, pluginContext } ) => { + const { + isPluginItemPinned, + } = select( 'core/edit-post' ); + const sidebarName = `${ pluginContext.name }/${ name }`; + + return { + isPinned: isPluginItemPinned( sidebarName ), + sidebarName, + }; + } ), + withDispatch( ( dispatch, { sidebarName } ) => { + const { + togglePinnedPluginItem, + } = dispatch( 'core/edit-post' ); + + return { + togglePin() { + togglePinnedPluginItem( sidebarName ); + }, + }; + } ), +)( PluginSidebar ); diff --git a/edit-post/store/test/selectors.js b/edit-post/store/test/selectors.js index 8a268d0b7b8c51..b237e8a458f497 100644 --- a/edit-post/store/test/selectors.js +++ b/edit-post/store/test/selectors.js @@ -192,17 +192,22 @@ describe( 'selectors', () => { const state = { preferences: { pinnedPluginItems: { - 'foo/bar': true, + 'foo/pinned': true, + 'foo/unpinned': false, }, }, }; - it( 'should return false if plugin item is not pinned', () => { + it( 'should return false if the flag is not set for the plugin item', () => { expect( isPluginItemPinned( state, 'foo/unknown' ) ).toBe( false ); } ); - it( 'should return true if plugin item item is pinned', () => { - expect( isPluginItemPinned( state, 'foo/bar' ) ).toBe( true ); + it( 'should return true if plugin item is not pinned', () => { + expect( isPluginItemPinned( state, 'foo/pinned' ) ).toBe( true ); + } ); + + it( 'should return false if plugin item item is unpinned', () => { + expect( isPluginItemPinned( state, 'foo/unpinned' ) ).toBe( false ); } ); } );