From e4df49ffc87d7f2076d4ea7e0e8bc6698bcc60ff Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Fri, 6 Dec 2024 15:23:01 +0100 Subject: [PATCH] DataForm: introduce isLoading prop --- .../src/components/dataform/index.tsx | 3 ++- packages/dataviews/src/types.ts | 1 + .../src/components/post-edit/index.js | 22 ++++++++++++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/dataviews/src/components/dataform/index.tsx b/packages/dataviews/src/components/dataform/index.tsx index b359ddba74381..63eb4f212b10f 100644 --- a/packages/dataviews/src/components/dataform/index.tsx +++ b/packages/dataviews/src/components/dataform/index.tsx @@ -16,13 +16,14 @@ export default function DataForm< Item >( { form, fields, onChange, + isLoading = false, }: DataFormProps< Item > ) { const normalizedFields = useMemo( () => normalizeFields( fields ), [ fields ] ); - if ( ! form.fields ) { + if ( ! form.fields || isLoading ) { return null; } diff --git a/packages/dataviews/src/types.ts b/packages/dataviews/src/types.ts index 96fd4a8cd01af..cfb5e418a60c9 100644 --- a/packages/dataviews/src/types.ts +++ b/packages/dataviews/src/types.ts @@ -543,6 +543,7 @@ export interface DataFormProps< Item > { fields: Field< Item >[]; form: Form; onChange: ( value: Record< string, any > ) => void; + isLoading?: boolean; } export interface FieldLayoutProps< Item > { diff --git a/packages/edit-site/src/components/post-edit/index.js b/packages/edit-site/src/components/post-edit/index.js index b3954e4ddbdea..0717ce9b33dd2 100644 --- a/packages/edit-site/src/components/post-edit/index.js +++ b/packages/edit-site/src/components/post-edit/index.js @@ -35,17 +35,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 ] @@ -162,6 +167,7 @@ function PostEditForm( { postType, postId } ) {