Skip to content

Commit

Permalink
Inserter: Add 'Starter Content' category to the inserter (#66819)
Browse files Browse the repository at this point in the history
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: carolinan <[email protected]>
  • Loading branch information
4 people authored Nov 11, 2024
1 parent 17a1809 commit de52623
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
isPatternFiltered,
allPatternsCategory,
myPatternsCategory,
starterPatternsCategory,
INSERTER_PATTERN_TYPES,
} from './utils';
import { store as blockEditorStore } from '../../../store';
Expand Down Expand Up @@ -86,6 +87,13 @@ export function PatternCategoryPreviews( {
return true;
}

if (
category.name === starterPatternsCategory.name &&
pattern.blockTypes?.includes( 'core/post-content' )
) {
return true;
}

if ( category.name === 'uncategorized' ) {
// The uncategorized category should show all the patterns without any category...
if ( ! pattern.categories ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isPatternFiltered,
allPatternsCategory,
myPatternsCategory,
starterPatternsCategory,
INSERTER_PATTERN_TYPES,
} from './utils';

Expand Down Expand Up @@ -67,6 +68,13 @@ export function usePatternCategories( rootClientId, sourceFilter = 'all' ) {
label: _x( 'Uncategorized' ),
} );
}
if (
filteredPatterns.some( ( pattern ) =>
pattern.blockTypes?.includes( 'core/post-content' )
)
) {
categories.unshift( starterPatternsCategory );
}
if (
filteredPatterns.some(
( pattern ) => pattern.type === INSERTER_PATTERN_TYPES.user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export const myPatternsCategory = {
label: __( 'My patterns' ),
};

export const starterPatternsCategory = {
name: 'core/starter-content',
label: __( 'Starter Content' ),
};

export function isPatternFiltered( pattern, sourceFilter, syncFilter ) {
const isUserPattern = pattern.name.startsWith( 'core/block' );
const isDirectoryPattern =
Expand Down

0 comments on commit de52623

Please sign in to comment.