Skip to content

Commit

Permalink
Remove parent block selector from Block Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
richtabor committed May 8, 2023
1 parent 05ad081 commit b45909e
Showing 1 changed file with 4 additions and 80 deletions.
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

0 comments on commit b45909e

Please sign in to comment.