From 688157b9cca123799f632886ced2e47e1ca07959 Mon Sep 17 00:00:00 2001 From: Brian Coords Date: Wed, 1 May 2024 07:00:50 -0700 Subject: [PATCH 1/3] adds template parts command to editor --- .../src/site-editor-navigation-commands.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/core-commands/src/site-editor-navigation-commands.js b/packages/core-commands/src/site-editor-navigation-commands.js index 695ad00e567203..7f1eb171aa37f9 100644 --- a/packages/core-commands/src/site-editor-navigation-commands.js +++ b/packages/core-commands/src/site-editor-navigation-commands.js @@ -338,6 +338,26 @@ function useSiteEditorBasicNavigationCommands() { }, } ); + result.push( { + name: 'core/edit-site/open-template-parts', + label: __( 'Template Parts' ), + icon: symbolFilled, + callback: ( { close } ) => { + const args = { + path: '/patterns', + categoryType: 'wp_template_part', + categoryId: 'all-parts', + }; + const targetUrl = addQueryArgs( 'site-editor.php', args ); + if ( isSiteEditor ) { + history.push( args ); + } else { + document.location = targetUrl; + } + close(); + }, + } ); + return result; }, [ history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme ] ); From 99d372216afcb04ffd2490563261ac9be8812fdb Mon Sep 17 00:00:00 2001 From: Brian Coords Date: Wed, 1 May 2024 07:17:15 -0700 Subject: [PATCH 2/3] moves template-part command from main navigation --- .../src/admin-navigation-commands.js | 22 ++++++++++++++++++- .../src/site-editor-navigation-commands.js | 20 ----------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/core-commands/src/admin-navigation-commands.js b/packages/core-commands/src/admin-navigation-commands.js index 4de403761f4cc4..83a6f56117969a 100644 --- a/packages/core-commands/src/admin-navigation-commands.js +++ b/packages/core-commands/src/admin-navigation-commands.js @@ -3,7 +3,7 @@ */ import { useCommand } from '@wordpress/commands'; import { __ } from '@wordpress/i18n'; -import { plus, symbol } from '@wordpress/icons'; +import { plus, symbol, symbolFilled } from '@wordpress/icons'; import { addQueryArgs, getPath } from '@wordpress/url'; import { privateApis as routerPrivateApis } from '@wordpress/router'; @@ -63,4 +63,24 @@ export function useAdminNavigationCommands() { } }, } ); + + useCommand( { + name: 'core/edit-site/open-template-parts', + label: __( 'Template Parts' ), + icon: symbolFilled, + callback: ( { close } ) => { + const args = { + path: '/patterns', + categoryType: 'wp_template_part', + categoryId: 'all-parts', + }; + const targetUrl = addQueryArgs( 'site-editor.php', args ); + if ( isSiteEditor ) { + history.push( args ); + } else { + document.location = targetUrl; + } + close(); + }, + } ); } diff --git a/packages/core-commands/src/site-editor-navigation-commands.js b/packages/core-commands/src/site-editor-navigation-commands.js index 7f1eb171aa37f9..695ad00e567203 100644 --- a/packages/core-commands/src/site-editor-navigation-commands.js +++ b/packages/core-commands/src/site-editor-navigation-commands.js @@ -338,26 +338,6 @@ function useSiteEditorBasicNavigationCommands() { }, } ); - result.push( { - name: 'core/edit-site/open-template-parts', - label: __( 'Template Parts' ), - icon: symbolFilled, - callback: ( { close } ) => { - const args = { - path: '/patterns', - categoryType: 'wp_template_part', - categoryId: 'all-parts', - }; - const targetUrl = addQueryArgs( 'site-editor.php', args ); - if ( isSiteEditor ) { - history.push( args ); - } else { - document.location = targetUrl; - } - close(); - }, - } ); - return result; }, [ history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme ] ); From e9e0b79b7dd41ea1635b4d2b182e17fa737e5e67 Mon Sep 17 00:00:00 2001 From: Brian Coords Date: Wed, 8 May 2024 08:32:41 -0700 Subject: [PATCH 3/3] moves template part command from admin navigatino to the template part command loader --- .../src/admin-navigation-commands.js | 22 +---- .../src/site-editor-navigation-commands.js | 85 +++++++++++++------ 2 files changed, 62 insertions(+), 45 deletions(-) diff --git a/packages/core-commands/src/admin-navigation-commands.js b/packages/core-commands/src/admin-navigation-commands.js index b4de24b36f3cfd..a833ad8c9ad027 100644 --- a/packages/core-commands/src/admin-navigation-commands.js +++ b/packages/core-commands/src/admin-navigation-commands.js @@ -3,7 +3,7 @@ */ import { useCommand } from '@wordpress/commands'; import { __ } from '@wordpress/i18n'; -import { plus, symbol, symbolFilled } from '@wordpress/icons'; +import { plus, symbol } from '@wordpress/icons'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import { addQueryArgs, getPath } from '@wordpress/url'; @@ -66,24 +66,4 @@ export function useAdminNavigationCommands() { } }, } ); - - useCommand( { - name: 'core/edit-site/open-template-parts', - label: __( 'Template Parts' ), - icon: symbolFilled, - callback: ( { close } ) => { - const args = { - path: '/patterns', - categoryType: 'wp_template_part', - categoryId: 'all-parts', - }; - const targetUrl = addQueryArgs( 'site-editor.php', args ); - if ( isSiteEditor ) { - history.push( args ); - } else { - document.location = targetUrl; - } - close(); - }, - } ); } diff --git a/packages/core-commands/src/site-editor-navigation-commands.js b/packages/core-commands/src/site-editor-navigation-commands.js index 64e0082d5910a9..4269e8415ff149 100644 --- a/packages/core-commands/src/site-editor-navigation-commands.js +++ b/packages/core-commands/src/site-editor-navigation-commands.js @@ -196,31 +196,67 @@ const getNavigationCommandLoaderPerTemplate = ( templateType ) => ) { return []; } - return orderedRecords.map( ( record ) => { - const isSiteEditor = getPath( window.location.href )?.includes( - 'site-editor.php' - ); - const extraArgs = isSiteEditor - ? { canvas: getQueryArg( window.location.href, 'canvas' ) } - : {}; + const isSiteEditor = getPath( window.location.href )?.includes( + 'site-editor.php' + ); + const result = []; + result.push( + ...orderedRecords.map( ( record ) => { + const extraArgs = isSiteEditor + ? { + canvas: getQueryArg( + window.location.href, + 'canvas' + ), + } + : {}; - return { - name: templateType + '-' + record.id, - searchLabel: record.title?.rendered + ' ' + record.id, - label: record.title?.rendered - ? record.title?.rendered - : __( '(no title)' ), - icon: icons[ templateType ], + return { + name: templateType + '-' + record.id, + searchLabel: record.title?.rendered + ' ' + record.id, + label: record.title?.rendered + ? record.title?.rendered + : __( '(no title)' ), + icon: icons[ templateType ], + callback: ( { close } ) => { + const args = { + postType: templateType, + postId: record.id, + didAccessPatternsPage: + ! isBlockBasedTheme && + ( isPatternsPage || didAccessPatternsPage ) + ? 1 + : undefined, + ...extraArgs, + }; + const targetUrl = addQueryArgs( + 'site-editor.php', + args + ); + if ( isSiteEditor ) { + history.push( args ); + } else { + document.location = targetUrl; + } + close(); + }, + }; + } ) + ); + + if ( + orderedRecords?.length > 0 && + templateType === 'wp_template_part' + ) { + result.push( { + name: 'core/edit-site/open-template-parts', + label: __( 'Template parts' ), + icon: symbolFilled, callback: ( { close } ) => { const args = { - postType: templateType, - postId: record.id, - didAccessPatternsPage: - ! isBlockBasedTheme && - ( isPatternsPage || didAccessPatternsPage ) - ? 1 - : undefined, - ...extraArgs, + path: '/patterns', + categoryType: 'wp_template_part', + categoryId: 'all-parts', }; const targetUrl = addQueryArgs( 'site-editor.php', @@ -233,8 +269,9 @@ const getNavigationCommandLoaderPerTemplate = ( templateType ) => } close(); }, - }; - } ); + } ); + } + return result; }, [ isBlockBasedTheme, orderedRecords, history ] ); return {