-
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 contextual commands #50543
Add contextual commands #50543
Conversation
Size Change: +633 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
I'll preface my comment with a caveat to ignore it if this is purely a technical implementation for further expansion :) In terms of contexts, "Browse styles" is a bit lacklustre at the root, especially as there's already a "Styles" menu item. It might be better to concentrate on a different context first. If we migrated the current template details popover actions into the command palette we could close #48481 (after #50369 is merged too). That would mean: When editing a template, display the "Reset" / "Delete" action, a shortcut to manage templates, and (as a welcome addition) shortcuts to other recently edited templates: What do you think? |
Yes, that command was just an example that I took from the related issue. I can remove it for now and focus on the the "edit" context instead of the "view" one. |
30e14d2
to
f12c10d
Compare
@jameskoster I've updated the PR, I removed the "browse styles" command and added "clear customization" and "delete" template commands. Let me know how it feels. The goal of this PR is not to be exhaustive in terms of available contextual commands but more to prove the API instead. Let me know if it achieves that or not. |
I'm unable to build the PR atm – it seems there's an unresolved conflict, but the description seems good :) |
Oh sorry about that, I had fixed the conflict but forgot to save the file 🙃 It should fine now |
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.
packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js
Outdated
Show resolved
Hide resolved
// that was set before the component actually mounts. | ||
useEffect( () => { | ||
const initialContextRef = initialContext.current; | ||
return () => setContext( initialContextRef ); |
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.
Can you explain a bit more about this? If I understand correctly this is not used right now and I'm not sure when the edit-site Layout could unmount.
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.
This is a solution to the problem of third-part contexts. Imagine you have a component that is only rendered in some conditions and that when rendered sets a different third-party context for the command center. The code here ensures that whenever that components unmount, we restore the context that was in the store before that particular component mounts. It's not perfect but it's probably acceptable.
name: label, | ||
label, | ||
icon: trash, | ||
context: 'site-editor-edit', |
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.
Do you think we will have multiple contexts in the future? For example being in a template with a block selected. That would mean commands for the template, but also for the block(copy/duplicate or whatever).
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.
probably yes.
I pushed an update to get very close to the mockup and desired behavior above. |
How is this looking, can we merge it? |
I'm still not seeing the Snackbar confirmation when resetting a template via the command palette. This is quite important, because when the customisations are small it's not always obvious whether the action was performed successfully or not. |
I'll take a look, the place where I copied the code from, there was no snackbar. |
Snackbar added back. |
No need, it seems that one saves the template right away and displays a different snackbar separately. (list view) |
Related #50407 and #48457
What?
This PR adds support for contextual commands to the command center by providing:
setContext
action in the commands store to set the current context.The behavior is the following:
For the current PR, I only added a single contextual command: "Browse styles" to the site editor.
Testing Instructions
1- Open the site editor
2- In view mode, notice that the "browse styles" command is visible as soon as you open the command center
3- In edit mode, notice that the "browse styles" is not visible but is accessible if you search for it.