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

Show the starter content pattern category on page creation #68806

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
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 @@ -93,7 +93,7 @@ function ZoomOutModeInserters() {
rootClientId: sectionRootClientId,
insertionIndex,
tab: 'patterns',
category: 'all',
category: 'allPatterns',
} );
showInsertionPoint( sectionRootClientId, insertionIndex, {
operation: 'insert',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function PatternCategoryPreviews( {
const { changePage } = pagingProps;

// Hide block pattern preview on unmount.
useEffect( () => () => onHover( null ), [] );
useEffect( () => () => onHover( null ), [ onHover ] );

const onSetPatternSyncFilter = useCallback(
( value ) => {
Expand All @@ -135,6 +135,11 @@ export function PatternCategoryPreviews( {
[ setPatternSourceFilter, changePage ]
);

const categoryLabel =
category.name === starterPatternsCategory?.name
? starterPatternsCategory.label || ''
: category?.label;

return (
<>
<VStack
Expand All @@ -149,7 +154,7 @@ export function PatternCategoryPreviews( {
level={ 4 }
as="div"
>
{ category?.label }
{ categoryLabel }
</Heading>
</FlexBlock>
<PatternsFilter
Expand Down Expand Up @@ -184,7 +189,7 @@ export function PatternCategoryPreviews( {
blockPatterns={ pagingProps.categoryPatterns }
onClickPattern={ onClickPattern }
onHover={ onHover }
label={ category.label }
label={ categoryLabel }
orientation="vertical"
category={ category.name }
isDraggable
Expand Down
15 changes: 13 additions & 2 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ function InserterMenu(
const [ filterValue, setFilterValue, delayedFilterValue ] =
useDebouncedInput( __experimentalFilterValue );
const [ hoveredItem, setHoveredItem ] = useState( null );

/*
* Some components may pass a string as the initial category.
* Convert it to an object to match the expected format.
*/
if ( typeof __experimentalInitialCategory === 'string' ) {
__experimentalInitialCategory = {
name: __experimentalInitialCategory,
};
}

const [ selectedPatternCategory, setSelectedPatternCategory ] = useState(
__experimentalInitialCategory
);
Expand Down Expand Up @@ -128,7 +139,7 @@ function InserterMenu(
}
} );
},
[ onInsertBlocks, onSelect, shouldFocusBlock ]
[ onInsertBlocks, onSelect, shouldFocusBlock, ref ]
);

const onInsertPattern = useCallback(
Expand All @@ -137,7 +148,7 @@ function InserterMenu(
onInsertBlocks( blocks, { patternName }, ...args );
onSelect();
},
[ onInsertBlocks, onSelect ]
[ onInsertBlocks, onSelect, onToggleInsertionPoint ]
);

const onHover = useCallback(
Expand Down
Loading