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: Reinstate my patterns category in site editor #54726

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { noCase } from 'change-case';
/**
* Internal dependencies
*/
import { PATTERN_DEFAULT_CATEGORY } from '../../utils/constants';
import {
PATTERN_DEFAULT_CATEGORY,
PATTERN_USER_CATEGORY,
PATTERN_TYPES,
} from '../../utils/constants';

// Default search helpers.
const defaultGetName = ( item ) => item.name || '';
Expand Down Expand Up @@ -141,6 +145,8 @@ function getItemSearchRank( item, searchTerm, config ) {

let rank =
categoryId === PATTERN_DEFAULT_CATEGORY ||
( categoryId === PATTERN_USER_CATEGORY &&
item.type === PATTERN_TYPES.user ) ||
hasCategory( item, categoryId )
? 1
: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import usePatterns from '../page-patterns/use-patterns';
import {
PATTERN_TYPES,
PATTERN_DEFAULT_CATEGORY,
PATTERN_USER_CATEGORY,
TEMPLATE_PART_AREA_DEFAULT_CATEGORY,
} from '../../utils/constants';

Expand Down Expand Up @@ -84,12 +85,20 @@ export default function usePatternCategories() {
const sortedCategories = categoriesWithCounts.sort( ( a, b ) =>
a.label.localeCompare( b.label )
);

sortedCategories.unshift( {
name: PATTERN_USER_CATEGORY,
label: __( 'My patterns' ),
count: userPatterns.length,
} );

sortedCategories.unshift( {
name: PATTERN_DEFAULT_CATEGORY,
label: __( 'All Patterns' ),
label: __( 'All patterns' ),
description: __( 'A list of all patterns from all sources' ),
count: themePatterns.length + userPatterns.length,
} );

return sortedCategories;
}, [
defaultCategories,
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 @@ -26,6 +26,7 @@ export const TEMPLATE_PART_AREA_DEFAULT_CATEGORY = 'uncategorized';
export const {
PATTERN_TYPES,
PATTERN_DEFAULT_CATEGORY,
PATTERN_USER_CATEGORY,
PATTERN_CORE_SOURCES,
PATTERN_SYNC_TYPES,
} = unlock( patternPrivateApis );
Expand Down
1 change: 1 addition & 0 deletions packages/patterns/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const PATTERN_TYPES = {
};

export const PATTERN_DEFAULT_CATEGORY = 'all-patterns';
export const PATTERN_USER_CATEGORY = 'my-patterns';
export const PATTERN_CORE_SOURCES = [
'core',
'pattern-directory/core',
Expand Down
2 changes: 2 additions & 0 deletions packages/patterns/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import PatternsMenuItems from './components';
import {
PATTERN_TYPES,
PATTERN_DEFAULT_CATEGORY,
PATTERN_USER_CATEGORY,
PATTERN_CORE_SOURCES,
PATTERN_SYNC_TYPES,
} from './constants';
Expand All @@ -17,6 +18,7 @@ lock( privateApis, {
PatternsMenuItems,
PATTERN_TYPES,
PATTERN_DEFAULT_CATEGORY,
PATTERN_USER_CATEGORY,
PATTERN_CORE_SOURCES,
PATTERN_SYNC_TYPES,
} );
Loading