From 22914c40ddc2f7714d3ffc560b5d1b32bf20140a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:36:29 +0200 Subject: [PATCH] Merge template parts & patterns categories --- .../index.js | 143 +++++++++--------- 1 file changed, 68 insertions(+), 75 deletions(-) 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 933ef256cf045..67ebada585748 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 @@ -4,7 +4,6 @@ import { __experimentalItemGroup as ItemGroup, __experimentalItem as Item, - __experimentalHeading as Heading, } from '@wordpress/components'; import { useViewportMatch } from '@wordpress/compose'; import { getTemplatePartIcon } from '@wordpress/editor'; @@ -31,75 +30,77 @@ import usePatternCategories from './use-pattern-categories'; import useTemplatePartAreas from './use-template-part-areas'; import { store as editSiteStore } from '../../store'; -function TemplatePartGroup( { areas, currentArea, currentType } ) { +function CategoriesGroup( { + templatePartAreas, + patternCategories, + currentCategory, + currentType, +} ) { + const [ allPatterns, ...otherPatterns ] = patternCategories; + return ( - <> -
- { __( 'Template parts' ) } -
- + + { allPatterns && ( 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 } + key={ allPatterns.name } + count={ allPatterns.count } + label={ allPatterns.label } + icon={ file } + id={ allPatterns.name } + type="pattern" isActive={ - currentArea === 'all-parts' && - currentType === TEMPLATE_PART_POST_TYPE + currentCategory === `${ allPatterns.name }` && + ( currentType === PATTERN_TYPES.theme || + currentType === PATTERN_TYPES.user ) } /> - { Object.entries( areas ).map( - ( [ area, { label, templateParts } ] ) => ( - - ) - ) } - - - ); -} - -function PatternCategoriesGroup( { - categories, - currentCategory, - currentType, -} ) { - return ( - <> - - { categories.map( ( category ) => ( + ) } + 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={ + currentCategory === 'all-parts' && + currentType === TEMPLATE_PART_POST_TYPE + } + /> + { Object.entries( templatePartAreas ).map( + ( [ area, { label, templateParts } ] ) => ( - ) ) } - - + ) + ) } + { otherPatterns.map( ( category ) => ( + + ) ) } + ); } @@ -162,20 +163,12 @@ export default function SidebarNavigationScreenPatterns() { ) } - { hasPatterns && ( - - ) } - { hasTemplateParts && ( - - ) } + ) }