From 3701a7bc88f62d440d79bd8162a5b6b7e7d31543 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Tue, 13 Jun 2023 11:52:26 +0200 Subject: [PATCH] Remove unnecessary wrapper functions, unused imports, clean up code, onClick => onSelect --- .../block-settings-menu-controls/README.md | 2 +- .../block-settings-menu-controls/index.js | 1 - .../block-settings-dropdown.js | 2 +- .../block-editor/src/hooks/content-lock-ui.js | 46 ++++---- .../src/template-part/edit/index.js | 42 ++++--- .../plugin-block-settings-menu-item.js | 3 +- .../reusable-block-convert-button.js | 110 +++++++++--------- 7 files changed, 98 insertions(+), 108 deletions(-) diff --git a/packages/block-editor/src/components/block-settings-menu-controls/README.md b/packages/block-editor/src/components/block-settings-menu-controls/README.md index 87a7ee5a7df0b2..cb489120a7e47f 100644 --- a/packages/block-editor/src/components/block-settings-menu-controls/README.md +++ b/packages/block-editor/src/components/block-settings-menu-controls/README.md @@ -13,7 +13,7 @@ function ReusableBlocksMenuItems() { {/* Is this a breaking change? */} {/* Should this use a menu item example? */} - { () => } + ); } diff --git a/packages/block-editor/src/components/block-settings-menu-controls/index.js b/packages/block-editor/src/components/block-settings-menu-controls/index.js index cbe2264ede428f..46a7fbb9b5c238 100644 --- a/packages/block-editor/src/components/block-settings-menu-controls/index.js +++ b/packages/block-editor/src/components/block-settings-menu-controls/index.js @@ -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'; /** diff --git a/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js b/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js index 4a6d0d927f7d07..cee98d210a5e05 100644 --- a/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js +++ b/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js @@ -426,7 +426,7 @@ export function BlockSettingsDropdown( { - { () => ( - /* TODO: check if this used in other legacy dropdown menus */ - { - __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' ) } - - ) } + { /* TODO: check if this used in other legacy dropdown menus */ } + { + __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' ) } + ) } diff --git a/packages/block-library/src/template-part/edit/index.js b/packages/block-library/src/template-part/edit/index.js index c256f2c67fcdbe..b2a4ed546d0ed4 100644 --- a/packages/block-library/src/template-part/edit/index.js +++ b/packages/block-library/src/template-part/edit/index.js @@ -163,28 +163,26 @@ export default function TemplatePartEdit( { ) } { canReplace && ( - { () => ( - /* TODO: check if this used in other legacy dropdown menus */ - { - setIsTemplatePartSelectionOpen( true ); - // Keep the dropdown menu open - event.preventDefault(); - } } - > - { createInterpolateElement( - __( 'Replace ' ), - { - BlockTitle: ( - - ), - } - ) } - - ) } + { /* TODO: check if this used in other legacy dropdown menus */ } + { + setIsTemplatePartSelectionOpen( true ); + // Keep the dropdown menu open + event.preventDefault(); + } } + > + { createInterpolateElement( + __( 'Replace ' ), + { + BlockTitle: ( + + ), + } + ) } + ) } { isEntityAvailable && ( diff --git a/packages/edit-post/src/components/block-settings-menu/plugin-block-settings-menu-item.js b/packages/edit-post/src/components/block-settings-menu/plugin-block-settings-menu-item.js index 382344af595867..edfcf34ae51988 100644 --- a/packages/edit-post/src/components/block-settings-menu/plugin-block-settings-menu-item.js +++ b/packages/edit-post/src/components/block-settings-menu/plugin-block-settings-menu-item.js @@ -6,7 +6,6 @@ import { Icon, privateApis as componentsPrivateApis, } from '@wordpress/components'; -import { compose } from '@wordpress/compose'; /** * Internal dependencies @@ -97,7 +96,7 @@ const PluginBlockSettingsMenuItem = ( { role, } ) => ( - { ( { selectedBlocks /*onClose*/ } ) => { + { ( { selectedBlocks } ) => { if ( ! shouldRenderItem( selectedBlocks, allowedBlocks ) ) { return null; } diff --git a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js index ac18319fe0c4d6..a7a23dcb1f36c3 100644 --- a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js +++ b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-convert-button.js @@ -112,69 +112,67 @@ export default function ReusableBlockConvertButton( { /* TODO: check if this used in other legacy dropdown menus */ return ( - { () => ( - <> - } - onSelect={ ( event ) => { - setIsModalOpen( true ); - // Keep the dropdown menu open - event.preventDefault(); + <> + } + onSelect={ ( event ) => { + setIsModalOpen( true ); + // Keep the dropdown menu open + event.preventDefault(); + } } + > + { __( 'Create Reusable block' ) } + + { isModalOpen && ( + { + setIsModalOpen( false ); + setTitle( '' ); } } + overlayClassName="reusable-blocks-menu-items__convert-modal" > - { __( 'Create Reusable block' ) } - - { isModalOpen && ( - { +
{ + 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" > - { - 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(); - } } - > - - - - + + + + - - - - -
- ) } - - ) } + + + + + + ) } +
); }