Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patterns: remove "Template parts" sidebar group #60359

Merged
merged 2 commits into from Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,75 +30,78 @@ import usePatternCategories from './use-pattern-categories';
import useTemplatePartAreas from './use-template-part-areas';
import { store as editSiteStore } from '../../store';

function TemplatePartGroup( { areas, currentArea, currentType } ) {
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">
<CategoryItem
key="all"
count={ Object.values( areas )
.map(
( { templateParts } ) => 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 } ] ) => (
<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,
function CategoriesGroup( {
templatePartAreas,
patternCategories,
currentCategory,
currentType,
} ) {
const [ allPatterns, ...otherPatterns ] = patternCategories;

return (
<>
<ItemGroup className="edit-site-sidebar-navigation-screen-patterns__group">
{ categories.map( ( category ) => (
<ItemGroup className="edit-site-sidebar-navigation-screen-patterns__group">
<CategoryItem
key="all"
count={ Object.values( templatePartAreas )
.map( ( { templateParts } ) => 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 } ] ) => (
<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>
</>
)
) }
<div className="edit-site-sidebar-navigation-screen-patterns__divider" />
{ 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 )
}
/>
) }
{ 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 +164,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
Expand Up @@ -21,3 +21,8 @@
text-transform: uppercase;
}
}

.edit-site-sidebar-navigation-screen-patterns__divider {
border-top: 1px solid $gray-800;
margin: $grid-unit-20 0;
}