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

Experiment with block drill down in contentOnly mode #64923

Closed
wants to merge 3 commits into from
Closed
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
55 changes: 39 additions & 16 deletions packages/block-editor/src/components/block-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import {
__experimentalVStack as VStack,
} from '@wordpress/components';
import { chevronLeft, chevronRight } from '@wordpress/icons';
import { __, isRTL } from '@wordpress/i18n';
import { __, isRTL, sprintf } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import BlockIcon from '../block-icon';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

function BlockCard( { title, icon, description, blockType, className } ) {
if ( blockType ) {
Expand All @@ -31,29 +32,51 @@ function BlockCard( { title, icon, description, blockType, className } ) {
( { title, icon, description } = blockType );
}

const { parentNavBlockClientId } = useSelect( ( select ) => {
const { getSelectedBlockClientId, getBlockParentsByBlockName } =
select( blockEditorStore );
const { parentNavBlockClientId, contentLockedParentClientId } = useSelect(
( select ) => {
const {
getSelectedBlockClientId,
getBlockParentsByBlockName,
getContentLockingParent,
} = unlock( select( blockEditorStore ) );

const _selectedBlockClientId = getSelectedBlockClientId();
const _selectedBlockClientId = getSelectedBlockClientId();

return {
parentNavBlockClientId: getBlockParentsByBlockName(
_selectedBlockClientId,
'core/navigation',
true
)[ 0 ],
};
}, [] );
return {
parentNavBlockClientId: getBlockParentsByBlockName(
_selectedBlockClientId,
'core/navigation',
true
)[ 0 ],
contentLockedParentClientId: getContentLockingParent(
_selectedBlockClientId
),
};
},
[]
);

const hasContentLockedParent = contentLockedParentClientId !== undefined;

const { selectBlock } = useDispatch( blockEditorStore );

return (
<div className={ clsx( 'block-editor-block-card', className ) }>
{ parentNavBlockClientId && ( // This is only used by the Navigation block for now. It's not ideal having Navigation block specific code here.
{ ( parentNavBlockClientId || hasContentLockedParent ) && ( // This is only used by the Navigation block for now. It's not ideal having Navigation block specific code here.
<Button
onClick={ () => selectBlock( parentNavBlockClientId ) }
label={ __( 'Go to parent Navigation block' ) }
onClick={ () => {
const targetClientId =
parentNavBlockClientId ||
contentLockedParentClientId;
selectBlock( targetClientId );
} }
label={ sprintf(
// Translators: Go to the parent navigation block or the parent block.
__( 'Go to %s' ),
parentNavBlockClientId
? 'parent navigation block'
: 'parent block'
) }
style={
// TODO: This style override is also used in ToolsPanelHeader.
// It should be supported out-of-the-box by Button.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
getSelectedBlockClientId,
getSelectedBlockCount,
getBlockName,
getContentLockingParent,
getTemplateLock,
} = unlock( select( blockEditorStore ) );
const _selectedBlockClientId = getSelectedBlockClientId();
Expand All @@ -113,11 +112,10 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
selectedBlockName: _selectedBlockName,
blockType: _blockType,
topLevelLockedBlock:
getContentLockingParent( _selectedBlockClientId ) ||
( getTemplateLock( _selectedBlockClientId ) === 'contentOnly' ||
getTemplateLock( _selectedBlockClientId ) === 'contentOnly' ||
_selectedBlockName === 'core/block'
? _selectedBlockClientId
: undefined ),
: undefined,
};
}, [] );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
Flex,
FlexBlock,
FlexItem,
Icon,
} from '@wordpress/components';
import { chevronLeftSmall, chevronRightSmall } from '@wordpress/icons';
import { isRTL } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down Expand Up @@ -42,18 +45,24 @@ function BlockQuickNavigationItem( { clientId, onSelect } ) {
clientId,
context: 'list-view',
} );
const { isSelected } = useSelect(

const isSynced = blockInformation?.isSynced;

const { isSelected, showDrillDown } = useSelect(
( select ) => {
const { isBlockSelected, hasSelectedInnerBlock } =
select( blockEditorStore );

const _showDrillDown = ! isSynced;

return {
isSelected:
isBlockSelected( clientId ) ||
hasSelectedInnerBlock( clientId, /* deep: */ true ),
showDrillDown: _showDrillDown,
};
},
[ clientId ]
[ isSynced, clientId ]
);
const { selectBlock } = useDispatch( blockEditorStore );

Expand All @@ -76,6 +85,16 @@ function BlockQuickNavigationItem( { clientId, onSelect } ) {
<FlexBlock style={ { textAlign: 'left' } }>
<Truncate>{ blockTitle }</Truncate>
</FlexBlock>

{ showDrillDown && (
<FlexItem>
<Icon
icon={
isRTL() ? chevronLeftSmall : chevronRightSmall
}
/>
</FlexItem>
) }
</Flex>
</Button>
);
Expand Down
Loading