From 1046b2ecd975a190eaf6ba1f9cc357d026a310dd Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 22 Dec 2025 13:29:10 +0100 Subject: [PATCH 1/4] Block Card: Make the parent block navigation generic, supports any block with list view support --- .../src/components/block-card/index.js | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/packages/block-editor/src/components/block-card/index.js b/packages/block-editor/src/components/block-card/index.js index 38fcd33f1c885f..250e197c3e253c 100644 --- a/packages/block-editor/src/components/block-card/index.js +++ b/packages/block-editor/src/components/block-card/index.js @@ -15,13 +15,14 @@ import { } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import deprecated from '@wordpress/deprecated'; -import { __, isRTL } from '@wordpress/i18n'; +import { __, sprintf, isRTL } from '@wordpress/i18n'; import { chevronLeft, chevronRight, arrowRight, arrowLeft, } from '@wordpress/icons'; +import { getBlockType } from '@wordpress/blocks'; /** * Internal dependencies @@ -29,6 +30,7 @@ import { import { unlock } from '../../lock-unlock'; import { store as blockEditorStore } from '../../store'; import BlockIcon from '../block-icon'; +import { hasListViewSupport } from '../../hooks/list-view'; const { Badge } = unlock( componentsPrivateApis ); @@ -103,18 +105,32 @@ function BlockCard( { ( { title, icon, description } = blockType ); } - const parentNavBlockClientId = useSelect( + const { parentNavBlockClientId, parentBlockName } = useSelect( ( select ) => { if ( parentClientId || isChild || ! allowParentNavigation ) { - return; + return {}; } - const { getBlockParentsByBlockName } = select( blockEditorStore ); + const { getBlockParents, getBlockName } = + select( blockEditorStore ); - return getBlockParentsByBlockName( - clientId, - 'core/navigation', - true - )[ 0 ]; + // Find the closest parent block that is either: + // 1. A navigation block (special case for ad-hoc list view support) + // 2. Any block with listView support + const parents = getBlockParents( clientId, true ); + const foundParentId = parents.find( ( parentId ) => { + const parentName = getBlockName( parentId ); + return ( + parentName === 'core/navigation' || + hasListViewSupport( parentName ) + ); + } ); + + return { + parentNavBlockClientId: foundParentId, + parentBlockName: foundParentId + ? getBlockName( foundParentId ) + : null, + }; }, [ clientId, allowParentNavigation, isChild, parentClientId ] ); @@ -134,14 +150,17 @@ function BlockCard( { className ) } > - { parentNavBlockClientId && ( // This is only used by the Navigation block for now. It's not ideal having Navigation block specific code here. + { parentNavBlockClientId && (