Skip to content

Commit

Permalink
Merge template parts & patterns categories
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Apr 16, 2024
1 parent bed12ce commit 8688daa
Showing 1 changed file with 60 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -31,16 +30,34 @@ 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 (
<>
<div className="edit-site-sidebar-navigation-screen-patterns__group-header">
<Heading level={ 2 }>{ __( 'Template parts' ) }</Heading>
</div>
<ItemGroup className="edit-site-sidebar-navigation-screen-patterns__group">
<ItemGroup className="edit-site-sidebar-navigation-screen-patterns__group">
{ allPatterns && (
<CategoryItem
key={ allPatterns.name }
count={ allPatterns.count }
label={ allPatterns.label }
icon={ file }
id={ allPatterns.name }
type="pattern"
isActive={
currentCategory === `${ allPatterns.name }` &&
( currentType === PATTERN_TYPES.theme ||
currentType === PATTERN_TYPES.user )
}
/>
) }
<CategoryItem
key="all"
count={ Object.values( areas )
count={ Object.values( templatePartAreas )
.map(
( { templateParts } ) => templateParts?.length || 0
)
Expand All @@ -50,56 +67,42 @@ function TemplatePartGroup( { areas, currentArea, currentType } ) {
id={ 'all-parts' }
type={ TEMPLATE_PART_POST_TYPE }
isActive={
currentArea === 'all-parts' &&
currentCategory === 'all-parts' &&
currentType === TEMPLATE_PART_POST_TYPE
}
/>
{ Object.entries( areas ).map(
( [ area, { label, templateParts } ] ) => (
<CategoryItem
key={ area }
count={ templateParts?.length }
icon={ getTemplatePartIcon( area ) }
label={ label }
id={ area }
type={ TEMPLATE_PART_POST_TYPE }
isActive={
currentArea === area &&
currentType === TEMPLATE_PART_POST_TYPE
}
/>
)
) }
</ItemGroup>
</>
);
}

function PatternCategoriesGroup( {
categories,
currentCategory,
currentType,
} ) {
return (
<>
<ItemGroup className="edit-site-sidebar-navigation-screen-patterns__group">
{ categories.map( ( category ) => (
{ Object.entries( templatePartAreas ).map(
( [ area, { label, templateParts } ] ) => (
<CategoryItem
key={ category.name }
count={ category.count }
label={ category.label }
icon={ file }
id={ category.name }
type="pattern"
key={ area }
count={ templateParts?.length }
icon={ getTemplatePartIcon( area ) }
label={ label }
id={ area }
type={ TEMPLATE_PART_POST_TYPE }
isActive={
currentCategory === `${ category.name }` &&
( currentType === PATTERN_TYPES.theme ||
currentType === PATTERN_TYPES.user )
currentCategory === area &&
currentType === TEMPLATE_PART_POST_TYPE
}
/>
) ) }
</ItemGroup>
</>
)
) }
{ otherPatterns.map( ( category ) => (
<CategoryItem
key={ category.name }
count={ category.count }
label={ category.label }
icon={ file }
id={ category.name }
type="pattern"
isActive={
currentCategory === `${ category.name }` &&
( currentType === PATTERN_TYPES.theme ||
currentType === PATTERN_TYPES.user )
}
/>
) ) }
</ItemGroup>
);
}

Expand Down Expand Up @@ -162,20 +165,12 @@ export default function SidebarNavigationScreenPatterns() {
</Item>
</ItemGroup>
) }
{ hasPatterns && (
<PatternCategoriesGroup
categories={ patternCategories }
currentCategory={ currentCategory }
currentType={ currentType }
/>
) }
{ hasTemplateParts && (
<TemplatePartGroup
areas={ templatePartAreas }
currentArea={ currentCategory }
currentType={ currentType }
/>
) }
<CategoriesGroup
templatePartAreas={ templatePartAreas }
patternCategories={ patternCategories }
currentCategory={ currentCategory }
currentType={ currentType }
/>
</>
) }
</>
Expand Down

0 comments on commit 8688daa

Please sign in to comment.