From be0e151a4d775a801c1fe9ab8047acefef5dbacb Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Mon, 3 Feb 2025 12:33:09 +0400 Subject: [PATCH] Editor: Display error message when loading current post fails (#68999) Co-authored-by: Mamaduka Co-authored-by: t-hamano --- .../editor/src/components/editor/index.js | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/editor/src/components/editor/index.js b/packages/editor/src/components/editor/index.js index 21becea43cd7ee..80c5419caf9975 100644 --- a/packages/editor/src/components/editor/index.js +++ b/packages/editor/src/components/editor/index.js @@ -31,12 +31,17 @@ function Editor( { extraSidebarPanels, ...props } ) { - const { post, template, hasLoadedPost } = useSelect( + const { post, template, hasLoadedPost, error } = useSelect( ( select ) => { - const { getEntityRecord, hasFinishedResolution } = - select( coreStore ); + const { + getEntityRecord, + getResolutionError, + hasFinishedResolution, + } = select( coreStore ); + + const postArgs = [ 'postType', postType, postId ]; return { - post: getEntityRecord( 'postType', postType, postId ), + post: getEntityRecord( ...postArgs ), template: templateId ? getEntityRecord( 'postType', @@ -44,11 +49,12 @@ function Editor( { templateId ) : undefined, - hasLoadedPost: hasFinishedResolution( 'getEntityRecord', [ - 'postType', - postType, - postId, - ] ), + hasLoadedPost: hasFinishedResolution( + 'getEntityRecord', + postArgs + ), + error: getResolutionError( 'getEntityRecord', postArgs ) + ?.message, }; }, [ postType, postId, templateId ] @@ -57,10 +63,15 @@ function Editor( { return ( <> { hasLoadedPost && ! post && ( - - { __( - "You attempted to edit an item that doesn't exist. Perhaps it was deleted?" - ) } + + { ! error + ? __( + "You attempted to edit an item that doesn't exist. Perhaps it was deleted?" + ) + : error } ) } { !! post && (