From 6dfee6341355a5aafd034bd2716578e96ca75a05 Mon Sep 17 00:00:00 2001 From: Ella Date: Tue, 25 Jun 2024 09:05:40 +0300 Subject: [PATCH] Fix e2e tests --- packages/edit-site/src/components/page-pages/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index 245c798022cbb..f9888be6b27ca 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -39,6 +39,7 @@ import AddNewPageModal from '../add-new-page'; import Media from '../media'; import { unlock } from '../../lock-unlock'; import { useEditPostAction } from '../dataviews-actions'; +import { usePrevious } from '@wordpress/compose'; const { usePostActions } = unlock( editorPrivateApis ); const { useLocation, useHistory } = unlock( routerPrivateApis ); @@ -274,16 +275,19 @@ export default function PagePages() { totalPages, } = useEntityRecords( 'postType', postType, queryArgs ); + const ids = pages?.map( ( page ) => getItemId( page ) ) ?? []; + const prevIds = usePrevious( ids ) ?? []; + const deletedIds = prevIds.filter( ( id ) => ! ids.includes( id ) ); + const postIdWasDeleted = deletedIds.includes( postId ); + useEffect( () => { - const postIdWasDeleted = - pages && ! pages.find( ( page ) => getItemId( page ) === postId ); if ( postIdWasDeleted ) { history.push( { ...history.getLocationWithParams().params, postId: undefined, } ); } - }, [ pages, postId, history ] ); + }, [ postIdWasDeleted, history ] ); const { records: authors, isResolving: isLoadingAuthors } = useEntityRecords( 'root', 'user', { per_page: -1 } );