Skip to content

Commit

Permalink
Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 25, 2024
1 parent 20db2cf commit 6dfee63
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 } );
Expand Down

0 comments on commit 6dfee63

Please sign in to comment.