-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mutations data and helper functions to useEntityRecord #39595
Merged
+157
−3
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bdcbe3c
Add mutations data and helper functions to __experimentalUseEntityRecord
adamziel 47f350a
Update unit tests
adamziel 0c1c064
Refactor rename-menu-item.js
adamziel 3cd07bc
Revert the usage example in rename-menu-item.js
adamziel f1de0e8
Add a usage example with mutation helpers
adamziel b019462
Lint
adamziel b3a5f61
Update packages/core-data/src/hooks/use-entity-record.ts
adamziel 4714e29
Update packages/core-data/src/hooks/use-entity-record.ts
adamziel e79e955
Update packages/core-data/src/hooks/use-entity-record.ts
adamziel 13f0404
Make throwOnError: true the default in save()
adamziel 897c3e6
Add the missing imports to the docstring example
adamziel 15a5b04
Merge branch 'hooks/entity-mutations-use-entity-record' of github.com…
adamziel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that still isn't clear to me. Why do we need
useState
here rather than usingconst title = page.editedRecord.title
andconst setTitle = ( value ) => page.edit( { title: value } )
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const setTitle = ( value ) => page.edit( { title: value } )
would make undo work character by character :( I considered documenting that behavior in this code snippet and ended up leaving it out. There's already a lot of concepts in there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to go ahead and merge this PR since there are no conflicts and the checks are finally green :D we can tweak the docs in a follow-up if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approved the PR. I'm wondering how the undo/redo works with
setAttributes
from the block edit API. I don't see there an issue with storing all atomic operations when usingonChange
withTextControl
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured out why it works in a special way for block attributes. There is this util that checks whether the changes get applied to the same block's attribute:
gutenberg/packages/block-editor/src/store/reducer.js
Lines 154 to 172 in e2b293d
It's used by the higher-order reducer that ensures that only a single entry gets added to the under/redo state for subsequent changes to the same attribute:
gutenberg/packages/block-editor/src/store/reducer.js
Lines 463 to 517 in e2b293d
Maybe we should figure out how to mirror the same behavior for entities to unify the experience and bring more value to using
editedRecord
and theedit
method from this hook.