-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Add new useEntityRecordsWithPermissions hook #63857
Core Data: Add new useEntityRecordsWithPermissions hook #63857
Conversation
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. |
Size Change: +228 B (+0.01%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
permissions: permissions[ index ], | ||
} ) ) ?? [], | ||
[ data, permissions ] | ||
); |
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.
Why not do this is a single memoized selector?
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 think that would also reduce the loops from 3 to 1?
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 think that would also reduce the loops from 3 to 1?
I don't think it reduces anything as the loop will exist but within the selector. I'm not sure which is better to be honest. A huge memoized selector or smaller ones with some in between memoizations. I have a feeling that the latter is better in terms of performance but the former is easier to work with.
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.
Yes, but it would just be one loop, that immediately fetches the permission and sets it on the item?
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.
Sounds great to me! Should we update the permissions in isEligible to use this, so we know what it's like?
This is what I want to do in a follow-up but I found that the way we fetch patterns and template parts is so complex (it's actually hard to even call a simple selector there). Doable but that part is not great code to be honest. |
Yes, just mentioning it because maybe it's relevant in making a decision? Fine with me to try in a follow-up |
I'm afraid, I have to do a bigger refactoring to the templates and patterns pages to be able to do that easily. I'll try to either open a refactoring PR or open a follow-up PR to this one before merging the current one. |
export const getEntityRecordsPermissions = createSelector( | ||
( state: State, kind: string, name: string, ids: string[] ) => { | ||
return ids.map( ( id ) => ( { | ||
delete: canUser( state, 'delete', { |
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.
We now have two canUser calls, but I checked and we still make one request per id and not two so it is fine.
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.
Yes, requests are deduped for related actions - #43480.
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 PR seems good to me 👍
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 think this is OK as a temporary solution, and I see it has already helped us highlight some pain points.
I'm not updating the actions yet, so in reality the current PR has no impact but it's the first step towards achieving that goal.
@youknowriad, what actions updates do you have in mind
@Mamaduka All the actions in post-actions/actions.js basically. Anything using useCanUserEligibilityCheckPostType |
0b55895
to
a78b7ed
Compare
Related #55083
What?
In different dataviews, we need a way to check whether the user has the right permissions to edit or delete a given item, we've tried an approach by dynamically updating the "action" object's is Eligible but that was bad for several reasons:
As discussed in slack, the right approach might be to embed the permissions within the "data". https://wordpress.slack.com/archives/C02QB2JS7/p1721732016850379
The current PR adds a new
useEntityRecordsWithPermissions
tocore-data
to be able to do that in an easy way. I'm not updating the actions yet, so in reality the current PR has no impact but it's the first step towards achieving that goal.Testing Instructions
Nothing to test really at the moment.