From ddfd2e48b7450d5d50d5ac96831fd09553191694 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 14 Jun 2023 19:28:10 +0100 Subject: [PATCH 1/3] Add commands to access template, template parts and styles --- .../src/site-editor-navigation-commands.js | 78 ++++++++++++++++++- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/packages/core-commands/src/site-editor-navigation-commands.js b/packages/core-commands/src/site-editor-navigation-commands.js index a787183a0a610..5c9acf42dcc95 100644 --- a/packages/core-commands/src/site-editor-navigation-commands.js +++ b/packages/core-commands/src/site-editor-navigation-commands.js @@ -6,7 +6,7 @@ import { __ } from '@wordpress/i18n'; import { useMemo } from '@wordpress/element'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; -import { post, page, layout, symbolFilled } from '@wordpress/icons'; +import { post, page, layout, symbolFilled, styles } from '@wordpress/icons'; import { privateApis as routerPrivateApis } from '@wordpress/router'; import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url'; @@ -55,9 +55,6 @@ const getNavigationCommandLoaderPerPostType = ( postType ) => 'getEntityRecords', [ 'postType', postType, query ] ), - // We're using the string literal to check whether we're in the site editor. - /* eslint-disable-next-line @wordpress/data-no-store-string-literals */ - isSiteEditor: !! select( 'edit-site' ), }; }, [ supportsSearch, search ] @@ -114,6 +111,75 @@ const useTemplateNavigationCommandLoader = const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPostType( 'wp_template_part' ); +function useSiteEditorBasicNavigationCommands() { + const history = useHistory(); + const isSiteEditor = getPath( window.location.href )?.includes( + 'site-editor.php' + ); + const commands = useMemo( () => { + const result = []; + result.push( { + name: 'core/edit-site/open-styles', + label: __( 'Open Styles' ), + icon: styles, + callback: ( { close } ) => { + const args = { + path: '/wp_global_styles', + }; + const targetUrl = addQueryArgs( 'site-editor.php', args ); + if ( isSiteEditor ) { + history.push( args ); + } else { + document.location = targetUrl; + } + close(); + }, + } ); + + result.push( { + name: 'core/edit-site/open-templates', + label: __( 'View all templates' ), + icon: layout, + callback: ( { close } ) => { + const args = { + path: '/wp_template', + }; + const targetUrl = addQueryArgs( 'site-editor.php', args ); + if ( isSiteEditor ) { + history.push( args ); + } else { + document.location = targetUrl; + } + close(); + }, + } ); + + result.push( { + name: 'core/edit-site/open-template-parts', + label: __( 'View all template parts' ), + icon: symbolFilled, + callback: ( { close } ) => { + const args = { + path: '/wp_template_part', + }; + const targetUrl = addQueryArgs( 'site-editor.php', args ); + if ( isSiteEditor ) { + history.push( args ); + } else { + document.location = targetUrl; + } + close(); + }, + } ); + return result; + }, [ history, isSiteEditor ] ); + + return { + commands, + isLoading: false, + }; +} + export function useSiteEditorNavigationCommands() { useCommandLoader( { name: 'core/edit-site/navigate-pages', @@ -131,4 +197,8 @@ export function useSiteEditorNavigationCommands() { name: 'core/edit-site/navigate-template-parts', hook: useTemplatePartNavigationCommandLoader, } ); + useCommandLoader( { + name: 'core/edit-site/basic-navigation', + hook: useSiteEditorBasicNavigationCommands, + } ); } From 4d6db58ceb0704db96b5c8a4516e38fe26b0f12a Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 15 Jun 2023 13:46:31 +0100 Subject: [PATCH 2/3] Add more navigation commands --- .../src/site-editor-navigation-commands.js | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/packages/core-commands/src/site-editor-navigation-commands.js b/packages/core-commands/src/site-editor-navigation-commands.js index 5c9acf42dcc95..a8e8140f3ae16 100644 --- a/packages/core-commands/src/site-editor-navigation-commands.js +++ b/packages/core-commands/src/site-editor-navigation-commands.js @@ -118,9 +118,45 @@ function useSiteEditorBasicNavigationCommands() { ); const commands = useMemo( () => { const result = []; + result.push( { + name: 'core/edit-site/open-navigation', + label: __( 'Open navigation' ), + icon: styles, + callback: ( { close } ) => { + const args = { + path: '/navigation', + }; + const targetUrl = addQueryArgs( 'site-editor.php', args ); + if ( isSiteEditor ) { + history.push( args ); + } else { + document.location = targetUrl; + } + close(); + }, + } ); + + result.push( { + name: 'core/edit-site/open-pages', + label: __( 'Open pages' ), + icon: styles, + callback: ( { close } ) => { + const args = { + path: '/page', + }; + const targetUrl = addQueryArgs( 'site-editor.php', args ); + if ( isSiteEditor ) { + history.push( args ); + } else { + document.location = targetUrl; + } + close(); + }, + } ); + result.push( { name: 'core/edit-site/open-styles', - label: __( 'Open Styles' ), + label: __( 'Open style variations' ), icon: styles, callback: ( { close } ) => { const args = { @@ -138,7 +174,7 @@ function useSiteEditorBasicNavigationCommands() { result.push( { name: 'core/edit-site/open-templates', - label: __( 'View all templates' ), + label: __( 'Open templates' ), icon: layout, callback: ( { close } ) => { const args = { @@ -156,7 +192,7 @@ function useSiteEditorBasicNavigationCommands() { result.push( { name: 'core/edit-site/open-template-parts', - label: __( 'View all template parts' ), + label: __( 'Open library' ), icon: symbolFilled, callback: ( { close } ) => { const args = { @@ -200,5 +236,6 @@ export function useSiteEditorNavigationCommands() { useCommandLoader( { name: 'core/edit-site/basic-navigation', hook: useSiteEditorBasicNavigationCommands, + context: 'site-editor', } ); } From f6d25041598d4fb5b47ab038c161e492e67fb288 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 15 Jun 2023 13:49:39 +0100 Subject: [PATCH 3/3] Fix icons --- .../src/site-editor-navigation-commands.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/core-commands/src/site-editor-navigation-commands.js b/packages/core-commands/src/site-editor-navigation-commands.js index a8e8140f3ae16..f516bcec31063 100644 --- a/packages/core-commands/src/site-editor-navigation-commands.js +++ b/packages/core-commands/src/site-editor-navigation-commands.js @@ -6,7 +6,14 @@ import { __ } from '@wordpress/i18n'; import { useMemo } from '@wordpress/element'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; -import { post, page, layout, symbolFilled, styles } from '@wordpress/icons'; +import { + post, + page, + layout, + symbolFilled, + styles, + navigation, +} from '@wordpress/icons'; import { privateApis as routerPrivateApis } from '@wordpress/router'; import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url'; @@ -121,7 +128,7 @@ function useSiteEditorBasicNavigationCommands() { result.push( { name: 'core/edit-site/open-navigation', label: __( 'Open navigation' ), - icon: styles, + icon: navigation, callback: ( { close } ) => { const args = { path: '/navigation', @@ -139,7 +146,7 @@ function useSiteEditorBasicNavigationCommands() { result.push( { name: 'core/edit-site/open-pages', label: __( 'Open pages' ), - icon: styles, + icon: page, callback: ( { close } ) => { const args = { path: '/page',