Skip to content

Commit

Permalink
Editor: Display error message when loading current post fails (#68999)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: t-hamano <[email protected]>
  • Loading branch information
3 people authored Feb 3, 2025
1 parent 0feca71 commit be0e151
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions packages/editor/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,30 @@ 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',
TEMPLATE_POST_TYPE,
templateId
)
: undefined,
hasLoadedPost: hasFinishedResolution( 'getEntityRecord', [
'postType',
postType,
postId,
] ),
hasLoadedPost: hasFinishedResolution(
'getEntityRecord',
postArgs
),
error: getResolutionError( 'getEntityRecord', postArgs )
?.message,
};
},
[ postType, postId, templateId ]
Expand All @@ -57,10 +63,15 @@ function Editor( {
return (
<>
{ hasLoadedPost && ! post && (
<Notice status="warning" isDismissible={ false }>
{ __(
"You attempted to edit an item that doesn't exist. Perhaps it was deleted?"
) }
<Notice
status={ !! error ? 'error' : 'warning' }
isDismissible={ false }
>
{ ! error
? __(
"You attempted to edit an item that doesn't exist. Perhaps it was deleted?"
)
: error }
</Notice>
) }
{ !! post && (
Expand Down

0 comments on commit be0e151

Please sign in to comment.