Skip to content

Commit

Permalink
DataForm: introduce isLoading prop
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Dec 6, 2024
1 parent 5896920 commit e4df49f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/dataviews/src/components/dataform/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions packages/dataviews/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 > {
Expand Down
22 changes: 14 additions & 8 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down Expand Up @@ -162,6 +167,7 @@ function PostEditForm( { postType, postId } ) {
<PostEditHeader postType={ postType } postId={ postId } />
<DataForm
data={ ids.length === 1 ? record : multiEdits }
isLoading={ ! hasFinishedResolution }
fields={ fieldsWithDependency }
form={ form }
onChange={ onChange }
Expand Down

0 comments on commit e4df49f

Please sign in to comment.