-
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
Core Data: Resolve user capabilities when fetching an entity #63430
Conversation
Size Change: +141 B (+0.01%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
b6ac044
to
27b4b0d
Compare
{ hasResolved && ( | ||
<ReusableBlockControl | ||
recordId={ ref } | ||
canOverrideBlocks={ canOverrideBlocks } | ||
hasContent={ !! content } | ||
handleEditOriginal={ | ||
onNavigateToEntityRecord | ||
? handleEditOriginal | ||
: undefined | ||
} | ||
resetContent={ resetContent } | ||
/> |
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.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
I think PR is in good shape for reviews and feedback. |
@@ -165,8 +171,29 @@ export const getEntityRecord = | |||
} | |||
} | |||
|
|||
const record = await apiFetch( { path } ); | |||
dispatch.receiveEntityRecords( kind, name, record, query ); | |||
const response = await apiFetch( { path, parse: false } ); |
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.
Setting parse: false
will disable the fetchAllMiddleware
. See how it returns early when options.parse
is false
. Is this a concern here?
fetchAllMiddleware
is relevant for fetching collections, and getEntityRecord
fetches only one item, so it shouldn't be relevant. But what if I do:
getEntityRecord( 'postType', 'post', '', { per_page: -1 } );
This will fetch the entire collection anyway, won't it? And should trigger fetchAllMiddleware
.
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 also had similar concerns during the original discussion: #43480 (comment). But it shouldn't affect the getEntityRecord
resolver.
The getEntityRecord
supports only fetching a single entity. Any other usage is incorrect, and it's up to consumers to fix it.
Calling wp.data.select( 'core' ).getEntityRecord( 'postType', 'post', '', { per_page: -1 } );
will make a request, but then will return undefined
.
Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com>
c38b9e3
to
c8ae4b6
Compare
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.
Looks good to go 👍
…ss#63430) * Core Data: Resolve user capabilities when fetching an entity * Mark canUser selector as resolved * Fix unit tests * Dedupe logic * Showcase: Update Pattern block to benefit from new user permission resolutions * Clarify comment Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
What?
Inspired by #43480 (comment).
Hopefully, this will be more effective after merging #63415 and #63423.
PR updates the
getEntityRecord
to resolve entity-related user permission when fetching entity data.Why?
Most of the time, actions to interact with the entity are displayed after loading it. Resolving user capability selectors for the same entity can improve the UI (no more popcorning) and reduce the number of requests the app makes.
Testing Instructions
Manually run selectors
canUser
selector for the same entity shouldn't trigger a REST API request.Pattern blocks
OPTIONS
requests are made for these patterns. You can usev2/blocks
to filter the endpoint.Testing Instructions for Keyboard
Same.
Screenshots or screencast
Requests before with four pattern blocks on canvas:
Requests after: