Skip to content

Commit

Permalink
Renders DataForm component only when data has been fetched (WordPre…
Browse files Browse the repository at this point in the history
…ss#67694)

Co-authored-by: gigitux <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: oandregal <[email protected]>
  • Loading branch information
4 people authored and yogeshbhutkar committed Dec 18, 2024
1 parent 8798511 commit ba47f43
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ const fieldsWithBulkEditSupport = [

function PostEditForm( { postType, postId } ) {
const ids = useMemo( () => postId.split( ',' ), [ postId ] );
const { record } = useSelect(
const { record, hasFinishedResolution } = useSelect(
( select ) => {
const args = [ 'postType', postType, ids[ 0 ] ];

const {
getEditedEntityRecord,
hasFinishedResolution: hasFinished,
} = select( coreDataStore );

return {
record:
ids.length === 1
? select( coreDataStore ).getEditedEntityRecord(
'postType',
postType,
ids[ 0 ]
)
: null,
ids.length === 1 ? getEditedEntityRecord( ...args ) : null,
hasFinishedResolution: hasFinished(
'getEditedEntityRecord',
args
),
};
},
[ postType, ids ]
Expand Down Expand Up @@ -159,12 +164,14 @@ function PostEditForm( { postType, postId } ) {
return (
<VStack spacing={ 4 }>
<PostCardPanel postType={ postType } postId={ ids } />
<DataForm
data={ ids.length === 1 ? record : multiEdits }
fields={ fieldsWithDependency }
form={ form }
onChange={ onChange }
/>
{ hasFinishedResolution && (
<DataForm
data={ ids.length === 1 ? record : multiEdits }
fields={ fieldsWithDependency }
form={ form }
onChange={ onChange }
/>
) }
</VStack>
);
}
Expand Down

0 comments on commit ba47f43

Please sign in to comment.