From 3a07113ebeb34a302a8874e976941edc4af3c507 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Mon, 22 Apr 2024 12:21:30 +0300 Subject: [PATCH] reorder edit excerpt menu item and show only for user generated entities --- .../src/components/template-actions/index.js | 62 +++++++++++++------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/packages/edit-site/src/components/template-actions/index.js b/packages/edit-site/src/components/template-actions/index.js index a42e2fdacbbf7d..9e954a78d6c7a7 100644 --- a/packages/edit-site/src/components/template-actions/index.js +++ b/packages/edit-site/src/components/template-actions/index.js @@ -17,6 +17,7 @@ import { store as noticesStore } from '@wordpress/notices'; import { decodeEntities } from '@wordpress/html-entities'; import { PostExcerpt, + store as editorStore, privateApis as editorPrivateApis, } from '@wordpress/editor'; @@ -39,14 +40,39 @@ export default function TemplateActions( { toggleProps, onRemove, } ) { - const template = useSelect( - ( select ) => - select( coreStore ).getEntityRecord( 'postType', postType, postId ), + const { template, eligibleToEditExcerpt } = useSelect( + ( select ) => { + const { getCurrentPostType, isEditorPanelEnabled } = + select( editorStore ); + const { getPostType } = select( coreStore ); + const _postType = getPostType( getCurrentPostType() ); + return { + eligibleToEditExcerpt: + isEditorPanelEnabled( 'post-excerpt' ) && + _postType?.supports?.excerpt, + template: select( coreStore ).getEntityRecord( + 'postType', + postType, + postId + ), + }; + }, [ postType, postId ] ); const { removeTemplate } = useDispatch( editSiteStore ); const isRemovable = isTemplateRemovable( template ); const isRevertable = isTemplateRevertable( template ); + // Until we consolidate these actions we need to make different checks for `wp_block` + // type and template/template parts. The reason for this is that we want to allow + // editing excerpt/description for templates/template parts that are + // user generated and this shouldn't abide by the isPanelEnabled flag. + const canEditExcerpt = + isRemovable || + ( eligibleToEditExcerpt && template?.type === 'wp_block' ); + + if ( ! isRemovable && ! isRevertable && ! canEditExcerpt ) { + return null; + } return ( ( { isRemovable && ( - <> - - { - removeTemplate( template ); - onRemove?.(); - onClose(); - } } - title={ template.title.rendered } - /> - + + ) } + { canEditExcerpt && } + { isRemovable && ( + { + removeTemplate( template ); + onRemove?.(); + onClose(); + } } + title={ template.title.rendered } + /> ) } - { isRevertable && (