From 6eb61e0e3948bd5dfcbd9d2217eb9e3ddbd1cb0e Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Fri, 6 Sep 2024 11:33:31 +0100 Subject: [PATCH 1/3] Fix: Moving a page to the trash on the site editor does not goes back to the pages list. --- packages/editor/README.md | 4 ++++ .../editor/src/components/post-trash/index.js | 17 ++++++++++++----- .../src/components/sidebar/post-summary.js | 4 +++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/editor/README.md b/packages/editor/README.md index ebd4af31e287d8..d18513b151beae 100644 --- a/packages/editor/README.md +++ b/packages/editor/README.md @@ -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. diff --git a/packages/editor/src/components/post-trash/index.js b/packages/editor/src/components/post-trash/index.js index ddb1776d479db9..743512e9efd7d4 100644 --- a/packages/editor/src/components/post-trash/index.js +++ b/packages/editor/src/components/post-trash/index.js @@ -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'; /** @@ -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 { @@ -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 (