Skip to content

Commit

Permalink
Fix: Moving a page to the trash on the site editor does not goes back…
Browse files Browse the repository at this point in the history
… to the pages list.
  • Loading branch information
jorgefilipecosta committed Sep 6, 2024
1 parent a7c4e26 commit 8c6da6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,10 @@ Undocumented declaration.

Displays the Post Trash Button and Confirm Dialog in the Editor.

_Parameters_

- _An_ `?{onActionPerformed: Object}`: object containing the onActionPerformed function.

_Returns_

- `JSX.Element|null`: The rendered PostTrash component.
Expand Down
17 changes: 12 additions & 5 deletions packages/editor/src/components/post-trash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Button,
__experimentalConfirmDialog as ConfirmDialog,
} from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
import { useState } from '@wordpress/element';

/**
Expand All @@ -18,9 +18,11 @@ import PostTrashCheck from './check';
/**
* Displays the Post Trash Button and Confirm Dialog in the Editor.
*
* @param {?{onActionPerformed: Object}} An object containing the onActionPerformed function.
* @return {JSX.Element|null} The rendered PostTrash component.
*/
export default function PostTrash() {
export default function PostTrash( { onActionPerformed } ) {
const registry = useRegistry();
const { isNew, isDeleting, postId, title } = useSelect( ( select ) => {
const store = select( editorStore );
return {
Expand All @@ -37,11 +39,16 @@ export default function PostTrash() {
return null;
}

const handleConfirm = () => {
const handleConfirm = async () => {
setShowConfirmDialog( false );
trashPost();
await trashPost();
const item = await registry
.resolveSelect( editorStore )
.getCurrentPost();
// After the post is trashed, we want to trigger the onActionPerformed callback, so the user is redirect
// to the post view depending on if the user is on post editor or site editor.
onActionPerformed?.( 'move-to-trash', [ item ] );
};

return (
<PostTrashCheck>
<Button
Expand Down
4 changes: 3 additions & 1 deletion packages/editor/src/components/sidebar/post-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export default function PostSummary( { onActionPerformed } ) {
<SiteDiscussion />
<PostFormatPanel />
</VStack>
<PostTrash />
<PostTrash
onActionPerformed={ onActionPerformed }
/>
{ fills }
</VStack>
) }
Expand Down

0 comments on commit 8c6da6e

Please sign in to comment.