Skip to content

Commit

Permalink
Fix uncategorized category
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jul 5, 2024
1 parent 0d6d391 commit ec45990
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/edit-site/src/components/page-patterns/use-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,21 @@ const selectPatterns = createSelector(
} );
} else {
patterns = searchItems( patterns, search, {
hasCategory: ( item ) => ! item.hasOwnProperty( 'categories' ),
hasCategory: ( item ) => {
if ( item.type === PATTERN_TYPES.user ) {
return (
userPatternCategories?.length &&
( ! item.wp_pattern_category?.length ||
! item.wp_pattern_category.some( ( catId ) =>
userPatternCategories.find(
( cat ) => cat.id === catId
)
) )
);
}

return ! item.hasOwnProperty( 'categories' );
},
} );
}
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ export default function usePatternCategories() {
}
} );
// If the pattern has no categories, add it to uncategorized.
if ( ! pattern.categories?.length ) {
if (
! pattern.wp_pattern_category?.length ||
! pattern.wp_pattern_category.some( ( catId ) =>
userPatternCategories.find( ( cat ) => cat.id === catId )
)
) {
categoryMap.uncategorized.count += 1;
}
} );
Expand Down

0 comments on commit ec45990

Please sign in to comment.