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

Inserter: Add 'Starter Content' category to the inserter #66819

Merged
merged 2 commits into from
Nov 11, 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
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;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not great that the categorization logic is duplicated in two components. Feels like something that can be factorized. Maybe within use-patterns-state

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
Loading