Skip to content

Commit

Permalink
Remove unnecessary wrapper functions, unused imports, clean up code, …
Browse files Browse the repository at this point in the history
…onClick => onSelect
  • Loading branch information
ciampo committed Jun 13, 2023
1 parent e01b967 commit 3701a7b
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function ReusableBlocksMenuItems() {
<BlockSettingsMenuControls>
{/* Is this a breaking change? */}
{/* Should this use a menu item example? */}
{ () => <MyToggleButton onToggle={ /* ... */ } /> }
<MyToggleButton onToggle={ /* ... */ } />
</BlockSettingsMenuControls>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { pipe } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export function BlockSettingsDropdown( {
<DropdownMenuSeparatorV2 />
<DropdownMenuGroupV2>
<DropdownMenuItemV2
onClick={ pipe(
onSelect={ pipe(
onRemove,
updateSelectionAfterRemove
) }
Expand Down
46 changes: 21 additions & 25 deletions packages/block-editor/src/hooks/content-lock-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,31 +130,27 @@ export const withBlockControls = createHigherOrderComponent(
) }
{ showStartEditingAsBlocks && (
<BlockSettingsMenuControls>
{ () => (
/* TODO: check if this used in other legacy dropdown menus */
<DropdownMenuItemV2
onSelect={ () => {
__unstableMarkNextChangeAsNotPersistent();
updateBlockAttributes( props.clientId, {
templateLock: undefined,
} );
updateBlockListSettings( props.clientId, {
...getBlockListSettings(
props.clientId
),
templateLock: false,
} );
focusModeToRevert.current =
getSettings().focusMode;
updateSettings( { focusMode: true } );
__unstableSetTemporarilyEditingAsBlocks(
props.clientId
);
} }
>
{ __( 'Modify' ) }
</DropdownMenuItemV2>
) }
{ /* TODO: check if this used in other legacy dropdown menus */ }
<DropdownMenuItemV2
onSelect={ () => {
__unstableMarkNextChangeAsNotPersistent();
updateBlockAttributes( props.clientId, {
templateLock: undefined,
} );
updateBlockListSettings( props.clientId, {
...getBlockListSettings( props.clientId ),
templateLock: false,
} );
focusModeToRevert.current =
getSettings().focusMode;
updateSettings( { focusMode: true } );
__unstableSetTemporarilyEditingAsBlocks(
props.clientId
);
} }
>
{ __( 'Modify' ) }
</DropdownMenuItemV2>
</BlockSettingsMenuControls>
) }
<BlockEdit key="edit" { ...props } />
Expand Down
42 changes: 20 additions & 22 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,28 +163,26 @@ export default function TemplatePartEdit( {
) }
{ canReplace && (
<BlockSettingsMenuControls>
{ () => (
/* TODO: check if this used in other legacy dropdown menus */
<DropdownMenuItemV2
onSelect={ ( event ) => {
setIsTemplatePartSelectionOpen( true );
// Keep the dropdown menu open
event.preventDefault();
} }
>
{ createInterpolateElement(
__( 'Replace <BlockTitle />' ),
{
BlockTitle: (
<BlockTitle
clientId={ clientId }
maximumLength={ 25 }
/>
),
}
) }
</DropdownMenuItemV2>
) }
{ /* TODO: check if this used in other legacy dropdown menus */ }
<DropdownMenuItemV2
onSelect={ ( event ) => {
setIsTemplatePartSelectionOpen( true );
// Keep the dropdown menu open
event.preventDefault();
} }
>
{ createInterpolateElement(
__( 'Replace <BlockTitle />' ),
{
BlockTitle: (
<BlockTitle
clientId={ clientId }
maximumLength={ 25 }
/>
),
}
) }
</DropdownMenuItemV2>
</BlockSettingsMenuControls>
) }
{ isEntityAvailable && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Icon,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { compose } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -97,7 +96,7 @@ const PluginBlockSettingsMenuItem = ( {
role,
} ) => (
<BlockSettingsMenuControls>
{ ( { selectedBlocks /*onClose*/ } ) => {
{ ( { selectedBlocks } ) => {
if ( ! shouldRenderItem( selectedBlocks, allowedBlocks ) ) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,69 +112,67 @@ export default function ReusableBlockConvertButton( {
/* TODO: check if this used in other legacy dropdown menus */
return (
<BlockSettingsMenuControls>
{ () => (
<>
<DropdownMenuItemV2
prefix={ <Icon icon={ symbol } size={ 24 } /> }
onSelect={ ( event ) => {
setIsModalOpen( true );
// Keep the dropdown menu open
event.preventDefault();
<>
<DropdownMenuItemV2
prefix={ <Icon icon={ symbol } size={ 24 } /> }
onSelect={ ( event ) => {
setIsModalOpen( true );
// Keep the dropdown menu open
event.preventDefault();
} }
>
{ __( 'Create Reusable block' ) }
</DropdownMenuItemV2>
{ isModalOpen && (
<Modal
title={ __( 'Create Reusable block' ) }
onRequestClose={ () => {
setIsModalOpen( false );
setTitle( '' );
} }
overlayClassName="reusable-blocks-menu-items__convert-modal"
>
{ __( 'Create Reusable block' ) }
</DropdownMenuItemV2>
{ isModalOpen && (
<Modal
title={ __( 'Create Reusable block' ) }
onRequestClose={ () => {
<form
onSubmit={ ( event ) => {
event.preventDefault();
onConvert( title );
setIsModalOpen( false );
setTitle( '' );
// TODO: the modal is expected to close the dropdown!
// - can we keep it open?
// - can we close the dropdown when the modal is opened instead?
// - otherwise, how do we go about it? We'd need to switch to
// controlled mode at the root, and pass `onClose` around
// onClose();
} }
overlayClassName="reusable-blocks-menu-items__convert-modal"
>
<form
onSubmit={ ( event ) => {
event.preventDefault();
onConvert( title );
setIsModalOpen( false );
setTitle( '' );
// TODO: the modal is expected to close the dropdown!
// - can we keep it open?
// - can we close the dropdown when the modal is opened instead?
// - otherwise, how do we go about it? We'd need to switch to
// controlled mode at the root, and pass `onClose` around
// onClose();
} }
>
<VStack spacing="5">
<TextControl
__nextHasNoMarginBottom
label={ __( 'Name' ) }
value={ title }
onChange={ setTitle }
/>
<HStack justify="right">
<Button
variant="tertiary"
onClick={ () => {
setIsModalOpen( false );
setTitle( '' );
} }
>
{ __( 'Cancel' ) }
</Button>
<VStack spacing="5">
<TextControl
__nextHasNoMarginBottom
label={ __( 'Name' ) }
value={ title }
onChange={ setTitle }
/>
<HStack justify="right">
<Button
variant="tertiary"
onClick={ () => {
setIsModalOpen( false );
setTitle( '' );
} }
>
{ __( 'Cancel' ) }
</Button>

<Button variant="primary" type="submit">
{ __( 'Save' ) }
</Button>
</HStack>
</VStack>
</form>
</Modal>
) }
</>
) }
<Button variant="primary" type="submit">
{ __( 'Save' ) }
</Button>
</HStack>
</VStack>
</form>
</Modal>
) }
</>
</BlockSettingsMenuControls>
);
}

0 comments on commit 3701a7b

Please sign in to comment.