Skip to content

Commit

Permalink
Change Delete page menu item to Move to trash. (#52641)
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia authored Jul 18, 2023
1 parent 1e31fd3 commit 3dfea59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/page-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { moreVertical } from '@wordpress/icons';
/**
* Internal dependencies
*/
import DeletePageMenuItem from './delete-page-menu-item';
import TrashPageMenuItem from './trash-page-menu-item';

export default function PageActions( {
postId,
Expand All @@ -25,7 +25,7 @@ export default function PageActions( {
>
{ () => (
<MenuGroup>
<DeletePageMenuItem
<TrashPageMenuItem
postId={ postId }
onRemove={ onRemove }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
*/
import { useDispatch, useSelect } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';
import { useState } from '@wordpress/element';
import { store as coreStore } from '@wordpress/core-data';
import { __, sprintf } from '@wordpress/i18n';
import {
MenuItem,
__experimentalConfirmDialog as ConfirmDialog,
} from '@wordpress/components';
import { MenuItem } from '@wordpress/components';
import { store as noticesStore } from '@wordpress/notices';

export default function DeletePageMenuItem( { postId, onRemove } ) {
const [ isModalOpen, setIsModalOpen ] = useState( false );
export default function TrashPageMenuItem( { postId, onRemove } ) {
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );
const { deleteEntityRecord } = useDispatch( coreStore );
Expand All @@ -34,39 +29,31 @@ export default function DeletePageMenuItem( { postId, onRemove } ) {
createSuccessNotice(
sprintf(
/* translators: The page's title. */
__( '"%s" deleted.' ),
__( '"%s" moved to the Trash.' ),
decodeEntities( page.title.rendered )
),
{
type: 'snackbar',
id: 'edit-site-page-removed',
id: 'edit-site-page-trashed',
}
);
onRemove?.();
} catch ( error ) {
const errorMessage =
error.message && error.code !== 'unknown_error'
? error.message
: __( 'An error occurred while deleting the page.' );
: __(
'An error occurred while moving the page to the trash.'
);

createErrorNotice( errorMessage, { type: 'snackbar' } );
} finally {
setIsModalOpen( false );
}
}
return (
<>
<MenuItem onClick={ () => setIsModalOpen( true ) } isDestructive>
{ __( 'Delete' ) }
<MenuItem onClick={ () => removePage() } isDestructive>
{ __( 'Move to Trash' ) }
</MenuItem>
<ConfirmDialog
isOpen={ isModalOpen }
onConfirm={ removePage }
onCancel={ () => setIsModalOpen( false ) }
confirmButtonText={ __( 'Delete' ) }
>
{ __( 'Are you sure you want to delete this page?' ) }
</ConfirmDialog>
</>
);
}

0 comments on commit 3dfea59

Please sign in to comment.