From 8f9158dfde641b31a0e904cb97a622789d9856dc Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 23 Jun 2023 15:51:44 +1200 Subject: [PATCH] Add a dismissible hint about the rename instead of changing menu labeling --- lib/compat/wordpress-6.3/blocks.php | 2 +- packages/block-editor/README.md | 4 ++ packages/block-editor/src/components/index.js | 5 ++ .../inserter/reusable-block-rename-hint.js | 50 +++++++++++++++++++ .../inserter/reusable-blocks-tab.js | 6 ++- .../src/components/inserter/style.scss | 24 +++++++++ .../src/components/inserter/tabs.js | 2 +- packages/edit-post/src/plugins/index.js | 2 +- .../reusable-block-convert-button.js | 6 +-- .../reusable-blocks-manage-button.js | 2 +- 10 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 packages/block-editor/src/components/inserter/reusable-block-rename-hint.js diff --git a/lib/compat/wordpress-6.3/blocks.php b/lib/compat/wordpress-6.3/blocks.php index dc340e84e36e5f..6902a258c5c3d8 100644 --- a/lib/compat/wordpress-6.3/blocks.php +++ b/lib/compat/wordpress-6.3/blocks.php @@ -41,7 +41,7 @@ function gutenberg_add_selectors_property_to_block_type_settings( $settings, $me */ function gutenberg_rename_reusable_block_cpt_to_pattern( $args, $post_type ) { if ( 'wp_block' === $post_type ) { - $args['labels']['name'] = _x( 'Patterns/Reusable blocks', 'post type general name' ); + $args['labels']['name'] = _x( 'Patterns', 'post type general name' ); $args['labels']['singular_name'] = _x( 'Pattern', 'post type singular name' ); $args['labels']['add_new_item'] = __( 'Add new Pattern' ); $args['labels']['new_item'] = __( 'New Pattern' ); diff --git a/packages/block-editor/README.md b/packages/block-editor/README.md index 72c3d50372e48e..13f9f2723f29de 100644 --- a/packages/block-editor/README.md +++ b/packages/block-editor/README.md @@ -680,6 +680,10 @@ _Related_ Private @wordpress/block-editor APIs. +### ReusableBlocksRenameHint + +Undocumented declaration. + ### RichText _Related_ diff --git a/packages/block-editor/src/components/index.js b/packages/block-editor/src/components/index.js index e804771f9ce64a..a49fd623ac14a3 100644 --- a/packages/block-editor/src/components/index.js +++ b/packages/block-editor/src/components/index.js @@ -164,3 +164,8 @@ export { default as __experimentalInspectorPopoverHeader } from './inspector-pop export { default as BlockEditorProvider } from './provider'; export { default as useSetting } from './use-setting'; + +/* + * The following rename hint component can be removed in 6.4. + */ +export { default as ReusableBlocksRenameHint } from './inserter/reusable-block-rename-hint'; diff --git a/packages/block-editor/src/components/inserter/reusable-block-rename-hint.js b/packages/block-editor/src/components/inserter/reusable-block-rename-hint.js new file mode 100644 index 00000000000000..e75bdea82e3583 --- /dev/null +++ b/packages/block-editor/src/components/inserter/reusable-block-rename-hint.js @@ -0,0 +1,50 @@ +/** + * WordPress dependencies + */ +import { Button } from '@wordpress/components'; +import { useDispatch, useSelect } from '@wordpress/data'; +import { focus } from '@wordpress/dom'; +import { useRef } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; +import { close } from '@wordpress/icons'; +import { store as preferencesStore } from '@wordpress/preferences'; + +const PREFERENCE_NAME = 'isResuableBlocksrRenameHintVisible'; + +export default function ReusableBlocksRenameHint() { + const isReusableBlocksRenameHint = useSelect( + ( select ) => + select( preferencesStore ).get( 'core', PREFERENCE_NAME ) ?? true, + [] + ); + + const ref = useRef(); + + const { set: setPreference } = useDispatch( preferencesStore ); + if ( ! isReusableBlocksRenameHint ) { + return null; + } + + return ( +
+
+ { __( 'Reusable blocks are now called "patterns".' ) } +
+
+ ); +} diff --git a/packages/block-editor/src/components/inserter/reusable-blocks-tab.js b/packages/block-editor/src/components/inserter/reusable-blocks-tab.js index ac30c7c7634e6e..b2edc32f84a0bf 100644 --- a/packages/block-editor/src/components/inserter/reusable-blocks-tab.js +++ b/packages/block-editor/src/components/inserter/reusable-blocks-tab.js @@ -13,6 +13,7 @@ import BlockTypesList from '../block-types-list'; import InserterPanel from './panel'; import InserterNoResults from './no-results'; import useBlockTypesState from './hooks/use-block-types-state'; +import ReusableBlocksRenameHint from './reusable-block-rename-hint'; function ReusableBlocksList( { onHover, onInsert, rootClientId } ) { const [ items, , , onSelectItem ] = useBlockTypesState( @@ -29,12 +30,12 @@ function ReusableBlocksList( { onHover, onInsert, rootClientId } ) { } return ( - + ); @@ -54,6 +55,7 @@ function ReusableBlocksList( { onHover, onInsert, rootClientId } ) { export function ReusableBlocksTab( { rootClientId, onInsert, onHover } ) { return ( <> + - { __( 'Manage Patterns/Reusable blocks' ) } + { __( 'Manage Patterns' ) } { __( 'Create pattern' ) } + { isModalOpen && ( - { __( 'Manage Patterns/Reusable blocks' ) } + { __( 'Manage Patterns' ) } { canRemove && ( convertBlockToStatic( clientId ) }>