-
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
Add context
in post actions API
#62443
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: +60 B (0%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
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.
Quick thoughts:
- I think introducing
context
makes sense - But I worry about overloading WordPress's preexisting
edit|view
dichotomy with something that is close but not quite like it - I wouldn't dismiss
context: 'list'
too quickly: there may be something worthwhile there
|
||
const actions = useMemo( () => { | ||
if ( type === TEMPLATE_PART_POST_TYPE ) { | ||
return [ editAction, ...templatePartActions ].filter( Boolean ); | ||
return templatePartActions.filter( Boolean ); |
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.
Is filtering still doing anything useful? I'd be surprised if usePostActions
were returning empty values.
ffa2496
to
a388f2e
Compare
a388f2e
to
bde1cc4
Compare
@@ -583,6 +583,7 @@ const viewPostAction = { | |||
|
|||
const postRevisionsAction = { | |||
id: 'view-post-revisions', | |||
context: 'list', |
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 know we only support one context right now, but I expect this will grow and we may endup with more contexts. Would it make sense for context to be array with all the supported contexts?
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.
Nothing is public right now, so I think we can add it when we'll need it.
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 we can merge this solution it seems very likely we will need a context for the actions, and we can iterate in the future how that context looks like.
This PR was cherry picked for 6.6. |
What?
Related: #62323 - in the aspect of not showing the
revisions
action inedit
mode.This PR proposes the addition of a new
context
prop in post actions API. Post actions in their majority are meant to be used in any context like in data views (lists) or in editors as part of the ellipsis menu in inspector controls. There are some exceptions though and a couple examples are:editPost
action which doesn't make sense in the editors, as we already editing. For that reason this actions lived in edit-site package and was separated from all the other actions that live ineditor
package (for now).My suggestion for the new
context
property values is a separation betweenlist
and whatever view/layout might use them in the future... Due to the unification of editors I don't think it makes sense to consideredit-post|edit-site
etc.. and also experimented withedit/view
context but the lines might blur when we havelist
views with editing allowed. It's a private API, so we can always revisit.A consumer of actions in order to get them from where ever (right now with
usePostActions
hook) can provide a specific context if needs to, but the absence of it means fetch all (default). Additionally actions can provide a context where they are allowed and is separate fromisEligible
, as it's meant for checks regarding a specific item.I'd welcome any feedback and suggestions about the API.
Testing Instructions
edit post
action