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

Remove parent block selector from Block Settings Menu #50443

Closed
wants to merge 1 commit into from
Closed
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
@@ -1,35 +1,24 @@
/**
* WordPress dependencies
*/
import {
getBlockType,
serialize,
store as blocksStore,
} from '@wordpress/blocks';
import { serialize } from '@wordpress/blocks';
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { useSelect } from '@wordpress/data';
import { moreVertical } from '@wordpress/icons';
import {
Children,
cloneElement,
useCallback,
useRef,
} from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { Children, cloneElement, useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { pipe, useCopyToClipboard } from '@wordpress/compose';

/**
* Internal dependencies
*/
import BlockActions from '../block-actions';
import BlockIcon from '../block-icon';
import BlockModeToggle from './block-mode-toggle';
import BlockHTMLConvertButton from './block-html-convert-button';
import __unstableBlockSettingsMenuFirstItem from './block-settings-menu-first-item';
import BlockSettingsMenuControls from '../block-settings-menu-controls';
import { store as blockEditorStore } from '../../store';
import { useShowMoversGestures } from '../block-toolbar/utils';

const noop = () => {};
const POPOVER_PROPS = {
Expand Down Expand Up @@ -60,43 +49,26 @@ export function BlockSettingsDropdown( {
const firstBlockClientId = blockClientIds[ 0 ];
const {
firstParentClientId,
isDistractionFree,
onlyBlock,
parentBlockType,
previousBlockClientId,
nextBlockClientId,
selectedBlockClientIds,
} = useSelect(
( select ) => {
const {
getBlockCount,
getBlockName,
getBlockRootClientId,
getPreviousBlockClientId,
getNextBlockClientId,
getSelectedBlockClientIds,
getSettings,
getBlockAttributes,
} = select( blockEditorStore );

const { getActiveBlockVariation } = select( blocksStore );

const _firstParentClientId =
getBlockRootClientId( firstBlockClientId );
const parentBlockName =
_firstParentClientId && getBlockName( _firstParentClientId );

return {
firstParentClientId: _firstParentClientId,
isDistractionFree: getSettings().isDistractionFree,
onlyBlock: 1 === getBlockCount( _firstParentClientId ),
parentBlockType:
_firstParentClientId &&
( getActiveBlockVariation(
parentBlockName,
getBlockAttributes( _firstParentClientId )
) ||
getBlockType( parentBlockName ) ),
previousBlockClientId:
getPreviousBlockClientId( firstBlockClientId ),
nextBlockClientId: getNextBlockClientId( firstBlockClientId ),
Expand All @@ -122,9 +94,6 @@ export function BlockSettingsDropdown( {
};
}, [] );

const { selectBlock, toggleBlockHighlight } =
useDispatch( blockEditorStore );

const updateSelectionAfterDuplicate = useCallback(
__experimentalSelectBlock
? async ( clientIdsPromise ) => {
Expand Down Expand Up @@ -170,24 +139,6 @@ export function BlockSettingsDropdown( {
const removeBlockLabel =
count === 1 ? __( 'Delete' ) : __( 'Delete blocks' );

// Allows highlighting the parent block outline when focusing or hovering
// the parent block selector within the child.
const selectParentButtonRef = useRef();
const { gestures: showParentOutlineGestures } = useShowMoversGestures( {
ref: selectParentButtonRef,
onChange( isFocused ) {
if ( isFocused && isDistractionFree ) {
return;
}
toggleBlockHighlight( firstParentClientId, isFocused );
},
} );

// This can occur when the selected block (the parent)
// displays child blocks within a List View.
const parentBlockIsSelected =
selectedBlockClientIds?.includes( firstParentClientId );

return (
<BlockActions
clientIds={ clientIds }
Expand Down Expand Up @@ -221,33 +172,6 @@ export function BlockSettingsDropdown( {
<__unstableBlockSettingsMenuFirstItem.Slot
fillProps={ { onClose } }
/>
{ ! parentBlockIsSelected &&
!! firstParentClientId && (
<MenuItem
{ ...showParentOutlineGestures }
ref={ selectParentButtonRef }
icon={
<BlockIcon
icon={
parentBlockType.icon
}
/>
}
onClick={ () =>
selectBlock(
firstParentClientId
)
}
>
{ sprintf(
/* translators: %s: Name of the block's parent. */
__(
'Select parent block (%s)'
),
parentBlockType.title
) }
</MenuItem>
) }
{ count === 1 && (
<BlockHTMLConvertButton
clientId={ firstBlockClientId }
Expand Down