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: add a "All Template Parts" section #60775

Merged
merged 3 commits into from
Apr 16, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/edit-site/src/components/page-patterns/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ function TemplatePartGroup( { areas, currentArea, currentType } ) {
<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
Expand Down
1 change: 1 addition & 0 deletions packages/edit-site/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading