Skip to content

Commit

Permalink
Add edits data to the useEntityRecord (#54167)
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasbenedetto authored Sep 6, 2023
1 parent f40a3f8 commit e7b7c83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/core-data/src/hooks/test/use-entity-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe( 'useEntityRecord', () => {
edit: expect.any( Function ),
editedRecord: {},
hasEdits: false,
edits: {},
record: undefined,
save: expect.any( Function ),
hasResolved: false,
Expand All @@ -64,6 +65,7 @@ describe( 'useEntityRecord', () => {
edit: expect.any( Function ),
editedRecord: { hello: 'world', id: 1 },
hasEdits: false,
edits: {},
record: { hello: 'world', id: 1 },
save: expect.any( Function ),
hasResolved: true,
Expand Down Expand Up @@ -92,6 +94,7 @@ describe( 'useEntityRecord', () => {
edit: expect.any( Function ),
editedRecord: { hello: 'world', id: 1 },
hasEdits: false,
edits: {},
record: { hello: 'world', id: 1 },
save: expect.any( Function ),
hasResolved: true,
Expand All @@ -108,5 +111,6 @@ describe( 'useEntityRecord', () => {

expect( widget.record ).toEqual( { hello: 'world', id: 1 } );
expect( widget.editedRecord ).toEqual( { hello: 'foo', id: 1 } );
expect( widget.edits ).toEqual( { hello: 'foo' } );
} );
} );
11 changes: 10 additions & 1 deletion packages/core-data/src/hooks/use-entity-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export interface EntityRecordResolution< RecordType > {
/** The edited entity record */
editedRecord: Partial< RecordType >;

/** The edits to the edited entity record */
edits: Partial< RecordType >;

/** Apply local (in-browser) edits to the edited entity record */
edit: ( diff: Partial< RecordType > ) => void;

Expand Down Expand Up @@ -163,7 +166,7 @@ export default function useEntityRecord< RecordType >(
[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]
);

const { editedRecord, hasEdits } = useSelect(
const { editedRecord, hasEdits, edits } = useSelect(
( select ) => ( {
editedRecord: select( coreStore ).getEditedEntityRecord(
kind,
Expand All @@ -175,6 +178,11 @@ export default function useEntityRecord< RecordType >(
name,
recordId
),
edits: select( coreStore ).getEntityRecordNonTransientEdits(
kind,
name,
recordId
),
} ),
[ kind, name, recordId ]
);
Expand All @@ -195,6 +203,7 @@ export default function useEntityRecord< RecordType >(
record,
editedRecord,
hasEdits,
edits,
...querySelectRest,
...mutations,
};
Expand Down

1 comment on commit e7b7c83

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in e7b7c83.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6100067773
📝 Reported issues:

Please sign in to comment.