-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Enable Command Palette in admin dashboard #71030
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
Changes from 1 commit
b2ecac7
1f38ae2
9df8f9a
3e9ff1e
ba390f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||
| <?php | ||||
| /** | ||||
| * Bootstraps the Command Palette in the admin dashboard. | ||||
| * | ||||
| * @package Gutenberg | ||||
| */ | ||||
|
|
||||
| /** | ||||
| * Enqueues the assets required for the Command Palette. | ||||
| * | ||||
| * @global string $pagenow The name of the current admin page being viewed. | ||||
| */ | ||||
| function gutenberg_enqueue_command_palette_assets() { | ||||
| // For now, we don't enqueue assets to the frontend. It may be available in the future. | ||||
| if ( ! is_admin() ) { | ||||
| return; | ||||
| } | ||||
|
|
||||
| global $pagenow, $current_screen; | ||||
|
|
||||
| // The Site Editor and Post Editor already implement the Command Palette | ||||
| // within the app, so do nothing on those pages. | ||||
| if ( in_array( $pagenow, array( 'site-editor.php', 'post.php', 'post-new.php' ), true ) && $current_screen->is_block_editor() ) { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove it from the editors and avoid this check?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it can be removed at the moment. See #71030 (comment) for the reason. We can remove it if we don't use experimental settings, but personally I'd like to iterate a bit more before stabilizing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think we can follow-up with this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My explanation wasn't clear enough. If we remove this check, we'll need to remove the command in the However, removing the command from these two packages will mean that the command won't work when the two packages are bundled into core. However, if we can decide to ship this PR into WP 6.9, we can remove this check along with the core backport PR. I hope I explained it well 😅
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't understand this part, I expect the backport of the new global command and the edit-post edit-site changes to happen at the same time. (6.9)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's right. However, since we need to do the PHP backport and package updates at the same time, we need to do that right before WP 6.9 Beta 1, right?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing is stopping us from doing multiple package updates no?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This kind of issue of having to do php changes and package update at the same time is not new and not specific to this case. I'm not sure it's something we should be thinking about when shipping things to the Gutenberg repo. For me it's a workflow issue.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, I think I might be misunderstanding 😅 I'd like to submit a follow-up PR to remove this check soon. |
||||
| return; | ||||
| } | ||||
|
Comment on lines
+23
to
+25
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This early return is necessary to avoid conflicts with the Command Palette UI in the post editor and site editor. For example:
However, if we can stabilize the "Command Palette everywhere" in the future, we may be able to remove the dependency on the |
||||
|
|
||||
| $gutenberg_experiments = get_option( 'gutenberg-experiments' ); | ||||
| if ( empty( $gutenberg_experiments ) || ! array_key_exists( 'gutenberg-command-palette-everywhere', $gutenberg_experiments ) ) { | ||||
| return; | ||||
| } | ||||
|
|
||||
| wp_enqueue_script( 'wp-commands' ); | ||||
| wp_enqueue_style( 'wp-commands' ); | ||||
| wp_enqueue_script( 'wp-core-commands' ); | ||||
|
|
||||
| $inline_script = <<<JS | ||||
| window.__experimentalEnableCommandPaletteEverywhere = true; | ||||
| wp.coreCommands.initializeCommandPalette(); | ||||
| JS; | ||||
|
|
||||
| wp_add_inline_script( 'wp-core-commands', $inline_script ); | ||||
| } | ||||
|
|
||||
| add_action( 'admin_enqueue_scripts', 'gutenberg_enqueue_command_palette_assets' ); | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,44 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { createRoot, StrictMode } from '@wordpress/element'; | ||
| import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
| import { CommandMenu } from '@wordpress/commands'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { useAdminNavigationCommands } from './admin-navigation-commands'; | ||
| import { useSiteEditorNavigationCommands } from './site-editor-navigation-commands'; | ||
| import { unlock } from './lock-unlock'; | ||
| export { privateApis } from './private-apis'; | ||
|
|
||
| const { RouterProvider } = unlock( routerPrivateApis ); | ||
|
|
||
| // Register core commands and render the Command Palette. | ||
| function CommandPalette() { | ||
| useAdminNavigationCommands(); | ||
| useSiteEditorNavigationCommands(); | ||
| return ( | ||
| <RouterProvider pathArg="p"> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some core commands use the |
||
| <CommandMenu /> | ||
| </RouterProvider> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Initializes the Command Palette. This function does nothing | ||
| * unless the experimental setting is enabled. | ||
| */ | ||
| export function initializeCommandPalette() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm hesitant about whether this should leave in this package or if we should have a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. If the direction of the Command Palette becomes clearer, we may be able to change to a more appropriate approach. |
||
| if ( ! window.__experimentalEnableCommandPaletteEverywhere ) { | ||
| return; | ||
| } | ||
| const root = document.createElement( 'div' ); | ||
| document.body.appendChild( root ); | ||
| createRoot( root ).render( | ||
| <StrictMode> | ||
| <CommandPalette /> | ||
| </StrictMode> | ||
| ); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.