From f2379787fd4cd57b175187b3f37a709a2a3e888f Mon Sep 17 00:00:00 2001 From: Enrique Piqueras Date: Tue, 7 Jul 2020 11:30:56 -0700 Subject: [PATCH] Edit Site: Integrate quick inserter. (#23516) * Edit Site: Integrate quick inserter. * Edit Site: Update unit tests. --- .../src/components/block-editor/index.js | 25 ++++++++------- .../edit-site/src/components/editor/index.js | 8 ++++- packages/edit-site/src/store/selectors.js | 32 +++++++++++-------- .../edit-site/src/store/test/selectors.js | 11 +++++-- 4 files changed, 48 insertions(+), 28 deletions(-) diff --git a/packages/edit-site/src/components/block-editor/index.js b/packages/edit-site/src/components/block-editor/index.js index cf7134fd388b82..0041ce021870b9 100644 --- a/packages/edit-site/src/components/block-editor/index.js +++ b/packages/edit-site/src/components/block-editor/index.js @@ -20,17 +20,20 @@ import { import NavigateToLink from '../navigate-to-link'; import { SidebarInspectorFill } from '../sidebar'; -export default function BlockEditor() { - const { settings, templateType, page } = useSelect( ( select ) => { - const { getSettings, getTemplateType, getPage } = select( - 'core/edit-site' - ); - return { - settings: getSettings(), - templateType: getTemplateType(), - page: getPage(), - }; - }, [] ); +export default function BlockEditor( { setIsInserterOpen } ) { + const { settings, templateType, page } = useSelect( + ( select ) => { + const { getSettings, getTemplateType, getPage } = select( + 'core/edit-site' + ); + return { + settings: getSettings( setIsInserterOpen ), + templateType: getTemplateType(), + page: getPage(), + }; + }, + [ setIsInserterOpen ] + ); const [ blocks, onInput, onChange ] = useEntityBlockEditor( 'postType', templateType diff --git a/packages/edit-site/src/components/editor/index.js b/packages/edit-site/src/components/editor/index.js index 2dacc62375ab80..f61e30ecf34f31 100644 --- a/packages/edit-site/src/components/editor/index.js +++ b/packages/edit-site/src/components/editor/index.js @@ -223,7 +223,13 @@ function Editor() { > - { template && } + { template && ( + + ) } } diff --git a/packages/edit-site/src/store/selectors.js b/packages/edit-site/src/store/selectors.js index aaaf9e870d619f..9e98f3ba36191e 100644 --- a/packages/edit-site/src/store/selectors.js +++ b/packages/edit-site/src/store/selectors.js @@ -47,29 +47,33 @@ export const getCanUserCreateMedia = createRegistrySelector( ( select ) => () => /** * Returns the settings, taking into account active features and permissions. * - * @param {Object} state Global application state. + * @param {Object} state Global application state. + * @param {Function} setIsInserterOpen Setter for the open state of the global inserter. * * @return {Object} Settings. */ export const getSettings = createSelector( - ( state ) => { + ( state, setIsInserterOpen ) => { + const settings = { + ...state.settings, + focusMode: isFeatureActive( state, 'focusMode' ), + hasFixedToolbar: isFeatureActive( state, 'fixedToolbar' ), + __experimentalSetIsInserterOpened: setIsInserterOpen, + }; + const canUserCreateMedia = getCanUserCreateMedia( state ); if ( ! canUserCreateMedia ) { - return state.settings; + return settings; } - return { - ...state.settings, - focusMode: isFeatureActive( state, 'focusMode' ), - hasFixedToolbar: isFeatureActive( state, 'fixedToolbar' ), - mediaUpload( { onError, ...rest } ) { - uploadMedia( { - wpAllowedMimeTypes: state.settings.allowedMimeTypes, - onError: ( { message } ) => onError( message ), - ...rest, - } ); - }, + settings.mediaUpload = ( { onError, ...rest } ) => { + uploadMedia( { + wpAllowedMimeTypes: state.settings.allowedMimeTypes, + onError: ( { message } ) => onError( message ), + ...rest, + } ); }; + return settings; }, ( state ) => [ getCanUserCreateMedia( state ), diff --git a/packages/edit-site/src/store/test/selectors.js b/packages/edit-site/src/store/test/selectors.js index 8335492fdf5598..f71e885b6b1472 100644 --- a/packages/edit-site/src/store/test/selectors.js +++ b/packages/edit-site/src/store/test/selectors.js @@ -79,7 +79,12 @@ describe( 'selectors', () => { canUser.mockReturnValueOnce( false ); canUser.mockReturnValueOnce( false ); const state = { settings: {}, preferences: {} }; - expect( getSettings( state ) ).toBe( state.settings ); + const setInserterOpened = () => {}; + expect( getSettings( state, setInserterOpened ) ).toEqual( { + focusMode: false, + hasFixedToolbar: false, + __experimentalSetIsInserterOpened: setInserterOpened, + } ); } ); it( 'returns the extended settings when the user can create media', () => { @@ -92,10 +97,12 @@ describe( 'selectors', () => { }, }, }; - expect( getSettings( state ) ).toEqual( { + const setInserterOpened = () => {}; + expect( getSettings( state, setInserterOpened ) ).toEqual( { key: 'value', focusMode: true, hasFixedToolbar: true, + __experimentalSetIsInserterOpened: setInserterOpened, mediaUpload: expect.any( Function ), } ); } );