Skip to content

Commit

Permalink
Restore: Move to trash button in Document settings (#65087)
Browse files Browse the repository at this point in the history
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
  • Loading branch information
7 people authored Sep 6, 2024
1 parent 0fc06de commit 6403b32
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
7 changes: 5 additions & 2 deletions packages/editor/src/components/post-trash/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { store as coreStore } from '@wordpress/core-data';
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import { GLOBAL_POST_TYPES } from '../../store/constants';

/**
* Wrapper component that renders its children only if the post can trashed.
Expand All @@ -34,10 +35,12 @@ export default function PostTrashCheck( { children } ) {
: false;

return {
canTrashPost: ( ! isNew || postId ) && canUserDelete,
canTrashPost:
( ! isNew || postId ) &&
canUserDelete &&
! GLOBAL_POST_TYPES.includes( postType ),
};
}, [] );

if ( ! canTrashPost ) {
return null;
}
Expand Down
18 changes: 11 additions & 7 deletions packages/editor/src/components/post-trash/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import {
Button,
__experimentalConfirmDialog as ConfirmDialog,
Expand All @@ -13,19 +13,21 @@ import { useState } from '@wordpress/element';
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import PostTrashCheck from './check';

/**
* Displays the Post Trash Button and Confirm Dialog in the Editor.
*
* @return {JSX.Element|null} The rendered PostTrash component.
*/
export default function PostTrash() {
const { isNew, isDeleting, postId } = useSelect( ( select ) => {
const { isNew, isDeleting, postId, title } = useSelect( ( select ) => {
const store = select( editorStore );
return {
isNew: store.isEditedPostNew(),
isDeleting: store.isDeletingPost(),
postId: store.getCurrentPostId(),
title: store.getCurrentPostAttribute( 'title' ),
};
}, [] );
const { trashPost } = useDispatch( editorStore );
Expand All @@ -41,7 +43,7 @@ export default function PostTrash() {
};

return (
<>
<PostTrashCheck>
<Button
__next40pxDefaultSize
className="editor-post-trash"
Expand All @@ -60,12 +62,14 @@ export default function PostTrash() {
onConfirm={ handleConfirm }
onCancel={ () => setShowConfirmDialog( false ) }
confirmButtonText={ __( 'Move to trash' ) }
size="medium"
size="small"
>
{ __(
'Are you sure you want to move this post to the trash?'
{ sprintf(
// translators: %s: The item's title.
__( 'Are you sure you want to move "%s" to the trash?' ),
title
) }
</ConfirmDialog>
</>
</PostTrashCheck>
);
}
2 changes: 2 additions & 0 deletions packages/editor/src/components/sidebar/post-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import PostsPerPage from '../posts-per-page';
import SiteDiscussion from '../site-discussion';
import { store as editorStore } from '../../store';
import { PrivatePostLastRevision } from '../post-last-revision';
import PostTrash from '../post-trash';

/**
* Module Constants
Expand Down Expand Up @@ -87,6 +88,7 @@ export default function PostSummary( { onActionPerformed } ) {
<SiteDiscussion />
<PostFormatPanel />
</VStack>
<PostTrash />
{ fills }
</VStack>
) }
Expand Down

0 comments on commit 6403b32

Please sign in to comment.