From 4a3ee6ea038969134efdf810243ed43e223576c8 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Fri, 30 Jun 2023 17:34:03 +1000 Subject: [PATCH] Patterns: Include template parts for custom areas in Uncategorized category --- .../src/components/page-patterns/use-patterns.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/page-patterns/use-patterns.js b/packages/edit-site/src/components/page-patterns/use-patterns.js index 6f3b7407e917dd..a8d76b58cb45d5 100644 --- a/packages/edit-site/src/components/page-patterns/use-patterns.js +++ b/packages/edit-site/src/components/page-patterns/use-patterns.js @@ -38,6 +38,15 @@ const templatePartToPattern = ( templatePart ) => ( { templatePart, } ); +const templatePartCategories = [ 'header', 'footer', 'sidebar' ]; +const templatePartHasCategory = ( item, category ) => { + if ( category === 'uncategorized' ) { + return ! templatePartCategories.includes( item.templatePart.area ); + } + + return item.templatePart.area === category; +}; + const useTemplatePartsAsPatterns = ( categoryId, postType = TEMPLATE_PARTS, @@ -83,7 +92,7 @@ const useTemplatePartsAsPatterns = ( return searchItems( templateParts, filterValue, { categoryId, - hasCategory: ( item, area ) => item.templatePart.area === area, + hasCategory: templatePartHasCategory, } ); }, [ templateParts, filterValue, categoryId ] );