Skip to content

Commit

Permalink
avoid calling usePostActions on trash eligibility check
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Sep 5, 2024
1 parent 1163143 commit eb18890
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 4 additions & 9 deletions packages/editor/src/components/post-trash/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useMemo } from '@wordpress/element';
*/
import { unlock } from '../../lock-unlock';
import { store as editorStore } from '../../store';
import { usePostActions } from '../post-actions/actions';
import trashPost from '../../dataviews/actions/trash-post';

/**
* Wrapper component that renders its children only if the post can trashed.
Expand All @@ -21,7 +21,7 @@ import { usePostActions } from '../post-actions/actions';
* @return {Component|null} The rendered child components or null if the post can not trashed.
*/
export default function PostTrashCheck( { children } ) {
const { item, permissions, postType } = useSelect( ( select ) => {
const { item, permissions } = useSelect( ( select ) => {
const store = select( editorStore );
const { getEditedEntityRecord, getEntityRecordPermissions } = unlock(
select( coreStore )
Expand All @@ -35,7 +35,6 @@ export default function PostTrashCheck( { children } ) {
_postType,
postId
),
postType: _postType,
};
}, [] );
const itemWithPermissions = useMemo( () => {
Expand All @@ -44,13 +43,9 @@ export default function PostTrashCheck( { children } ) {
permissions,
};
}, [ item, permissions ] );
const actions = usePostActions( { postType } );
const trashPostAction = actions.find(
( action ) => action.id === 'move-to-trash'
);
if (
! trashPostAction ||
! trashPostAction.isEligible( itemWithPermissions )
! itemWithPermissions ||
! trashPost.isEligible( itemWithPermissions )
) {
return null;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/editor/src/components/post-trash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ function PostTrashButton( { onActionPerformed } ) {
const trashPostAction = actions.find(
( action ) => action.id === 'move-to-trash'
);

if ( ! trashPostAction ) {
return null;
}
return (
<ActionWithModal
action={ trashPostAction }
Expand Down

0 comments on commit eb18890

Please sign in to comment.