From 49af1ebf123fae3fd484129da7e8c2e5b4e58c4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Maneiro?=
<583546+oandregal@users.noreply.github.com>
Date: Mon, 15 Apr 2024 13:33:16 +0200
Subject: [PATCH 1/3] Sidebar frame: add All Template Parts category
---
.../sidebar-navigation-screen-patterns/index.js | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-patterns/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-patterns/index.js
index 587c24e326c2d..933ef256cf045 100644
--- a/packages/edit-site/src/components/sidebar-navigation-screen-patterns/index.js
+++ b/packages/edit-site/src/components/sidebar-navigation-screen-patterns/index.js
@@ -38,6 +38,22 @@ function TemplatePartGroup( { areas, currentArea, currentType } ) {
{ __( 'Template parts' ) }
+ templateParts?.length || 0
+ )
+ .reduce( ( acc, val ) => acc + val, 0 ) }
+ icon={ getTemplatePartIcon() } /* no name, so it provides the fallback icon */
+ label={ __( 'All template parts' ) }
+ id={ 'all-parts' }
+ type={ TEMPLATE_PART_POST_TYPE }
+ isActive={
+ currentArea === 'all-parts' &&
+ currentType === TEMPLATE_PART_POST_TYPE
+ }
+ />
{ Object.entries( areas ).map(
( [ area, { label, templateParts } ] ) => (
Date: Mon, 15 Apr 2024 13:37:56 +0200
Subject: [PATCH 2/3] Content frame: add header
---
packages/edit-site/src/components/page-patterns/header.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/packages/edit-site/src/components/page-patterns/header.js b/packages/edit-site/src/components/page-patterns/header.js
index ce078900a5229..7cca997c7dd02 100644
--- a/packages/edit-site/src/components/page-patterns/header.js
+++ b/packages/edit-site/src/components/page-patterns/header.js
@@ -40,8 +40,10 @@ export default function PatternsHeader( {
const templatePartArea = templatePartAreas.find(
( area ) => area.area === categoryId
);
- title = templatePartArea?.label;
- description = templatePartArea?.description;
+ title = templatePartArea?.label || __( 'All Template Parts' );
+ description =
+ templatePartArea?.description ||
+ __( 'Includes every template part defined for any area.' );
} else if ( type === PATTERN_TYPES.theme ) {
patternCategory = patternCategories.find(
( category ) => category.name === categoryId
From ee7810720987112d2443a88e82606bac01ac2153 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Maneiro?=
<583546+oandregal@users.noreply.github.com>
Date: Tue, 16 Apr 2024 12:38:41 +0200
Subject: [PATCH 3/3] Content frame: display all parts
---
.../edit-site/src/components/page-patterns/search-items.js | 3 +++
packages/edit-site/src/utils/constants.js | 1 +
2 files changed, 4 insertions(+)
diff --git a/packages/edit-site/src/components/page-patterns/search-items.js b/packages/edit-site/src/components/page-patterns/search-items.js
index b5231964a78d6..8aa4b349f48d7 100644
--- a/packages/edit-site/src/components/page-patterns/search-items.js
+++ b/packages/edit-site/src/components/page-patterns/search-items.js
@@ -16,6 +16,7 @@ const { extractWords, getNormalizedSearchTerms, normalizeString } = unlock(
* Internal dependencies
*/
import {
+ TEMPLATE_PART_ALL_AREAS_CATEGORY,
PATTERN_DEFAULT_CATEGORY,
PATTERN_USER_CATEGORY,
PATTERN_TYPES,
@@ -48,6 +49,7 @@ const removeMatchingTerms = ( unmatchedTerms, unprocessedTerms ) => {
*/
export const searchItems = ( items = [], searchInput = '', config = {} ) => {
const normalizedSearchTerms = getNormalizedSearchTerms( searchInput );
+
// Filter patterns by category: the default category indicates that all patterns will be shown.
const onlyFilterByCategory =
config.categoryId !== PATTERN_DEFAULT_CATEGORY &&
@@ -100,6 +102,7 @@ function getItemSearchRank( item, searchTerm, config ) {
let rank =
categoryId === PATTERN_DEFAULT_CATEGORY ||
+ categoryId === TEMPLATE_PART_ALL_AREAS_CATEGORY ||
( categoryId === PATTERN_USER_CATEGORY &&
item.type === PATTERN_TYPES.user ) ||
hasCategory( item, categoryId )
diff --git a/packages/edit-site/src/utils/constants.js b/packages/edit-site/src/utils/constants.js
index dfae1102df921..395c59afdd647 100644
--- a/packages/edit-site/src/utils/constants.js
+++ b/packages/edit-site/src/utils/constants.js
@@ -21,6 +21,7 @@ export const TEMPLATE_ORIGINS = {
plugin: 'plugin',
};
export const TEMPLATE_PART_AREA_DEFAULT_CATEGORY = 'uncategorized';
+export const TEMPLATE_PART_ALL_AREAS_CATEGORY = 'all-parts';
// Patterns.
export const {