Skip to content

Commit

Permalink
reorder edit excerpt menu item and show only for user generated entities
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Apr 23, 2024
1 parent 7aff204 commit a266fe6
Showing 1 changed file with 44 additions and 18 deletions.
62 changes: 44 additions & 18 deletions packages/edit-site/src/components/template-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 (
<DropdownMenu
Expand All @@ -58,22 +84,22 @@ export default function TemplateActions( {
{ ( { onClose } ) => (
<MenuGroup>
{ isRemovable && (
<>
<RenamePostMenuItem
post={ template }
onClose={ onClose }
/>
<DeleteMenuItem
onRemove={ () => {
removeTemplate( template );
onRemove?.();
onClose();
} }
title={ template.title.rendered }
/>
</>
<RenamePostMenuItem
post={ template }
onClose={ onClose }
/>
) }
{ canEditExcerpt && <EditDescriptionMenuItem /> }
{ isRemovable && (
<DeleteMenuItem
onRemove={ () => {
removeTemplate( template );
onRemove?.();
onClose();
} }
title={ template.title.rendered }
/>
) }
<EditDescriptionMenuItem />
{ isRevertable && (
<ResetMenuItem
template={ template }
Expand Down

0 comments on commit a266fe6

Please sign in to comment.