From aed94fc8cc828faaa8104ef15780941e86d9397d Mon Sep 17 00:00:00 2001 From: ramon Date: Thu, 1 Feb 2024 14:38:39 +1100 Subject: [PATCH 1/6] This commit: - checks for a clientId in the list view to fix a bug in template editing mode where no block is selected - turns the logo button into a back button similar to the document bar when editing a template to avoid creating a post_type=wp_template link (which doesn't work) --- .../components/list-view/block-contents.js | 6 ++- .../header/fullscreen-mode-close/index.js | 44 +++++++++++++------ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/packages/block-editor/src/components/list-view/block-contents.js b/packages/block-editor/src/components/list-view/block-contents.js index 0537a4b48cbe46..c683a2478ddba3 100644 --- a/packages/block-editor/src/components/list-view/block-contents.js +++ b/packages/block-editor/src/components/list-view/block-contents.js @@ -33,7 +33,7 @@ const ListViewBlockContents = forwardRef( }, ref ) => { - const { clientId } = block; + const clientId = block?.clientId; const { blockMovingClientId, selectedBlockInBlockEditor } = useSelect( ( select ) => { @@ -50,6 +50,10 @@ const ListViewBlockContents = forwardRef( const { AdditionalBlockContent, insertedBlock, setInsertedBlock } = useListViewContext(); + if ( ! clientId ) { + return null; + } + const isBlockMoveTarget = blockMovingClientId && selectedBlockInBlockEditor === clientId; diff --git a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js index a6445a1982dd2f..8e0e5c26154ad9 100644 --- a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js +++ b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js @@ -18,6 +18,7 @@ import { wordpress } from '@wordpress/icons'; import { store as editorStore } from '@wordpress/editor'; import { store as coreStore } from '@wordpress/core-data'; import { useReducedMotion } from '@wordpress/compose'; +import { useCallback } from '@wordpress/element'; /** * Internal dependencies @@ -25,14 +26,16 @@ import { useReducedMotion } from '@wordpress/compose'; import { store as editPostStore } from '../../../store'; function FullscreenModeClose( { showTooltip, icon, href } ) { - const { isActive, isRequestingSiteIcon, postType, siteIconUrl } = useSelect( - ( select ) => { - const { getCurrentPostType } = select( editorStore ); + const { isActive, isRequestingSiteIcon, postType, siteIconUrl, goBack } = + useSelect( ( select ) => { + const { getCurrentPostType, getEditorSettings } = + select( editorStore ); const { isFeatureActive } = select( editPostStore ); const { getEntityRecord, getPostType, isResolving } = select( coreStore ); const siteData = getEntityRecord( 'root', '__unstableBase', undefined ) || {}; + const _goBack = getEditorSettings()?.goBack; return { isActive: isFeatureActive( 'fullscreenMode' ), @@ -43,12 +46,20 @@ function FullscreenModeClose( { showTooltip, icon, href } ) { ] ), postType: getPostType( getCurrentPostType() ), siteIconUrl: siteData.site_icon_url, + goBack: typeof _goBack === 'function' ? _goBack : undefined, }; - }, - [] - ); + }, [] ); const disableMotion = useReducedMotion(); + const onClick = useCallback( + ( event ) => { + if ( goBack ) { + event.preventDefault(); + goBack(); + } + }, + [ goBack ] + ); if ( ! isActive || ! postType ) { return null; @@ -88,18 +99,25 @@ function FullscreenModeClose( { showTooltip, icon, href } ) { 'has-icon': siteIconUrl, } ); + const buttonHref = + href ?? + addQueryArgs( 'edit.php', { + post_type: postType.slug, + } ); + + const buttonLabel = + ! goBack && postType?.labels?.view_items + ? postType?.labels?.view_items + : __( 'Back' ); + return ( From e2e5922fffa564c5e174bfe6a5e7af5271cd7ef6 Mon Sep 17 00:00:00 2001 From: ramon Date: Thu, 1 Feb 2024 14:57:05 +1100 Subject: [PATCH 2/6] Rolling back change in favour of https://github.com/WordPress/gutenberg/pull/58533 --- .../block-editor/src/components/list-view/block-contents.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/block-editor/src/components/list-view/block-contents.js b/packages/block-editor/src/components/list-view/block-contents.js index c683a2478ddba3..0537a4b48cbe46 100644 --- a/packages/block-editor/src/components/list-view/block-contents.js +++ b/packages/block-editor/src/components/list-view/block-contents.js @@ -33,7 +33,7 @@ const ListViewBlockContents = forwardRef( }, ref ) => { - const clientId = block?.clientId; + const { clientId } = block; const { blockMovingClientId, selectedBlockInBlockEditor } = useSelect( ( select ) => { @@ -50,10 +50,6 @@ const ListViewBlockContents = forwardRef( const { AdditionalBlockContent, insertedBlock, setInsertedBlock } = useListViewContext(); - if ( ! clientId ) { - return null; - } - const isBlockMoveTarget = blockMovingClientId && selectedBlockInBlockEditor === clientId; From d4ecbc547f15691c14232d45fb7b6b430745368a Mon Sep 17 00:00:00 2001 From: ramon Date: Thu, 1 Feb 2024 15:19:56 +1100 Subject: [PATCH 3/6] Updating tests and adding some to cover the new functionality --- .../fullscreen-mode-close/test/index.js | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js b/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js index 59088779a5241e..eaef9ff3852396 100644 --- a/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js +++ b/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js @@ -33,11 +33,13 @@ describe( 'FullscreenModeClose', () => { getEntityRecord: () => ( { site_icon_url: 'https://fakeUrl.com', } ), + getEditorSettings: () => ( { + goBack: undefined, + } ), } ) ); } ); render( ); - const siteIcon = screen.getByAltText( 'Site Icon' ); expect( siteIcon ).toBeVisible(); @@ -53,6 +55,9 @@ describe( 'FullscreenModeClose', () => { getEntityRecord: () => ( { site_icon_url: '', } ), + getEditorSettings: () => ( { + goBack: undefined, + } ), } ) ); } ); @@ -64,5 +69,68 @@ describe( 'FullscreenModeClose', () => { expect( container ).toMatchSnapshot(); } ); + + it( 'should add correct href where post type exists', () => { + useSelect.mockImplementation( ( cb ) => { + return cb( () => ( { + isResolving: () => false, + isFeatureActive: () => true, + getCurrentPostType: () => {}, + getPostType: () => { + return { + slug: 'post', + labels: { + view_items: 'View Posts', + }, + }; + }, + getEntityRecord: () => ( { + site_icon_url: '', + } ), + getEditorSettings: () => ( { + goBack: undefined, + } ), + } ) ); + } ); + + render( ); + + const button = screen.getByLabelText( 'View Posts' ); + expect( button.href ).toBe( + 'http://localhost/edit.php?post_type=post' + ); + } ); + + it( 'should add correct click handler where goBack function exists', () => { + const goBack = jest.fn(); + useSelect.mockImplementation( ( cb ) => { + return cb( () => ( { + isResolving: () => false, + isFeatureActive: () => true, + getCurrentPostType: () => {}, + getPostType: () => { + return { + slug: 'post', + labels: { + view_items: 'View Posts', + }, + }; + }, + getEntityRecord: () => ( { + site_icon_url: '', + } ), + getEditorSettings: () => ( { + goBack, + } ), + } ) ); + } ); + + render( ); + + const button = screen.getByLabelText( 'Back' ); + expect( button.href ).toBeUndefined(); + button.click(); + expect( goBack ).toHaveBeenCalled(); + } ); } ); } ); From 789d88f21925fedd159095b8bf3cd1cd11abf600 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 2 Feb 2024 15:42:45 +1100 Subject: [PATCH 4/6] This commit adds a method to the post editor settings that return the initial post id and post type. --- .../header/fullscreen-mode-close/index.js | 34 ++++------- .../fullscreen-mode-close/test/index.js | 58 +++++-------------- packages/edit-post/src/editor.js | 34 +++++------ .../edit-post/src/hooks/use-post-history.js | 8 +++ 4 files changed, 49 insertions(+), 85 deletions(-) diff --git a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js index 8e0e5c26154ad9..136476ced9999d 100644 --- a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js +++ b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js @@ -18,7 +18,6 @@ import { wordpress } from '@wordpress/icons'; import { store as editorStore } from '@wordpress/editor'; import { store as coreStore } from '@wordpress/core-data'; import { useReducedMotion } from '@wordpress/compose'; -import { useCallback } from '@wordpress/element'; /** * Internal dependencies @@ -26,16 +25,15 @@ import { useCallback } from '@wordpress/element'; import { store as editPostStore } from '../../../store'; function FullscreenModeClose( { showTooltip, icon, href } ) { - const { isActive, isRequestingSiteIcon, postType, siteIconUrl, goBack } = - useSelect( ( select ) => { - const { getCurrentPostType, getEditorSettings } = - select( editorStore ); + const { isActive, isRequestingSiteIcon, postType, siteIconUrl } = useSelect( + ( select ) => { + const { getEditorSettings } = select( editorStore ); const { isFeatureActive } = select( editPostStore ); const { getEntityRecord, getPostType, isResolving } = select( coreStore ); const siteData = getEntityRecord( 'root', '__unstableBase', undefined ) || {}; - const _goBack = getEditorSettings()?.goBack; + const { getEditPostTypeProps } = getEditorSettings(); return { isActive: isFeatureActive( 'fullscreenMode' ), @@ -44,23 +42,15 @@ function FullscreenModeClose( { showTooltip, icon, href } ) { '__unstableBase', undefined, ] ), - postType: getPostType( getCurrentPostType() ), + postType: getPostType( getEditPostTypeProps()?.postType ), siteIconUrl: siteData.site_icon_url, - goBack: typeof _goBack === 'function' ? _goBack : undefined, }; - }, [] ); - - const disableMotion = useReducedMotion(); - const onClick = useCallback( - ( event ) => { - if ( goBack ) { - event.preventDefault(); - goBack(); - } }, - [ goBack ] + [] ); + const disableMotion = useReducedMotion(); + if ( ! isActive || ! postType ) { return null; } @@ -105,19 +95,15 @@ function FullscreenModeClose( { showTooltip, icon, href } ) { post_type: postType.slug, } ); - const buttonLabel = - ! goBack && postType?.labels?.view_items - ? postType?.labels?.view_items - : __( 'Back' ); + const buttonLabel = postType?.labels?.view_items ?? __( 'Back' ); return ( diff --git a/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js b/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js index eaef9ff3852396..a8580217b00dad 100644 --- a/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js +++ b/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js @@ -15,8 +15,7 @@ import FullscreenModeClose from '../'; jest.mock( '@wordpress/data/src/components/use-select', () => { // This allows us to tweak the returned value on each test. - const mock = jest.fn(); - return mock; + return jest.fn(); } ); jest.mock( '@wordpress/core-data' ); @@ -28,13 +27,14 @@ describe( 'FullscreenModeClose', () => { return cb( () => ( { isResolving: () => false, isFeatureActive: () => true, - getCurrentPostType: () => {}, getPostType: () => true, getEntityRecord: () => ( { site_icon_url: 'https://fakeUrl.com', } ), getEditorSettings: () => ( { - goBack: undefined, + getEditPostTypeProps: () => ( { + postType: 'post', + } ), } ), } ) ); } ); @@ -50,13 +50,14 @@ describe( 'FullscreenModeClose', () => { return cb( () => ( { isResolving: () => false, isFeatureActive: () => true, - getCurrentPostType: () => {}, getPostType: () => true, getEntityRecord: () => ( { site_icon_url: '', } ), getEditorSettings: () => ( { - goBack: undefined, + getEditPostTypeProps: () => ( { + postType: 'post', + } ), } ), } ) ); } ); @@ -75,12 +76,11 @@ describe( 'FullscreenModeClose', () => { return cb( () => ( { isResolving: () => false, isFeatureActive: () => true, - getCurrentPostType: () => {}, getPostType: () => { return { - slug: 'post', + slug: 'page', labels: { - view_items: 'View Posts', + view_items: 'View Pages', }, }; }, @@ -88,49 +88,19 @@ describe( 'FullscreenModeClose', () => { site_icon_url: '', } ), getEditorSettings: () => ( { - goBack: undefined, + getEditPostTypeProps: () => ( { + postType: 'page', + } ), } ), } ) ); } ); render( ); - const button = screen.getByLabelText( 'View Posts' ); + const button = screen.getByLabelText( 'View Pages' ); expect( button.href ).toBe( - 'http://localhost/edit.php?post_type=post' + 'http://localhost/edit.php?post_type=page' ); } ); - - it( 'should add correct click handler where goBack function exists', () => { - const goBack = jest.fn(); - useSelect.mockImplementation( ( cb ) => { - return cb( () => ( { - isResolving: () => false, - isFeatureActive: () => true, - getCurrentPostType: () => {}, - getPostType: () => { - return { - slug: 'post', - labels: { - view_items: 'View Posts', - }, - }; - }, - getEntityRecord: () => ( { - site_icon_url: '', - } ), - getEditorSettings: () => ( { - goBack, - } ), - } ) ); - } ); - - render( ); - - const button = screen.getByLabelText( 'Back' ); - expect( button.href ).toBeUndefined(); - button.click(); - expect( goBack ).toHaveBeenCalled(); - } ); } ); } ); diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index 99039a7d786313..3f19879136e288 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -32,10 +32,8 @@ function Editor( { initialEdits, ...props } ) { - const { currentPost, getPostLinkProps, goBack } = usePostHistory( - initialPostId, - initialPostType - ); + const { currentPost, getPostLinkProps, getEditPostTypeProps, goBack } = + usePostHistory( initialPostId, initialPostType ); const { hasInlineToolbar, post, preferredStyleVariations, template } = useSelect( @@ -80,10 +78,11 @@ function Editor( { const defaultRenderingMode = currentPost.postType === 'wp_template' ? 'all' : 'post-only'; - const editorSettings = useMemo( () => { - const result = { + const editorSettings = useMemo( + () => ( { ...settings, getPostLinkProps, + getEditPostTypeProps, goBack, defaultRenderingMode, __experimentalPreferredStyleVariations: { @@ -91,17 +90,18 @@ function Editor( { onChange: updatePreferredStyleVariations, }, hasInlineToolbar, - }; - return result; - }, [ - settings, - hasInlineToolbar, - preferredStyleVariations, - updatePreferredStyleVariations, - getPostLinkProps, - goBack, - defaultRenderingMode, - ] ); + } ), + [ + settings, + hasInlineToolbar, + preferredStyleVariations, + updatePreferredStyleVariations, + getPostLinkProps, + getEditPostTypeProps, + goBack, + defaultRenderingMode, + ] + ); if ( ! post ) { return null; diff --git a/packages/edit-post/src/hooks/use-post-history.js b/packages/edit-post/src/hooks/use-post-history.js index fe7252b7d270d5..3543f5864ebb6d 100644 --- a/packages/edit-post/src/hooks/use-post-history.js +++ b/packages/edit-post/src/hooks/use-post-history.js @@ -35,6 +35,13 @@ export default function usePostHistory( initialPostId, initialPostType ) { [ { postId: initialPostId, postType: initialPostType } ] ); + const getEditPostTypeProps = useCallback( () => { + return { + postType: initialPostType, + postId: initialPostId, + }; + }, [ initialPostType, initialPostId ] ); + const getPostLinkProps = useCallback( ( params ) => { const currentArgs = getQueryArgs( window.location.href ); const currentUrlWithoutArgs = removeQueryArgs( @@ -68,6 +75,7 @@ export default function usePostHistory( initialPostId, initialPostType ) { return { currentPost, getPostLinkProps, + getEditPostTypeProps, goBack: postHistory.length > 1 ? goBack : undefined, }; } From db2b1781b1f782547215d21b96b0a5dc2314b521 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 2 Feb 2024 15:49:16 +1100 Subject: [PATCH 5/6] No need for a useCallback. Use useMemo! --- .../components/header/fullscreen-mode-close/index.js | 4 ++-- .../header/fullscreen-mode-close/test/index.js | 12 ++++++------ packages/edit-post/src/editor.js | 6 +++--- packages/edit-post/src/hooks/use-post-history.js | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js index 136476ced9999d..ab6d78cabecef4 100644 --- a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js +++ b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js @@ -33,7 +33,7 @@ function FullscreenModeClose( { showTooltip, icon, href } ) { select( coreStore ); const siteData = getEntityRecord( 'root', '__unstableBase', undefined ) || {}; - const { getEditPostTypeProps } = getEditorSettings(); + const { editPostTypeProps } = getEditorSettings(); return { isActive: isFeatureActive( 'fullscreenMode' ), @@ -42,7 +42,7 @@ function FullscreenModeClose( { showTooltip, icon, href } ) { '__unstableBase', undefined, ] ), - postType: getPostType( getEditPostTypeProps()?.postType ), + postType: getPostType( editPostTypeProps?.postType ), siteIconUrl: siteData.site_icon_url, }; }, diff --git a/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js b/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js index a8580217b00dad..ccddd30454a184 100644 --- a/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js +++ b/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js @@ -32,9 +32,9 @@ describe( 'FullscreenModeClose', () => { site_icon_url: 'https://fakeUrl.com', } ), getEditorSettings: () => ( { - getEditPostTypeProps: () => ( { + editPostTypeProps: { postType: 'post', - } ), + }, } ), } ) ); } ); @@ -55,9 +55,9 @@ describe( 'FullscreenModeClose', () => { site_icon_url: '', } ), getEditorSettings: () => ( { - getEditPostTypeProps: () => ( { + editPostTypeProps: { postType: 'post', - } ), + }, } ), } ) ); } ); @@ -88,9 +88,9 @@ describe( 'FullscreenModeClose', () => { site_icon_url: '', } ), getEditorSettings: () => ( { - getEditPostTypeProps: () => ( { + editPostTypeProps: { postType: 'page', - } ), + }, } ), } ) ); } ); diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index 3f19879136e288..32e5f7466e3413 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -32,7 +32,7 @@ function Editor( { initialEdits, ...props } ) { - const { currentPost, getPostLinkProps, getEditPostTypeProps, goBack } = + const { currentPost, getPostLinkProps, editPostTypeProps, goBack } = usePostHistory( initialPostId, initialPostType ); const { hasInlineToolbar, post, preferredStyleVariations, template } = @@ -82,7 +82,7 @@ function Editor( { () => ( { ...settings, getPostLinkProps, - getEditPostTypeProps, + editPostTypeProps, goBack, defaultRenderingMode, __experimentalPreferredStyleVariations: { @@ -97,7 +97,7 @@ function Editor( { preferredStyleVariations, updatePreferredStyleVariations, getPostLinkProps, - getEditPostTypeProps, + editPostTypeProps, goBack, defaultRenderingMode, ] diff --git a/packages/edit-post/src/hooks/use-post-history.js b/packages/edit-post/src/hooks/use-post-history.js index 3543f5864ebb6d..c7171c520f4baf 100644 --- a/packages/edit-post/src/hooks/use-post-history.js +++ b/packages/edit-post/src/hooks/use-post-history.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { useCallback, useReducer } from '@wordpress/element'; +import { useCallback, useReducer, useMemo } from '@wordpress/element'; import { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url'; /** @@ -35,7 +35,7 @@ export default function usePostHistory( initialPostId, initialPostType ) { [ { postId: initialPostId, postType: initialPostType } ] ); - const getEditPostTypeProps = useCallback( () => { + const editPostTypeProps = useMemo( () => { return { postType: initialPostType, postId: initialPostId, @@ -75,7 +75,7 @@ export default function usePostHistory( initialPostId, initialPostType ) { return { currentPost, getPostLinkProps, - getEditPostTypeProps, + editPostTypeProps, goBack: postHistory.length > 1 ? goBack : undefined, }; } From 50abed8a2889b929437f29ddaa83364c4a3a746c Mon Sep 17 00:00:00 2001 From: ramon Date: Mon, 5 Feb 2024 10:35:53 +1100 Subject: [PATCH 6/6] Reverting adding intialPost props to the settings. Prop drill down to the relevant component. --- .../header/fullscreen-mode-close/index.js | 9 ++++---- .../fullscreen-mode-close/test/index.js | 22 +++++-------------- .../edit-post/src/components/header/index.js | 7 ++++-- .../edit-post/src/components/layout/index.js | 3 ++- packages/edit-post/src/editor.js | 6 ++--- .../edit-post/src/hooks/use-post-history.js | 8 +++---- 6 files changed, 22 insertions(+), 33 deletions(-) diff --git a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js index ab6d78cabecef4..04054390374796 100644 --- a/packages/edit-post/src/components/header/fullscreen-mode-close/index.js +++ b/packages/edit-post/src/components/header/fullscreen-mode-close/index.js @@ -24,17 +24,16 @@ import { useReducedMotion } from '@wordpress/compose'; */ import { store as editPostStore } from '../../../store'; -function FullscreenModeClose( { showTooltip, icon, href } ) { +function FullscreenModeClose( { showTooltip, icon, href, initialPost } ) { const { isActive, isRequestingSiteIcon, postType, siteIconUrl } = useSelect( ( select ) => { - const { getEditorSettings } = select( editorStore ); + const { getCurrentPostType } = select( editorStore ); const { isFeatureActive } = select( editPostStore ); const { getEntityRecord, getPostType, isResolving } = select( coreStore ); const siteData = getEntityRecord( 'root', '__unstableBase', undefined ) || {}; - const { editPostTypeProps } = getEditorSettings(); - + const _postType = initialPost?.type || getCurrentPostType(); return { isActive: isFeatureActive( 'fullscreenMode' ), isRequestingSiteIcon: isResolving( 'getEntityRecord', [ @@ -42,7 +41,7 @@ function FullscreenModeClose( { showTooltip, icon, href } ) { '__unstableBase', undefined, ] ), - postType: getPostType( editPostTypeProps?.postType ), + postType: getPostType( _postType ), siteIconUrl: siteData.site_icon_url, }; }, diff --git a/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js b/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js index ccddd30454a184..b66d548045ad42 100644 --- a/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js +++ b/packages/edit-post/src/components/header/fullscreen-mode-close/test/index.js @@ -31,11 +31,7 @@ describe( 'FullscreenModeClose', () => { getEntityRecord: () => ( { site_icon_url: 'https://fakeUrl.com', } ), - getEditorSettings: () => ( { - editPostTypeProps: { - postType: 'post', - }, - } ), + getCurrentPostType: () => 'post', } ) ); } ); @@ -54,11 +50,7 @@ describe( 'FullscreenModeClose', () => { getEntityRecord: () => ( { site_icon_url: '', } ), - getEditorSettings: () => ( { - editPostTypeProps: { - postType: 'post', - }, - } ), + getCurrentPostType: () => 'post', } ) ); } ); @@ -71,7 +63,7 @@ describe( 'FullscreenModeClose', () => { expect( container ).toMatchSnapshot(); } ); - it( 'should add correct href where post type exists', () => { + it( 'should add correct href using post type from initialPost props', () => { useSelect.mockImplementation( ( cb ) => { return cb( () => ( { isResolving: () => false, @@ -87,15 +79,11 @@ describe( 'FullscreenModeClose', () => { getEntityRecord: () => ( { site_icon_url: '', } ), - getEditorSettings: () => ( { - editPostTypeProps: { - postType: 'page', - }, - } ), + getCurrentPostType: () => 'post', } ) ); } ); - render( ); + render( ); const button = screen.getByLabelText( 'View Pages' ); expect( button.href ).toBe( diff --git a/packages/edit-post/src/components/header/index.js b/packages/edit-post/src/components/header/index.js index 3074d5f0da88db..152ccd0e1c390a 100644 --- a/packages/edit-post/src/components/header/index.js +++ b/packages/edit-post/src/components/header/index.js @@ -55,7 +55,7 @@ const slideX = { hover: { x: 0, transition: { type: 'tween', delay: 0.2 } }, }; -function Header( { setEntitiesSavedStatesCallback } ) { +function Header( { setEntitiesSavedStatesCallback, initialPost } ) { const isWideViewport = useViewportMatch( 'large' ); const isLargeViewport = useViewportMatch( 'medium' ); const blockToolbarRef = useRef(); @@ -101,7 +101,10 @@ function Header( { setEntitiesSavedStatesCallback } ) { variants={ slideX } transition={ { type: 'tween', delay: 0.8 } } > - + } editorNotices={ } diff --git a/packages/edit-post/src/editor.js b/packages/edit-post/src/editor.js index 32e5f7466e3413..ce99ed1eef38eb 100644 --- a/packages/edit-post/src/editor.js +++ b/packages/edit-post/src/editor.js @@ -32,7 +32,7 @@ function Editor( { initialEdits, ...props } ) { - const { currentPost, getPostLinkProps, editPostTypeProps, goBack } = + const { currentPost, getPostLinkProps, initialPost, goBack } = usePostHistory( initialPostId, initialPostType ); const { hasInlineToolbar, post, preferredStyleVariations, template } = @@ -82,7 +82,6 @@ function Editor( { () => ( { ...settings, getPostLinkProps, - editPostTypeProps, goBack, defaultRenderingMode, __experimentalPreferredStyleVariations: { @@ -97,7 +96,6 @@ function Editor( { preferredStyleVariations, updatePreferredStyleVariations, getPostLinkProps, - editPostTypeProps, goBack, defaultRenderingMode, ] @@ -120,7 +118,7 @@ function Editor( { - + diff --git a/packages/edit-post/src/hooks/use-post-history.js b/packages/edit-post/src/hooks/use-post-history.js index c7171c520f4baf..fa76258a0c2468 100644 --- a/packages/edit-post/src/hooks/use-post-history.js +++ b/packages/edit-post/src/hooks/use-post-history.js @@ -35,10 +35,10 @@ export default function usePostHistory( initialPostId, initialPostType ) { [ { postId: initialPostId, postType: initialPostType } ] ); - const editPostTypeProps = useMemo( () => { + const initialPost = useMemo( () => { return { - postType: initialPostType, - postId: initialPostId, + type: initialPostType, + id: initialPostId, }; }, [ initialPostType, initialPostId ] ); @@ -75,7 +75,7 @@ export default function usePostHistory( initialPostId, initialPostType ) { return { currentPost, getPostLinkProps, - editPostTypeProps, + initialPost, goBack: postHistory.length > 1 ? goBack : undefined, }; }