Skip to content
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 block-specific commands as contextual suggestions [#53539] #53974

Merged
merged 10 commits into from Oct 13, 2023

Conversation

jrtashjian
Copy link
Contributor

@jrtashjian jrtashjian commented Aug 27, 2023

What?

This PR adds a new context named block-selection-edit which is applied to the command palette when a block (or group of blocks) are selected. This allows us to show the block actions in the command palette immediately rather than searching for them.

Why?

Related to #53539, closes #53539.

How?

By adding additional logic to the edit-site and edit-post packages (when context is set) we can apply our new context. I could use assistance improving this to simplify the logic maybe with global context conditions that can be defined in one place rather than duplicating code.

Testing Instructions

  1. Open a post, page, or template.
  2. Without selecting a block open up the command palette. You should not see any block action commands (group/ungroup, add before/after, etc).
  3. Now select a block or multiple blocks and open up the command palette again. You should see any block action commands for the selected block (group/ungroup, add before/after, etc).

Testing Instructions for Keyboard

Screenshots or screencast

Screenshot 2023-08-27 at 2 17 37 PM

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @jrtashjian! I'll cc @WordPress/gutenberg-design for any input about the UX and the prominence of these commands.

@@ -124,7 +131,9 @@ function useEditorStyles() {
}

function Layout() {
useCommands();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have the hook in edit post here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove it from the Editor component and leave it where I initially added it in the Layout component. This will make sure things stay consistent between edit-post and edit-site packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5e96629.

@jameskoster
Copy link
Contributor

I think it looks good. The pencil icon for the Remove action threw me though. Should that use the trash icon instead?

@jrtashjian
Copy link
Contributor Author

@jameskoster this PR only exposes the existing commands in a contextual matter. I know these block level actions were recently merged into trunk though. I can update this branch with the latest on trunk to see if icons have been tweaked.

@jrtashjian
Copy link
Contributor Author

Looks like no changes to the icons on trunk but I did run across this follow up issue for tweaking the icons: #53538

@jrtashjian
Copy link
Contributor Author

I've just pushed another PR up for those icon fixes mentioned in the issue I found: #54427

Copy link
Member

@richtabor richtabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid.

Can we also get them in the same order as the block options menu? And let's take out "Move to" from the contextual suggestions.

  • Duplicate
  • Add before
  • Add after
  • Group
  • Ungroup (only shows up when selecting a group)
  • Delete
CleanShot 2023-09-13 at 18 16 04 CleanShot 2023-09-13 at 18 15 51

@jrtashjian
Copy link
Contributor Author

Done. Because of how useCommandLoader functions by giving context to groups of commands, I decided to split the commands into two separate command loaders. This split gives us the ability to control exactly which commands appear in the palette.

  • useActionsCommands registers the command with the palette.
  • useQuickActionsCommands registers the command within a context in the palette.

Re-ordered and removed "Move to"
Screen Shot 2023-09-13 at 23 19 40

"Move to" is still available when searching
Screen Shot 2023-09-13 at 23 19 44

Example with group block selected
Screen Shot 2023-09-13 at 23 19 59

Copy link
Contributor

@draganescu draganescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea with the special quick actions loader, it's the only way to filter out what we don't want to show in quick actions. Otherwise the code looks good.

It also tested well for me.

@richtabor richtabor self-requested a review September 15, 2023 19:09
Copy link
Member

@richtabor richtabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@richtabor
Copy link
Member

@jrtashjian mind rebasing, running the checks again?

@jrtashjian
Copy link
Contributor Author

I rebased but there still seems to be a failing test. It's definitely unrelated to the command palette though. I'm not super familiar with the test suite yet but if someone else is able to help resolve it, I'd appreciate it.

@richtabor
Copy link
Member

@jrtashjian do you mind rebasing/seeing if that fixes the test? 🙇‍♂️

@jrtashjian
Copy link
Contributor Author

@richtabor ok, rebased again and it looks like the previously failing tests passed. However the Performance Tests are taking quite a while to run.

@draganescu draganescu merged commit a54da2d into WordPress:trunk Oct 13, 2023
48 checks passed
@github-actions github-actions bot added this to the Gutenberg 16.9 milestone Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Commands /packages/commands [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add block-specific commands as contextual suggestions
5 participants