From f80a769f2c0800a9a670fd4159d144472119e204 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 1 Apr 2019 14:56:49 +0200 Subject: [PATCH 1/4] Fix property name in PluginBlockSettingsMenuItem --- .../block-settings-menu/plugin-block-settings-menu-item.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 7a7451a983ce3..9ba873e0362bf 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 @@ -18,7 +18,7 @@ const isEverySelectedBlockAllowed = ( selected, allowed ) => difference( selecte /** * Plugins may want to add an item to the menu either for every block - * or only for the specific ones provided in the `allowedBlocks` component property. + * or only for the specific ones provided in the `allowedBlockNames` component property. * * If there are multiple blocks selected the item will be rendered if every block * is of one allowed type (not necessarily the same). @@ -83,10 +83,10 @@ const shouldRenderItem = ( selectedBlockNames, allowedBlockNames ) => ! Array.is * * @return {WPElement} The WPElement to be rendered. */ -const PluginBlockSettingsMenuItem = ( { allowedBlocks, icon, label, onClick, small, role } ) => ( +const PluginBlockSettingsMenuItem = ( { allowedBlockNames, icon, label, onClick, small, role } ) => ( { ( { selectedBlocks, onClose } ) => { - if ( ! shouldRenderItem( selectedBlocks, allowedBlocks ) ) { + if ( ! shouldRenderItem( selectedBlocks, allowedBlockNames ) ) { return null; } return ( Date: Mon, 1 Apr 2019 15:54:23 +0200 Subject: [PATCH 2/4] Rename component prop the other way around --- packages/edit-post/README.md | 6 +++--- .../plugin-block-settings-menu-item.js | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/edit-post/README.md b/packages/edit-post/README.md index 1ad054b97bce0..4c2c8e46b2cfb 100644 --- a/packages/edit-post/README.md +++ b/packages/edit-post/README.md @@ -61,7 +61,7 @@ function MyPluginBlockSettingsMenuItem() { return wp.element.createElement( PluginBlockSettingsMenuItem, { - allowedBlockNames: [ 'core/paragraph' ], + allowedBlocks: [ 'core/paragraph' ], icon: 'dashicon-name', label: __( 'Menu item text' ), onClick: doOnClick, @@ -81,7 +81,7 @@ const doOnClick = ( ) => { const MyPluginBlockSettingsMenuItem = () => ( @@ -91,7 +91,7 @@ const MyPluginBlockSettingsMenuItem = () => ( _Parameters_ - _props_ `Object`: Component props. -- _props.allowedBlockNames_ `[Array]`: An array containing a list of block names for which the item should be shown. If not present, it'll be rendered for any block. If multiple blocks are selected, it'll be shown if and only if all of them are in the whitelist. +- _props.allowedBlocks_ `[Array]`: An array containing a list of block names for which the item should be shown. If not present, it'll be rendered for any block. If multiple blocks are selected, it'll be shown if and only if all of them are in the whitelist. - _props.icon_ `[(string|Element)]`: The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element. - _props.label_ `string`: The menu item text. - _props.onClick_ `Function`: Callback function to be executed when the user click the menu item. 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 9ba873e0362bf..910ac677e8c6a 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 @@ -34,7 +34,7 @@ const shouldRenderItem = ( selectedBlockNames, allowedBlockNames ) => ! Array.is * Renders a new item in the block settings menu. * * @param {Object} props Component props. - * @param {Array} [props.allowedBlockNames] An array containing a list of block names for which the item should be shown. If not present, it'll be rendered for any block. If multiple blocks are selected, it'll be shown if and only if all of them are in the whitelist. + * @param {Array} [props.allowedBlocks] An array containing a list of block names for which the item should be shown. If not present, it'll be rendered for any block. If multiple blocks are selected, it'll be shown if and only if all of them are in the whitelist. * @param {string|Element} [props.icon] The [Dashicon](https://developer.wordpress.org/resource/dashicons/) icon slug string, or an SVG WP element. * @param {string} props.label The menu item text. * @param {Function} props.onClick Callback function to be executed when the user click the menu item. @@ -53,7 +53,7 @@ const shouldRenderItem = ( selectedBlockNames, allowedBlockNames ) => ! Array.is * return wp.element.createElement( * PluginBlockSettingsMenuItem, * { - * allowedBlockNames: [ 'core/paragraph' ], + * allowedBlocks: [ 'core/paragraph' ], * icon: 'dashicon-name', * label: __( 'Menu item text' ), * onClick: doOnClick, @@ -74,7 +74,7 @@ const shouldRenderItem = ( selectedBlockNames, allowedBlockNames ) => ! Array.is * * const MyPluginBlockSettingsMenuItem = () => ( * @@ -83,10 +83,10 @@ const shouldRenderItem = ( selectedBlockNames, allowedBlockNames ) => ! Array.is * * @return {WPElement} The WPElement to be rendered. */ -const PluginBlockSettingsMenuItem = ( { allowedBlockNames, icon, label, onClick, small, role } ) => ( +const PluginBlockSettingsMenuItem = ( { allowedBlocks, icon, label, onClick, small, role } ) => ( { ( { selectedBlocks, onClose } ) => { - if ( ! shouldRenderItem( selectedBlocks, allowedBlockNames ) ) { + if ( ! shouldRenderItem( selectedBlocks, allowedBlocks ) ) { return null; } return ( Date: Mon, 1 Apr 2019 16:10:30 +0200 Subject: [PATCH 3/4] Undo rename in shouldRenderItem docblock --- .../block-settings-menu/plugin-block-settings-menu-item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 910ac677e8c6a..8f41dd8334dc8 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 @@ -18,7 +18,7 @@ const isEverySelectedBlockAllowed = ( selected, allowed ) => difference( selecte /** * Plugins may want to add an item to the menu either for every block - * or only for the specific ones provided in the `allowedBlockNames` component property. + * or only for the specific ones provided in the `allowedBlocks` component property. * * If there are multiple blocks selected the item will be rendered if every block * is of one allowed type (not necessarily the same). From f2ec314f994597eb95b3177e0a510e7404d94196 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 1 Apr 2019 16:52:49 +0200 Subject: [PATCH 4/4] Change shouldRenderItem function signature for more internal consistency --- .../plugin-block-settings-menu-item.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 8f41dd8334dc8..038723cc1b44b 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 @@ -23,12 +23,12 @@ const isEverySelectedBlockAllowed = ( selected, allowed ) => difference( selecte * If there are multiple blocks selected the item will be rendered if every block * is of one allowed type (not necessarily the same). * - * @param {string[]} selectedBlockNames Array containing the names of the blocks selected - * @param {string[]} allowedBlockNames Array containing the names of the blocks allowed + * @param {string[]} selectedBlocks Array containing the names of the blocks selected + * @param {string[]} allowedBlocks Array containing the names of the blocks allowed * @return {boolean} Whether the item will be rendered or not. */ -const shouldRenderItem = ( selectedBlockNames, allowedBlockNames ) => ! Array.isArray( allowedBlockNames ) || - isEverySelectedBlockAllowed( selectedBlockNames, allowedBlockNames ); +const shouldRenderItem = ( selectedBlocks, allowedBlocks ) => ! Array.isArray( allowedBlocks ) || + isEverySelectedBlockAllowed( selectedBlocks, allowedBlocks ); /** * Renders a new item in the block settings menu.