From 72198da4b7544797db876f04d7312cdf3bc4bdd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Tue, 16 Apr 2024 14:02:23 +0200 Subject: [PATCH] Patterns: add a "All Template Parts" section (#60775) Co-authored-by: oandregal Co-authored-by: jorgefilipecosta --- .../src/components/page-patterns/header.js | 6 ++++-- .../src/components/page-patterns/search-items.js | 3 +++ .../sidebar-navigation-screen-patterns/index.js | 16 ++++++++++++++++ packages/edit-site/src/utils/constants.js | 1 + 4 files changed, 24 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 ce078900a52297..7cca997c7dd02e 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 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 b5231964a78d68..8aa4b349f48d7c 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/components/sidebar-navigation-screen-patterns/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-patterns/index.js index 587c24e326c2dd..933ef256cf0459 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 } ] ) => (