From 347577787ba03c69a9606113d7e65a52ecbe1742 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 1 Jun 2023 12:46:59 +1200 Subject: [PATCH 01/68] Add the option to create a non-synced pattern by adding content to existing reusable block CPT --- packages/block-library/src/block/edit.js | 7 ++++ .../reusable-block-convert-button.js | 42 +++++++++++++++---- packages/reusable-blocks/src/store/actions.js | 17 +++++--- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/packages/block-library/src/block/edit.js b/packages/block-library/src/block/edit.js index fcba45450ea5e..25a485afc82cb 100644 --- a/packages/block-library/src/block/edit.js +++ b/packages/block-library/src/block/edit.js @@ -54,11 +54,18 @@ export default function ReusableBlockEdit( { attributes: { ref }, clientId } ) { const { __experimentalConvertBlockToStatic: convertBlockToStatic } = useDispatch( reusableBlocksStore ); + const { replaceBlocks } = useDispatch( blockEditorStore ); + const [ blocks, onInput, onChange ] = useEntityBlockEditor( 'postType', 'wp_block', { id: ref } ); + + if ( blocks?.length > 0 && blocks[ 0 ].name === 'core/pattern' ) { + replaceBlocks( clientId, blocks[ 0 ].innerBlocks ); + } + const [ title, setTitle ] = useEntityProp( 'postType', 'wp_block', 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 18824b892544a..a8b258564202c 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 @@ -17,7 +17,7 @@ import { } from '@wordpress/components'; import { symbol } from '@wordpress/icons'; import { useDispatch, useSelect } from '@wordpress/data'; -import { __ } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; import { store as coreStore } from '@wordpress/core-data'; @@ -39,6 +39,7 @@ export default function ReusableBlockConvertButton( { rootClientId, } ) { const [ isModalOpen, setIsModalOpen ] = useState( false ); + const [ blockType, setBlockType ] = useState( 'resuable' ); const [ title, setTitle ] = useState( '' ); const canConvert = useSelect( ( select ) => { @@ -88,17 +89,29 @@ export default function ReusableBlockConvertButton( { const onConvert = useCallback( async function ( reusableBlockTitle ) { try { - await convertBlocksToReusable( clientIds, reusableBlockTitle ); - createSuccessNotice( __( 'Reusable block created.' ), { - type: 'snackbar', - } ); + await convertBlocksToReusable( + clientIds, + reusableBlockTitle, + blockType + ); + createSuccessNotice( + sprintf( + __( '%s created.' ), + blockType === 'reusable' + ? __( 'Reusable block' ) + : __( 'Pattern' ) + ), + { + type: 'snackbar', + } + ); } catch ( error ) { createErrorNotice( error.message, { type: 'snackbar', } ); } }, - [ clientIds ] + [ clientIds, blockType ] ); if ( ! canConvert ) { @@ -112,14 +125,29 @@ export default function ReusableBlockConvertButton( { { + setBlockType( 'reusable' ); setIsModalOpen( true ); } } > { __( 'Create Reusable block' ) } + { + setBlockType( 'pattern' ); + setIsModalOpen( true ); + } } + > + { __( 'Create a Pattern' ) } + { isModalOpen && ( { setIsModalOpen( false ); setTitle( '' ); diff --git a/packages/reusable-blocks/src/store/actions.js b/packages/reusable-blocks/src/store/actions.js index b039c2e3883de..12435d62f9a53 100644 --- a/packages/reusable-blocks/src/store/actions.js +++ b/packages/reusable-blocks/src/store/actions.js @@ -44,17 +44,22 @@ export const __experimentalConvertBlockToStatic = * * @param {string[]} clientIds The client IDs of the block to detach. * @param {string} title Reusable block title. + * @param {string} blockType They type of block being created, reusable or pattern. */ export const __experimentalConvertBlocksToReusable = - ( clientIds, title ) => + ( clientIds, title, blockType ) => async ( { registry, dispatch } ) => { + let content = serialize( + registry.select( blockEditorStore ).getBlocksByClientId( clientIds ) + ); + + if ( blockType === 'pattern' ) { + content = `${ content }`; + } + const reusableBlock = { title: title || __( 'Untitled Reusable block' ), - content: serialize( - registry - .select( blockEditorStore ) - .getBlocksByClientId( clientIds ) - ), + content, status: 'publish', }; From 25c492ad3d08cd900f741f630b393d0e0820a82b Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 1 Jun 2023 16:27:08 +1200 Subject: [PATCH 02/68] Switch to using post meta to track sync status --- lib/compat/wordpress-6.3/blocks.php | 25 +++++++++++++++++++ packages/block-library/src/block/edit.js | 12 +++++++-- packages/reusable-blocks/src/store/actions.js | 16 +++++++----- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/lib/compat/wordpress-6.3/blocks.php b/lib/compat/wordpress-6.3/blocks.php index 5f017997f52b5..0b18111c0b483 100644 --- a/lib/compat/wordpress-6.3/blocks.php +++ b/lib/compat/wordpress-6.3/blocks.php @@ -26,3 +26,28 @@ function gutenberg_add_selectors_property_to_block_type_settings( $settings, $me return $settings; } add_filter( 'block_type_metadata_settings', 'gutenberg_add_selectors_property_to_block_type_settings', 10, 2 ); + +add_filter('register_post_type_args', 'gutenberg_add_custom_fields_to_wp_block', 10, 2); +function gutenberg_add_custom_fields_to_wp_block($args, $post_type){ + + if ($post_type == 'wp_block'){ + array_push( $args['supports'], 'custom-fields' ); + } + + return $args; +} + +add_action( 'init', 'gutenberg_wp_block_register_post_meta' ); + +function gutenberg_wp_block_register_post_meta() { + $post_type = 'wp_block'; + register_post_meta( $post_type, 'wp_block_sync_status', [ + 'auth_callback' => function() { + return current_user_can('edit_posts'); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ]); +} diff --git a/packages/block-library/src/block/edit.js b/packages/block-library/src/block/edit.js index 25a485afc82cb..500c5be0ee9d0 100644 --- a/packages/block-library/src/block/edit.js +++ b/packages/block-library/src/block/edit.js @@ -29,6 +29,7 @@ import { } from '@wordpress/block-editor'; import { store as reusableBlocksStore } from '@wordpress/reusable-blocks'; import { ungroup } from '@wordpress/icons'; +import { cloneBlock } from '@wordpress/blocks'; export default function ReusableBlockEdit( { attributes: { ref }, clientId } ) { const hasAlreadyRendered = useHasRecursion( ref ); @@ -62,8 +63,15 @@ export default function ReusableBlockEdit( { attributes: { ref }, clientId } ) { { id: ref } ); - if ( blocks?.length > 0 && blocks[ 0 ].name === 'core/pattern' ) { - replaceBlocks( clientId, blocks[ 0 ].innerBlocks ); + if ( + hasResolved && + record.meta?.wp_block_sync_status === 'notSynced' && + blocks?.length > 0 + ) { + replaceBlocks( + clientId, + blocks.map( ( block ) => cloneBlock( block ) ) + ); } const [ title, setTitle ] = useEntityProp( diff --git a/packages/reusable-blocks/src/store/actions.js b/packages/reusable-blocks/src/store/actions.js index 12435d62f9a53..a1cd7c402d575 100644 --- a/packages/reusable-blocks/src/store/actions.js +++ b/packages/reusable-blocks/src/store/actions.js @@ -49,18 +49,22 @@ export const __experimentalConvertBlockToStatic = export const __experimentalConvertBlocksToReusable = ( clientIds, title, blockType ) => async ( { registry, dispatch } ) => { - let content = serialize( - registry.select( blockEditorStore ).getBlocksByClientId( clientIds ) - ); - + let meta; if ( blockType === 'pattern' ) { - content = `${ content }`; + meta = { + wp_block_sync_status: 'notSynced', + }; } const reusableBlock = { title: title || __( 'Untitled Reusable block' ), - content, + content: serialize( + registry + .select( blockEditorStore ) + .getBlocksByClientId( clientIds ) + ), status: 'publish', + meta, }; const updatedRecord = await registry From 13142263426643e32ae1819a203b352b26a3e733 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 1 Jun 2023 16:34:03 +1200 Subject: [PATCH 03/68] Fix linting --- lib/compat/wordpress-6.3/blocks.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/compat/wordpress-6.3/blocks.php b/lib/compat/wordpress-6.3/blocks.php index 0b18111c0b483..3b2964e1abc61 100644 --- a/lib/compat/wordpress-6.3/blocks.php +++ b/lib/compat/wordpress-6.3/blocks.php @@ -27,10 +27,10 @@ function gutenberg_add_selectors_property_to_block_type_settings( $settings, $me } add_filter( 'block_type_metadata_settings', 'gutenberg_add_selectors_property_to_block_type_settings', 10, 2 ); -add_filter('register_post_type_args', 'gutenberg_add_custom_fields_to_wp_block', 10, 2); -function gutenberg_add_custom_fields_to_wp_block($args, $post_type){ +add_filter( 'register_post_type_args', 'gutenberg_add_custom_fields_to_wp_block', 10, 2 ); +function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ){ - if ($post_type == 'wp_block'){ + if ( $post_type === 'wp_block' ){ array_push( $args['supports'], 'custom-fields' ); } @@ -42,12 +42,12 @@ function gutenberg_add_custom_fields_to_wp_block($args, $post_type){ function gutenberg_wp_block_register_post_meta() { $post_type = 'wp_block'; register_post_meta( $post_type, 'wp_block_sync_status', [ - 'auth_callback' => function() { - return current_user_can('edit_posts'); + 'auth_callback' => function() { + return current_user_can( 'edit_posts' ); }, 'sanitize_callback' => 'sanitize_text_field', 'show_in_rest' => true, 'single' => true, 'type' => 'string', - ]); + ] ); } From 24db1a3574e8261131a4bfd16564ad0b22dbfe5f Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 1 Jun 2023 16:56:05 +1200 Subject: [PATCH 04/68] More linting fixes --- lib/compat/wordpress-6.3/blocks.php | 30 ++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/compat/wordpress-6.3/blocks.php b/lib/compat/wordpress-6.3/blocks.php index 3b2964e1abc61..e0e65ded080b0 100644 --- a/lib/compat/wordpress-6.3/blocks.php +++ b/lib/compat/wordpress-6.3/blocks.php @@ -27,18 +27,37 @@ function gutenberg_add_selectors_property_to_block_type_settings( $settings, $me } add_filter( 'block_type_metadata_settings', 'gutenberg_add_selectors_property_to_block_type_settings', 10, 2 ); -add_filter( 'register_post_type_args', 'gutenberg_add_custom_fields_to_wp_block', 10, 2 ); -function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ){ +/** + * Adds custom fields support to the wp_block post type so a partial and unsynced option can be added. + * + * Note: This should be removed when the minimum required WP version is >= 6.3. + * + * @see https://github.com/WordPress/gutenberg/pull/51144 + * + * @param array $args Register post type args. + * @param string $post_type The post type string. + * + * @return array Register post type args. + */ +function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ) { - if ( $post_type === 'wp_block' ){ + if ( 'wp_block' === $post_type ) { array_push( $args['supports'], 'custom-fields' ); } return $args; } +add_filter( 'register_post_type_args', 'gutenberg_add_custom_fields_to_wp_block', 10, 2 ); -add_action( 'init', 'gutenberg_wp_block_register_post_meta' ); - +/** + * Adds wp_block_sync_status meta field to the wp_block post type so a partial and unsynced option can be added. + * + * Note: This should be removed when the minimum required WP version is >= 6.3. + * + * @see https://github.com/WordPress/gutenberg/pull/51144 + * + * @return void + */ function gutenberg_wp_block_register_post_meta() { $post_type = 'wp_block'; register_post_meta( $post_type, 'wp_block_sync_status', [ @@ -51,3 +70,4 @@ function gutenberg_wp_block_register_post_meta() { 'type' => 'string', ] ); } +add_action( 'init', 'gutenberg_wp_block_register_post_meta' ); From 4d5f40f63bd0d443f169beaba930bcd136017a13 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 1 Jun 2023 17:07:57 +1200 Subject: [PATCH 05/68] Lint lint lint --- lib/compat/wordpress-6.3/blocks.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/compat/wordpress-6.3/blocks.php b/lib/compat/wordpress-6.3/blocks.php index e0e65ded080b0..14152f5bd343e 100644 --- a/lib/compat/wordpress-6.3/blocks.php +++ b/lib/compat/wordpress-6.3/blocks.php @@ -41,11 +41,11 @@ function gutenberg_add_selectors_property_to_block_type_settings( $settings, $me */ function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ) { - if ( 'wp_block' === $post_type ) { - array_push( $args['supports'], 'custom-fields' ); - } + if ( 'wp_block' === $post_type ) { + array_push( $args['supports'], 'custom-fields' ); + } - return $args; + return $args; } add_filter( 'register_post_type_args', 'gutenberg_add_custom_fields_to_wp_block', 10, 2 ); @@ -59,15 +59,15 @@ function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ) { * @return void */ function gutenberg_wp_block_register_post_meta() { - $post_type = 'wp_block'; - register_post_meta( $post_type, 'wp_block_sync_status', [ - 'auth_callback' => function() { - return current_user_can( 'edit_posts' ); - }, - 'sanitize_callback' => 'sanitize_text_field', - 'show_in_rest' => true, - 'single' => true, - 'type' => 'string', - ] ); + $post_type = 'wp_block'; + register_post_meta( $post_type, 'wp_block_sync_status', [ + 'auth_callback' => function() { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ] ); } add_action( 'init', 'gutenberg_wp_block_register_post_meta' ); From 1a6d5e9a3783c84e1751f35fb944e72106ae82ac Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 1 Jun 2023 17:28:29 +1200 Subject: [PATCH 06/68] Add categories --- lib/compat/wordpress-6.3/blocks.php | 11 +++++- .../reusable-block-convert-button.js | 38 ++++++++++++++++--- packages/reusable-blocks/src/store/actions.js | 10 +++-- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/lib/compat/wordpress-6.3/blocks.php b/lib/compat/wordpress-6.3/blocks.php index 14152f5bd343e..ad7badd073835 100644 --- a/lib/compat/wordpress-6.3/blocks.php +++ b/lib/compat/wordpress-6.3/blocks.php @@ -50,7 +50,7 @@ function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ) { add_filter( 'register_post_type_args', 'gutenberg_add_custom_fields_to_wp_block', 10, 2 ); /** - * Adds wp_block_sync_status meta field to the wp_block post type so a partial and unsynced option can be added. + * Adds wp_block_sync_status and wp_block_category_name meta fields to the wp_block post type so a partial and unsynced option can be added. * * Note: This should be removed when the minimum required WP version is >= 6.3. * @@ -69,5 +69,14 @@ function gutenberg_wp_block_register_post_meta() { 'single' => true, 'type' => 'string', ] ); + register_post_meta( $post_type, 'wp_block_category_name', [ + 'auth_callback' => function() { + return current_user_can( 'edit_posts' ); + }, + 'sanitize_callback' => 'sanitize_text_field', + 'show_in_rest' => true, + 'single' => true, + 'type' => 'string', + ] ); } add_action( 'init', 'gutenberg_wp_block_register_post_meta' ); 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 a8b258564202c..fdce4c28e95df 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 @@ -14,6 +14,7 @@ import { TextControl, __experimentalHStack as HStack, __experimentalVStack as VStack, + SelectControl, } from '@wordpress/components'; import { symbol } from '@wordpress/icons'; import { useDispatch, useSelect } from '@wordpress/data'; @@ -41,10 +42,11 @@ export default function ReusableBlockConvertButton( { const [ isModalOpen, setIsModalOpen ] = useState( false ); const [ blockType, setBlockType ] = useState( 'resuable' ); const [ title, setTitle ] = useState( '' ); - const canConvert = useSelect( + const [ categoryName, setCategoryName ] = useState( '' ); + const { canConvert, patternCategories } = useSelect( ( select ) => { const { canUser } = select( coreStore ); - const { getBlocksByClientId, canInsertBlockType } = + const { getBlocksByClientId, canInsertBlockType, getSettings } = select( blockEditorStore ); const blocks = getBlocksByClientId( clientIds ) ?? []; @@ -76,7 +78,11 @@ export default function ReusableBlockConvertButton( { // Hide when current doesn't have permission to do that. !! canUser( 'create', 'blocks' ); - return _canConvert; + return { + canConvert: _canConvert, + patternCategories: + getSettings().__experimentalBlockPatternCategories, + }; }, [ clientIds ] ); @@ -92,7 +98,8 @@ export default function ReusableBlockConvertButton( { await convertBlocksToReusable( clientIds, reusableBlockTitle, - blockType + blockType, + categoryName ); createSuccessNotice( sprintf( @@ -111,13 +118,25 @@ export default function ReusableBlockConvertButton( { } ); } }, - [ clientIds, blockType ] + [ + convertBlocksToReusable, + clientIds, + blockType, + categoryName, + createSuccessNotice, + createErrorNotice, + ] ); if ( ! canConvert ) { return null; } + const categoryOptions = patternCategories.map( ( category ) => ( { + label: category.label, + value: category.name, + } ) ); + return ( { ( { onClose } ) => ( @@ -170,6 +189,15 @@ export default function ReusableBlockConvertButton( { value={ title } onChange={ setTitle } /> + { blockType === 'pattern' && ( + + ) } diff --git a/packages/block-editor/src/components/inserter/tabs.js b/packages/block-editor/src/components/inserter/tabs.js index 6f8377892059b..844a6a87110af 100644 --- a/packages/block-editor/src/components/inserter/tabs.js +++ b/packages/block-editor/src/components/inserter/tabs.js @@ -14,12 +14,12 @@ const blocksTab = { const patternsTab = { name: 'patterns', /* translators: Patterns tab title in the block inserter. */ - title: __( 'Patterns' ), + title: __( 'Imported Patterns' ), }; const reusableBlocksTab = { name: 'reusable', /* translators: Reusable blocks tab title in the block inserter. */ - title: __( 'Reusable' ), + title: __( 'Local Patterns' ), icon: reusableBlockIcon, }; const mediaTab = { @@ -45,12 +45,12 @@ function InserterTabs( { if ( ! prioritizePatterns && showPatterns ) { tempTabs.push( patternsTab ); } - if ( showMedia ) { - tempTabs.push( mediaTab ); - } if ( showReusableBlocks ) { tempTabs.push( reusableBlocksTab ); } + if ( showMedia ) { + tempTabs.push( mediaTab ); + } return tempTabs; }, [ prioritizePatterns, showPatterns, showReusableBlocks, showMedia ] ); diff --git a/packages/block-library/src/block/edit.js b/packages/block-library/src/block/edit.js index 94586f6d60894..a35f0c1414984 100644 --- a/packages/block-library/src/block/edit.js +++ b/packages/block-library/src/block/edit.js @@ -65,7 +65,7 @@ export default function ReusableBlockEdit( { attributes: { ref }, clientId } ) { if ( hasResolved && - record?.meta?.wp_block?.sync_status === 'notSynced' && + record?.meta?.wp_block?.sync_status === 'unsynced' && blocks?.length > 0 ) { replaceBlocks( 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 cb1e8716cc3a2..28a674abbc0b0 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 @@ -15,6 +15,7 @@ import { __experimentalHStack as HStack, __experimentalVStack as VStack, SelectControl, + ToggleControl, } from '@wordpress/components'; import { symbol } from '@wordpress/icons'; import { useDispatch, useSelect } from '@wordpress/data'; @@ -48,7 +49,7 @@ export default function ReusableBlockConvertButton( { ); const [ isModalOpen, setIsModalOpen ] = useState( false ); - const [ blockType, setBlockType ] = useState( 'reusable' ); + const [ syncType, setSyncType ] = useState( 'fully' ); const [ title, setTitle ] = useState( '' ); const [ categoryId, setCategoryId ] = useState( '' ); const { canConvert } = useSelect( @@ -105,16 +106,16 @@ export default function ReusableBlockConvertButton( { await convertBlocksToReusable( clientIds, reusableBlockTitle, - blockType, + syncType, categoryId ); createSuccessNotice( sprintf( // translators: %s: Type of block (i.e. Reusable or Pattern). __( '%s created.' ), - blockType === 'reusable' - ? __( 'Reusable block' ) - : __( 'Pattern' ) + syncType === 'synced' + ? __( 'Synced Pattern' ) + : __( 'Unsynced Pattern' ) ), { type: 'snackbar', @@ -129,7 +130,7 @@ export default function ReusableBlockConvertButton( { [ convertBlocksToReusable, clientIds, - blockType, + syncType, categoryId, createSuccessNotice, createErrorNotice, @@ -156,16 +157,6 @@ export default function ReusableBlockConvertButton( { { - setBlockType( 'reusable' ); - setIsModalOpen( true ); - } } - > - { __( 'Create Reusable block' ) } - - { - setBlockType( 'pattern' ); setIsModalOpen( true ); } } > @@ -173,13 +164,7 @@ export default function ReusableBlockConvertButton( { { isModalOpen && ( { setIsModalOpen( false ); setTitle( '' ); @@ -202,15 +187,30 @@ export default function ReusableBlockConvertButton( { value={ title } onChange={ setTitle } /> - { blockType === 'pattern' && ( - - ) } + + + { + setSyncType( + syncType === 'fully' + ? 'unsynced' + : 'fully' + ); + } } + /> diff --git a/packages/block-editor/src/components/inserter/tabs.js b/packages/block-editor/src/components/inserter/tabs.js index 8946304918846..f11ce9d31ab5d 100644 --- a/packages/block-editor/src/components/inserter/tabs.js +++ b/packages/block-editor/src/components/inserter/tabs.js @@ -19,7 +19,7 @@ const patternsTab = { const reusableBlocksTab = { name: 'reusable', /* translators: Locally created Patterns tab title in the block inserter. */ - title: __( 'Local Patterns' ), + title: __( 'Synced Patterns' ), icon: reusableBlockIcon, }; const mediaTab = { From 2d575ee1d48fbe19f5fc5514170fb6fe23dae54d Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 16 Jun 2023 09:52:49 +1200 Subject: [PATCH 46/68] Remove the patterns taxonomy for now --- lib/compat/wordpress-6.3/block-patterns.php | 152 ------------------ lib/compat/wordpress-6.3/blocks.php | 5 +- lib/load.php | 1 - .../index.js | 2 +- .../reusable-block-convert-button.js | 40 +---- packages/reusable-blocks/src/store/actions.js | 11 +- 6 files changed, 12 insertions(+), 199 deletions(-) delete mode 100644 lib/compat/wordpress-6.3/block-patterns.php diff --git a/lib/compat/wordpress-6.3/block-patterns.php b/lib/compat/wordpress-6.3/block-patterns.php deleted file mode 100644 index c0bb2f2822fc8..0000000000000 --- a/lib/compat/wordpress-6.3/block-patterns.php +++ /dev/null @@ -1,152 +0,0 @@ -= 6.3. - * - * @see https://github.com/WordPress/gutenberg/pull/51144 - * - * @return void - */ -function gutenberg_register_taxonomy_patterns() { - $labels = array( - 'name' => _x( 'Pattern Categories', 'taxonomy general name' ), - 'singular_name' => _x( 'Pattern Category', 'taxonomy singular name' ), - ); - $args = array( - 'hierarchical' => false, - 'labels' => $labels, - 'show_ui' => true, - 'show_in_menu' => false, - 'show_in_nav_menus' => false, - 'show_admin_column' => true, - 'query_var' => true, - 'show_in_rest' => true, - 'rewrite' => array( 'slug' => 'wp_pattern' ), - ); - register_taxonomy( 'wp_pattern', array( 'wp_block' ), $args ); -} -add_action( 'init', 'gutenberg_register_taxonomy_patterns' ); - -/** - * Add categories to new wp_patterns taxonomy for WP 6.3. - * - * @package gutenberg - */ -function gutenberg_register_wp_patterns_taxonomy_categories() { - $categories = array( - array( - 'slug' => 'banner', - 'label' => _x( 'Banners', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Patterns used for adding banners', 'gutenberg' ), - ), - array( - 'slug' => 'buttons', - 'label' => _x( 'Buttons', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Patterns that contain buttons and call to actions.', 'gutenberg' ), - ), - array( - 'slug' => 'columns', - 'label' => _x( 'Columns', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Multi-column patterns with more complex layouts.', 'gutenberg' ), - ), - array( - 'slug' => 'text', - 'label' => _x( 'Text', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Patterns containing mostly text.', 'gutenberg' ), - ), - array( - 'slug' => 'query', - 'label' => _x( 'Post list', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Display your latest posts in lists, grids or other layouts.', 'gutenberg' ), - ), - array( - 'slug' => 'featured', - 'label' => _x( 'Featured', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'A set of high quality curated patterns.', 'gutenberg' ), - ), - - // Register new core block pattern categories. - array( - 'slug' => 'call-to-action', - 'label' => _x( 'Call to Action', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Sections whose purpose is to trigger a specific action.', 'gutenberg' ), - ), - array( - 'slug' => 'team', - 'label' => _x( 'Team', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'A variety of designs to display your team members.', 'gutenberg' ), - ), - array( - 'slug' => 'testimonials', - 'label' => _x( 'Testimonials', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Share reviews and feedback about your brand/business.', 'gutenberg' ), - ), - array( - 'slug' => 'services', - 'label' => _x( 'Services', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Briefly describe what your business does and how you can help.', 'gutenberg' ), - ), - array( - 'slug' => 'contact', - 'label' => _x( 'Contact', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Display your contact information.', 'gutenberg' ), - ), - array( - 'slug' => 'about', - 'label' => _x( 'About', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Introduce yourself.', 'gutenberg' ), - ), - array( - 'slug' => 'portfolio', - 'label' => _x( 'Portfolio', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Showcase your latest work.', 'gutenberg' ), - ), - array( - 'slug' => 'gallery', - 'label' => _x( 'Gallery', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Different layouts for displaying images.', 'gutenberg' ), - ), - array( - 'slug' => 'media', - 'label' => _x( 'Media', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Different layouts containing video or audio.', 'gutenberg' ), - ), - array( - 'slug' => 'posts', - 'label' => _x( 'Posts', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'Display your latest posts in lists, grids or other layouts.', 'gutenberg' ), - ), - // Site building pattern categories. - array( - 'slug' => 'footer', - 'label' => _x( 'Footers', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'A variety of footer designs displaying information and site navigation.', 'gutenberg' ), - ), - array( - 'slug' => 'header', - 'label' => _x( 'Headers', 'Block pattern category', 'gutenberg' ), - 'description' => __( 'A variety of header designs displaying your site title and navigation.', 'gutenberg' ), - ), - ); - - foreach ( $categories as $category ) { - if ( empty( term_exists( $category['slug'], 'wp_pattern' ) ) ) { - wp_insert_term( - $category['label'], - 'wp_pattern', - array( - 'slug' => $category['slug'], - 'description' => $category['description'], - ) - ); - } - } -} -add_action( 'init', 'gutenberg_register_wp_patterns_taxonomy_categories', 20 ); diff --git a/lib/compat/wordpress-6.3/blocks.php b/lib/compat/wordpress-6.3/blocks.php index bc8e4b7392d2d..3171f125c64fd 100644 --- a/lib/compat/wordpress-6.3/blocks.php +++ b/lib/compat/wordpress-6.3/blocks.php @@ -28,7 +28,8 @@ function gutenberg_add_selectors_property_to_block_type_settings( $settings, $me add_filter( 'block_type_metadata_settings', 'gutenberg_add_selectors_property_to_block_type_settings', 10, 2 ); /** - * Adds custom fields support to the wp_block post type so a partial and unsynced option can be added. + * Adds custom fields support to the wp_block post type so an unsynced option can be added and renames + * from Reusable block to Pattern. * * Note: This should be removed when the minimum required WP version is >= 6.3. * @@ -67,7 +68,7 @@ function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ) { add_filter( 'register_post_type_args', 'gutenberg_add_custom_fields_to_wp_block', 10, 2 ); /** - * Adds wp_block_sync_status and wp_block_category_name meta fields to the wp_block post type so a partial and unsynced option can be added. + * Adds wp_block_sync_status meta fields to the wp_block post type so an unsynced option can be added. * * Note: This should be removed when the minimum required WP version is >= 6.3. * diff --git a/lib/load.php b/lib/load.php index c9f221d4d5ced..ceecaf7f89478 100644 --- a/lib/load.php +++ b/lib/load.php @@ -53,7 +53,6 @@ function gutenberg_is_experiment_enabled( $name ) { require_once __DIR__ . '/compat/wordpress-6.3/navigation-block-preloading.php'; require_once __DIR__ . '/compat/wordpress-6.3/link-template.php'; require_once __DIR__ . '/compat/wordpress-6.3/behaviors.php'; - require_once __DIR__ . '/compat/wordpress-6.3/block-patterns.php'; // Experimental. if ( ! class_exists( 'WP_Rest_Customizer_Nonces' ) ) { diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-templates/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-templates/index.js index 2efe5c423e0c9..54c2dab7fa59c 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-templates/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-templates/index.js @@ -41,7 +41,7 @@ const config = { loading: __( 'Loading library' ), notFound: __( 'No patterns found' ), manage: __( 'Manage all template parts' ), - reusableBlocks: __( 'Manage Patterns' ), + reusableBlocks: __( 'Manage patterns' ), description: __( 'Template Parts are small pieces of a layout that can be reused across multiple templates and always appear the same way. Common template parts include the site header, footer, or sidebar.' ), 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 8a06fcbfb76ab..a723d784d89b6 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 @@ -14,14 +14,13 @@ import { TextControl, __experimentalHStack as HStack, __experimentalVStack as VStack, - SelectControl, ToggleControl, } from '@wordpress/components'; import { symbol } from '@wordpress/icons'; import { useDispatch, useSelect } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; -import { store as coreStore, useEntityRecords } from '@wordpress/core-data'; +import { store as coreStore } from '@wordpress/core-data'; /** * Internal dependencies @@ -40,16 +39,7 @@ export default function ReusableBlockConvertButton( { clientIds, rootClientId, } ) { - const query = { per_page: -1, hide_empty: false, context: 'view' }; - - const { records: categories } = useEntityRecords( - 'taxonomy', - 'wp_pattern', - query - ); - const [ syncType, setSyncType ] = useState( 'unsynced' ); - const [ categoryId, setCategoryId ] = useState( '' ); const [ isModalOpen, setIsModalOpen ] = useState( false ); const [ title, setTitle ] = useState( '' ); const canConvert = useSelect( @@ -89,7 +79,7 @@ export default function ReusableBlockConvertButton( { return _canConvert; }, - [ clientIds ] + [ clientIds, rootClientId ] ); const { __experimentalConvertBlocksToReusable: convertBlocksToReusable } = @@ -103,8 +93,7 @@ export default function ReusableBlockConvertButton( { await convertBlocksToReusable( clientIds, reusableBlockTitle, - syncType, - categoryId + syncType ); createSuccessNotice( sprintf( @@ -128,7 +117,6 @@ export default function ReusableBlockConvertButton( { convertBlocksToReusable, clientIds, syncType, - categoryId, createSuccessNotice, createErrorNotice, ] @@ -137,16 +125,6 @@ export default function ReusableBlockConvertButton( { if ( ! canConvert ) { return null; } - const patternCategories = categories === null ? [] : categories; - const categoryOptions = patternCategories - .filter( ( category ) => category.slug !== 'query' ) - .map( ( category ) => ( { - label: category.name, - value: category.id, - } ) ) - .concat( [ - { value: '', label: __( 'Select a category' ), disabled: true }, - ] ); return ( @@ -154,10 +132,7 @@ export default function ReusableBlockConvertButton( { <> { - setCategoryId( '' ); - setIsModalOpen( true ); - } } + onClick={ () => setIsModalOpen( true ) } > { __( 'Create a Pattern' ) } @@ -186,13 +161,6 @@ export default function ReusableBlockConvertButton( { value={ title } onChange={ setTitle } /> - + ( clientIds, title, syncType ) => async ( { registry, dispatch } ) => { const meta = syncType === 'unsynced' @@ -58,7 +57,6 @@ export const __experimentalConvertBlocksToReusable = }, } : undefined; - const categories = categoryId ? [ categoryId ] : undefined; const reusableBlock = { title: title || __( 'Untitled Pattern block' ), @@ -69,7 +67,6 @@ export const __experimentalConvertBlocksToReusable = ), status: 'publish', meta, - wp_pattern: categories, }; const updatedRecord = await registry From a197050ca8fd58bcdcdfcf8f89240f35018b93e4 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 16 Jun 2023 10:47:40 +1200 Subject: [PATCH 47/68] Fix e2e tests --- packages/e2e-test-utils/src/create-reusable-block.js | 7 ++++++- .../editor/various/block-editor-keyboard-shortcuts.test.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/e2e-test-utils/src/create-reusable-block.js b/packages/e2e-test-utils/src/create-reusable-block.js index ec35e07390847..ce2ecfdaa8116 100644 --- a/packages/e2e-test-utils/src/create-reusable-block.js +++ b/packages/e2e-test-utils/src/create-reusable-block.js @@ -15,17 +15,22 @@ import { canvas } from './canvas'; export const createReusableBlock = async ( content, title ) => { const reusableBlockNameInputSelector = '.reusable-blocks-menu-items__convert-modal .components-text-control__input'; + const syncToggleSelector = '.components-form-toggle__input'; // Insert a paragraph block await insertBlock( 'Paragraph' ); await page.keyboard.type( content ); await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create Reusable block' ); + await clickMenuItem( 'Create Pattern' ); const nameInput = await page.waitForSelector( reusableBlockNameInputSelector ); await nameInput.click(); await page.keyboard.type( title ); + const syncToggle = await page.waitForSelector( + `${ reusableBlockNameInputSelector } ${ syncToggleSelector }` + ); + syncToggle.click(); await page.keyboard.press( 'Enter' ); // Wait for creation to finish diff --git a/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js b/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js index f1e6be7b816ab..9bacdc8f32cf1 100644 --- a/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js +++ b/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js @@ -90,7 +90,7 @@ describe( 'block editor keyboard shortcuts', () => { } ); it( 'should prevent deleting multiple selected blocks from inputs', async () => { await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create Reusable block' ); + await clickMenuItem( 'Create Pattern' ); const reusableBlockNameInputSelector = '.reusable-blocks-menu-items__convert-modal .components-text-control__input'; const nameInput = await page.waitForSelector( From 764e82a5531d5461ef447e38e02851a7bf6cd47b Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 16 Jun 2023 10:55:38 +1200 Subject: [PATCH 48/68] Remove whitespace --- lib/compat/wordpress-6.3/blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.3/blocks.php b/lib/compat/wordpress-6.3/blocks.php index 3171f125c64fd..0e123d3e82c83 100644 --- a/lib/compat/wordpress-6.3/blocks.php +++ b/lib/compat/wordpress-6.3/blocks.php @@ -28,7 +28,7 @@ function gutenberg_add_selectors_property_to_block_type_settings( $settings, $me add_filter( 'block_type_metadata_settings', 'gutenberg_add_selectors_property_to_block_type_settings', 10, 2 ); /** - * Adds custom fields support to the wp_block post type so an unsynced option can be added and renames + * Adds custom fields support to the wp_block post type so an unsynced option can be added and renames * from Reusable block to Pattern. * * Note: This should be removed when the minimum required WP version is >= 6.3. From 370ef366b91aec46b1463966ba533ca57b41f546 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 16 Jun 2023 11:32:16 +1200 Subject: [PATCH 49/68] Fix native tests --- packages/block-library/src/block/test/edit.native.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/block/test/edit.native.js b/packages/block-library/src/block/test/edit.native.js index 4652f8ba20f38..ae9d3d7c03e3e 100644 --- a/packages/block-library/src/block/test/edit.native.js +++ b/packages/block-library/src/block/test/edit.native.js @@ -114,7 +114,7 @@ describe( 'Reusable block', () => { // Get the reusable block. const [ reusableBlock ] = await screen.findAllByLabelText( - /Reusable block Block\. Row 1/ + /Pattern Block\. Row 1/ ); expect( reusableBlock ).toBeDefined(); @@ -131,7 +131,7 @@ describe( 'Reusable block', () => { } ); const [ reusableBlock ] = await screen.findAllByLabelText( - /Reusable block Block\. Row 1/ + /Pattern Block\. Row 1/ ); const blockDeleted = within( reusableBlock ).getByText( @@ -164,7 +164,7 @@ describe( 'Reusable block', () => { } ); const [ reusableBlock ] = await screen.findByLabelText( - /Reusable block Block\. Row 1/ + /Pattern Block\. Row 1/ ); const innerBlockListWrapper = await within( From 3311e3bd30bec02c34540921531e9c355c45159d Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 16 Jun 2023 12:29:51 +1200 Subject: [PATCH 50/68] Another mobile tests fix --- packages/block-library/src/block/test/transforms.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/block/test/transforms.native.js b/packages/block-library/src/block/test/transforms.native.js index 9771b40743a42..95104ac613399 100644 --- a/packages/block-library/src/block/test/transforms.native.js +++ b/packages/block-library/src/block/test/transforms.native.js @@ -9,7 +9,7 @@ import { getBlockTransformOptions, } from 'test/helpers'; -const block = 'Reusable block'; +const block = 'Pattern'; const initialHtml = ` `; From 120091d53335a0d4366259bc2d5a27de05e6a6ec Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 16 Jun 2023 12:49:12 +1200 Subject: [PATCH 51/68] another test fix --- .../src/block/test/__snapshots__/transforms.native.js.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/block/test/__snapshots__/transforms.native.js.snap b/packages/block-library/src/block/test/__snapshots__/transforms.native.js.snap index 7489c0b04954a..3c4d791eb9f75 100644 --- a/packages/block-library/src/block/test/__snapshots__/transforms.native.js.snap +++ b/packages/block-library/src/block/test/__snapshots__/transforms.native.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Reusable block block transforms to Columns block 1`] = ` +exports[`Pattern block transforms to Columns block 1`] = ` "
@@ -8,7 +8,7 @@ exports[`Reusable block block transforms to Columns block 1`] = ` " `; -exports[`Reusable block block transforms to Group block 1`] = ` +exports[`Pattern block transforms to Group block 1`] = ` "
" From 7ea3f60dcfe3ae48cc2585562f62c0f7e62b7eab Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 16 Jun 2023 13:26:29 +1200 Subject: [PATCH 52/68] another test fix --- packages/e2e-test-utils/src/create-reusable-block.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/e2e-test-utils/src/create-reusable-block.js b/packages/e2e-test-utils/src/create-reusable-block.js index ce2ecfdaa8116..651e5b639e689 100644 --- a/packages/e2e-test-utils/src/create-reusable-block.js +++ b/packages/e2e-test-utils/src/create-reusable-block.js @@ -21,7 +21,7 @@ export const createReusableBlock = async ( content, title ) => { await page.keyboard.type( content ); await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create Pattern' ); + await clickMenuItem( 'Create a Pattern' ); const nameInput = await page.waitForSelector( reusableBlockNameInputSelector ); From 6e3ac593308695e4bba1c30b20a5007430a5c624 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 16 Jun 2023 14:00:04 +1200 Subject: [PATCH 53/68] And another! --- .../editor/various/block-editor-keyboard-shortcuts.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js b/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js index 9bacdc8f32cf1..97248c472e4ac 100644 --- a/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js +++ b/packages/e2e-tests/specs/editor/various/block-editor-keyboard-shortcuts.test.js @@ -90,7 +90,7 @@ describe( 'block editor keyboard shortcuts', () => { } ); it( 'should prevent deleting multiple selected blocks from inputs', async () => { await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create Pattern' ); + await clickMenuItem( 'Create a Pattern' ); const reusableBlockNameInputSelector = '.reusable-blocks-menu-items__convert-modal .components-text-control__input'; const nameInput = await page.waitForSelector( From c21b9d059683fc1568a86f0a9dd9084f57f3598e Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 16 Jun 2023 15:27:24 +1200 Subject: [PATCH 54/68] simplify the sync_status postmeta --- lib/compat/wordpress-6.3/blocks.php | 17 ++++++++--------- packages/block-library/src/block/edit.js | 2 +- packages/reusable-blocks/src/store/actions.js | 4 +--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/compat/wordpress-6.3/blocks.php b/lib/compat/wordpress-6.3/blocks.php index 0e123d3e82c83..470175ffd86f8 100644 --- a/lib/compat/wordpress-6.3/blocks.php +++ b/lib/compat/wordpress-6.3/blocks.php @@ -68,7 +68,7 @@ function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ) { add_filter( 'register_post_type_args', 'gutenberg_add_custom_fields_to_wp_block', 10, 2 ); /** - * Adds wp_block_sync_status meta fields to the wp_block post type so an unsynced option can be added. + * Adds sync_status meta fields to the wp_block post type so an unsynced option can be added. * * Note: This should be removed when the minimum required WP version is >= 6.3. * @@ -80,17 +80,17 @@ function gutenberg_wp_block_register_post_meta() { $post_type = 'wp_block'; register_post_meta( $post_type, - 'wp_block', + 'sync_status', array( 'auth_callback' => function() { return current_user_can( 'edit_posts' ); }, 'sanitize_callback' => 'gutenberg_wp_block_sanitize_post_meta', 'single' => true, - 'type' => 'object', + 'type' => 'string', 'show_in_rest' => array( 'schema' => array( - 'type' => 'object', + 'type' => 'string', 'properties' => array( 'sync_status' => array( 'type' => 'string', @@ -102,18 +102,17 @@ function gutenberg_wp_block_register_post_meta() { ); } /** - * Sanitizes the array of wp_block post meta categories array. + * Sanitizes the array of wp_block post meta sync_status string. * * Note: This should be removed when the minimum required WP version is >= 6.3. * * @see https://github.com/WordPress/gutenberg/pull/51144 * - * @param array $meta_value Array of values to sanitize. + * @param array $meta_value String to sanitize. * - * @return array Sanitized array of values. + * @return array Sanitized string. */ function gutenberg_wp_block_sanitize_post_meta( $meta_value ) { - $meta_value['sync_status'] = sanitize_text_field( $meta_value['sync_status'] ); - return $meta_value; + return sanitize_text_field( $meta_value ); } add_action( 'init', 'gutenberg_wp_block_register_post_meta' ); diff --git a/packages/block-library/src/block/edit.js b/packages/block-library/src/block/edit.js index 7fc2faf048472..093d9e5f6c597 100644 --- a/packages/block-library/src/block/edit.js +++ b/packages/block-library/src/block/edit.js @@ -65,7 +65,7 @@ export default function ReusableBlockEdit( { attributes: { ref }, clientId } ) { if ( hasResolved && - record?.meta?.wp_block?.sync_status === 'unsynced' && + record?.meta?.sync_status === 'unsynced' && blocks.length > 0 ) { replaceBlocks( diff --git a/packages/reusable-blocks/src/store/actions.js b/packages/reusable-blocks/src/store/actions.js index 578d636deef30..aae706adfab36 100644 --- a/packages/reusable-blocks/src/store/actions.js +++ b/packages/reusable-blocks/src/store/actions.js @@ -52,9 +52,7 @@ export const __experimentalConvertBlocksToReusable = const meta = syncType === 'unsynced' ? { - wp_block: { - sync_status: syncType, - }, + sync_status: syncType, } : undefined; From 542272a7d3e15b97c548aed8798c3b2c17701dca Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 16 Jun 2023 16:45:58 +1200 Subject: [PATCH 55/68] Fingers crossed the last e2e test fix for the week --- .../e2e-test-utils/src/create-reusable-block.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/e2e-test-utils/src/create-reusable-block.js b/packages/e2e-test-utils/src/create-reusable-block.js index 651e5b639e689..266e0525d34bd 100644 --- a/packages/e2e-test-utils/src/create-reusable-block.js +++ b/packages/e2e-test-utils/src/create-reusable-block.js @@ -15,7 +15,10 @@ import { canvas } from './canvas'; export const createReusableBlock = async ( content, title ) => { const reusableBlockNameInputSelector = '.reusable-blocks-menu-items__convert-modal .components-text-control__input'; - const syncToggleSelector = '.components-form-toggle__input'; + const syncToggleSelector = + '.reusable-blocks-menu-items__convert-modal .components-form-toggle__input'; + const syncToggleSelectorChecked = + '.reusable-blocks-menu-items__convert-modal .components-form-toggle.is-checked'; // Insert a paragraph block await insertBlock( 'Paragraph' ); await page.keyboard.type( content ); @@ -27,15 +30,15 @@ export const createReusableBlock = async ( content, title ) => { ); await nameInput.click(); await page.keyboard.type( title ); - const syncToggle = await page.waitForSelector( - `${ reusableBlockNameInputSelector } ${ syncToggleSelector }` - ); + + const syncToggle = await page.waitForSelector( syncToggleSelector ); syncToggle.click(); + await page.waitForSelector( syncToggleSelectorChecked ); await page.keyboard.press( 'Enter' ); // Wait for creation to finish await page.waitForXPath( - '//*[contains(@class, "components-snackbar")]/*[text()="Reusable block created."]' + '//*[contains(@class, "components-snackbar")]/*[text()="Synced Pattern created."]' ); // Check that we have a reusable block on the page From e0e8882ba0ac6a5ca6fcf1c8f5d9c655c1c41261 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Fri, 16 Jun 2023 17:23:30 +1200 Subject: [PATCH 56/68] Remove unsynced patterns from synced patterns inserter tab --- .../src/components/inserter/reusable-blocks-tab.js | 5 ++++- packages/block-editor/src/store/selectors.js | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) 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 0de66c83a2cb6..b091499d018bd 100644 --- a/packages/block-editor/src/components/inserter/reusable-blocks-tab.js +++ b/packages/block-editor/src/components/inserter/reusable-blocks-tab.js @@ -21,7 +21,10 @@ function ReusableBlocksList( { onHover, onInsert, rootClientId } ) { ); const filteredItems = useMemo( () => { - return items.filter( ( { category } ) => category === 'reusable' ); + return items.filter( + ( { category, syncStatus } ) => + category === 'reusable' && syncStatus !== 'unsynced' + ); }, [ items ] ); if ( filteredItems.length === 0 ) { diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 1616a2fde8b1b..7f44f140b3dd7 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -2026,6 +2026,7 @@ export const getInserterItems = createSelector( isDisabled: false, utility: 1, // Deprecated. frecency, + syncStatus: reusableBlock.meta.sync_status, }; }; From e96852c3a500e9653e180d0e7d34140918660947 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 19 Jun 2023 10:52:31 +1200 Subject: [PATCH 57/68] More e2e test fixes --- packages/e2e-test-utils/src/inserter.js | 16 ++++++++-------- .../specs/editor/various/reusable-blocks.test.js | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/e2e-test-utils/src/inserter.js b/packages/e2e-test-utils/src/inserter.js index 58f6d01a66514..075e74ee623af 100644 --- a/packages/e2e-test-utils/src/inserter.js +++ b/packages/e2e-test-utils/src/inserter.js @@ -106,8 +106,8 @@ export async function selectGlobalInserterTab( label ) { case 'Media': labelSelector = `. = "${ label }"`; break; - case 'Reusable': - // Reusable tab label is an icon, hence the different selector. + case 'Synced Patterns': + // Synced Patterns tab label is an icon, hence the different selector. labelSelector = `@aria-label = "${ label }"`; break; } @@ -180,7 +180,7 @@ export async function searchGlobalInserter( category, searchTerm ) { switch ( category ) { case 'Blocks': case 'Patterns': - case 'Reusable': { + case 'Synced Patterns': { waitForInsertElement = async () => { return await page.waitForXPath( `//*[@role='option' and contains(., '${ searchTerm }')]` @@ -220,7 +220,7 @@ export async function searchGlobalInserter( category, searchTerm ) { * If the entity is not instantly available in the open inserter, a search will * be performed. If the search returns no results, an error will be thrown. * - * Available categories: Blocks, Patterns, Reusable and Block Directory. + * Available categories: Blocks, Patterns, Synced Patterns and Block Directory. * * @param {string} category The category to insert from. * @param {string} searchTerm The term by which to find the entity to insert. @@ -231,8 +231,8 @@ export async function insertFromGlobalInserter( category, searchTerm ) { let insertButton; - if ( [ 'Blocks', 'Reusable' ].includes( category ) ) { - // If it's a block, see it it's insertable without searching... + if ( [ 'Blocks', 'Synced Patterns' ].includes( category ) ) { + // If it's a block, see if it's insertable without searching... try { insertButton = ( await page.$x( @@ -260,7 +260,7 @@ export async function insertFromGlobalInserter( category, searchTerm ) { await insertButton.click(); // Extra wait for the reusable block to be ready. - if ( category === 'Reusable' ) { + if ( category === 'Synced Patterns' ) { await canvas().waitForSelector( '.block-library-block__reusable-block-container' ); @@ -347,7 +347,7 @@ export async function insertPattern( searchTerm ) { * insert. */ export async function insertReusableBlock( searchTerm ) { - await insertFromGlobalInserter( 'Reusable', searchTerm ); + await insertFromGlobalInserter( 'Synced Patterns', searchTerm ); } /** diff --git a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js index 3215e4185c08f..97bfe31a9077f 100644 --- a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js @@ -193,7 +193,7 @@ describe( 'Reusable blocks', () => { // Convert block to a reusable block. await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create Reusable block' ); + await clickMenuItem( 'Create a Pattern' ); // Set title. const nameInput = await page.waitForSelector( @@ -205,7 +205,7 @@ describe( 'Reusable blocks', () => { // Wait for creation to finish. await page.waitForXPath( - '//*[contains(@class, "components-snackbar")]/*[text()="Reusable block created."]' + '//*[contains(@class, "components-snackbar")]/*[text()="Synced Pattern created."]' ); await clearAllBlocks(); @@ -259,7 +259,7 @@ describe( 'Reusable blocks', () => { // Save the reusable block. await page.click( publishButtonSelector ); await page.waitForXPath( - '//*[contains(@class, "components-snackbar")]/*[text()="Reusable block updated."]' + '//*[contains(@class, "components-snackbar")]/*[text()="Site updated."]' ); await createNewPost(); @@ -340,7 +340,7 @@ describe( 'Reusable blocks', () => { await canvas().click( 'p[aria-label="Paragraph block"]' ); await page.keyboard.type( '2' ); const selector = - '//div[@aria-label="Block: Reusable block"]//p[@aria-label="Paragraph block"][.="12"]'; + '//div[@aria-label="Block: Pattern"]//p[@aria-label="Paragraph block"][.="12"]'; const reusableBlockWithParagraph = await page.$x( selector ); expect( reusableBlockWithParagraph ).toBeTruthy(); @@ -376,7 +376,7 @@ describe( 'Reusable blocks', () => { // Convert to reusable. await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Create Reusable block' ); + await clickMenuItem( 'Create a Pattern' ); const nameInput = await page.waitForSelector( reusableBlockNameInputSelector ); @@ -384,7 +384,7 @@ describe( 'Reusable blocks', () => { await page.keyboard.type( 'Block with styles' ); await page.keyboard.press( 'Enter' ); const reusableBlock = await canvas().waitForSelector( - '.block-editor-block-list__block[aria-label="Block: Reusable block"]' + '.block-editor-block-list__block[aria-label="Block: Pattern"]' ); expect( reusableBlock ).toBeTruthy(); } ); From 302f5f9eaf1bba382a7207bd458305d403faeabb Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 19 Jun 2023 11:20:15 +1200 Subject: [PATCH 58/68] Unit test fix --- packages/block-editor/src/store/selectors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 7f44f140b3dd7..4b5ffbbb45f7a 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -2026,7 +2026,7 @@ export const getInserterItems = createSelector( isDisabled: false, utility: 1, // Deprecated. frecency, - syncStatus: reusableBlock.meta.sync_status, + syncStatus: reusableBlock.meta?.sync_status, }; }; From c04f927363622bf19c5bc9ebab3c98c3da420e09 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 19 Jun 2023 12:13:59 +1200 Subject: [PATCH 59/68] Put all user patterns in the old reusable blocks tab for now --- .../src/components/inserter/reusable-blocks-tab.js | 11 ++++------- .../block-editor/src/components/inserter/tabs.js | 2 +- packages/e2e-test-utils/src/inserter.js | 14 +++++++------- 3 files changed, 12 insertions(+), 15 deletions(-) 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 b091499d018bd..78a84a820c76d 100644 --- a/packages/block-editor/src/components/inserter/reusable-blocks-tab.js +++ b/packages/block-editor/src/components/inserter/reusable-blocks-tab.js @@ -21,10 +21,7 @@ function ReusableBlocksList( { onHover, onInsert, rootClientId } ) { ); const filteredItems = useMemo( () => { - return items.filter( - ( { category, syncStatus } ) => - category === 'reusable' && syncStatus !== 'unsynced' - ); + return items.filter( ( { category } ) => category === 'reusable' ); }, [ items ] ); if ( filteredItems.length === 0 ) { @@ -32,12 +29,12 @@ function ReusableBlocksList( { onHover, onInsert, rootClientId } ) { } return ( - + ); @@ -70,7 +67,7 @@ export function ReusableBlocksTab( { rootClientId, onInsert, onHover } ) { post_type: 'wp_block', } ) } > - { __( 'Manage Synced Patterns' ) } + { __( 'Manage Your Patterns' ) }
diff --git a/packages/block-editor/src/components/inserter/tabs.js b/packages/block-editor/src/components/inserter/tabs.js index f11ce9d31ab5d..78a606f70407a 100644 --- a/packages/block-editor/src/components/inserter/tabs.js +++ b/packages/block-editor/src/components/inserter/tabs.js @@ -19,7 +19,7 @@ const patternsTab = { const reusableBlocksTab = { name: 'reusable', /* translators: Locally created Patterns tab title in the block inserter. */ - title: __( 'Synced Patterns' ), + title: __( 'Your Patterns' ), icon: reusableBlockIcon, }; const mediaTab = { diff --git a/packages/e2e-test-utils/src/inserter.js b/packages/e2e-test-utils/src/inserter.js index 075e74ee623af..cc03f17f34284 100644 --- a/packages/e2e-test-utils/src/inserter.js +++ b/packages/e2e-test-utils/src/inserter.js @@ -106,8 +106,8 @@ export async function selectGlobalInserterTab( label ) { case 'Media': labelSelector = `. = "${ label }"`; break; - case 'Synced Patterns': - // Synced Patterns tab label is an icon, hence the different selector. + case 'Your Patterns': + // Your Patterns tab label is an icon, hence the different selector. labelSelector = `@aria-label = "${ label }"`; break; } @@ -180,7 +180,7 @@ export async function searchGlobalInserter( category, searchTerm ) { switch ( category ) { case 'Blocks': case 'Patterns': - case 'Synced Patterns': { + case 'Your Patterns': { waitForInsertElement = async () => { return await page.waitForXPath( `//*[@role='option' and contains(., '${ searchTerm }')]` @@ -220,7 +220,7 @@ export async function searchGlobalInserter( category, searchTerm ) { * If the entity is not instantly available in the open inserter, a search will * be performed. If the search returns no results, an error will be thrown. * - * Available categories: Blocks, Patterns, Synced Patterns and Block Directory. + * Available categories: Blocks, Patterns, Your Patterns and Block Directory. * * @param {string} category The category to insert from. * @param {string} searchTerm The term by which to find the entity to insert. @@ -231,7 +231,7 @@ export async function insertFromGlobalInserter( category, searchTerm ) { let insertButton; - if ( [ 'Blocks', 'Synced Patterns' ].includes( category ) ) { + if ( [ 'Blocks', 'Your Patterns' ].includes( category ) ) { // If it's a block, see if it's insertable without searching... try { insertButton = ( @@ -260,7 +260,7 @@ export async function insertFromGlobalInserter( category, searchTerm ) { await insertButton.click(); // Extra wait for the reusable block to be ready. - if ( category === 'Synced Patterns' ) { + if ( category === 'Your Patterns' ) { await canvas().waitForSelector( '.block-library-block__reusable-block-container' ); @@ -347,7 +347,7 @@ export async function insertPattern( searchTerm ) { * insert. */ export async function insertReusableBlock( searchTerm ) { - await insertFromGlobalInserter( 'Synced Patterns', searchTerm ); + await insertFromGlobalInserter( 'Your Patterns', searchTerm ); } /** From 6d7fd7e313f7aea762b0c98e6d1df637f6b8048d Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 19 Jun 2023 13:07:19 +1200 Subject: [PATCH 60/68] More test fixes --- .../specs/editor/various/reusable-blocks.test.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js index 97bfe31a9077f..416782733dfaa 100644 --- a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js @@ -23,6 +23,10 @@ const reusableBlockNameInputSelector = '.reusable-blocks-menu-items__convert-modal .components-text-control__input'; const reusableBlockInspectorNameInputSelector = '.block-editor-block-inspector .components-text-control__input'; +const syncToggleSelector = + '.reusable-blocks-menu-items__convert-modal .components-form-toggle__input'; +const syncToggleSelectorChecked = + '.reusable-blocks-menu-items__convert-modal .components-form-toggle.is-checked'; const saveAll = async () => { const publishButtonSelector = @@ -201,6 +205,9 @@ describe( 'Reusable blocks', () => { ); await nameInput.click(); await page.keyboard.type( 'Multi-selection reusable block' ); + const syncToggle = await page.waitForSelector( syncToggleSelector ); + syncToggle.click(); + await page.waitForSelector( syncToggleSelectorChecked ); await page.keyboard.press( 'Enter' ); // Wait for creation to finish. @@ -259,7 +266,7 @@ describe( 'Reusable blocks', () => { // Save the reusable block. await page.click( publishButtonSelector ); await page.waitForXPath( - '//*[contains(@class, "components-snackbar")]/*[text()="Site updated."]' + '//*[contains(@class, "components-snackbar")]/*[text()="Pattern updated."]' ); await createNewPost(); @@ -345,7 +352,7 @@ describe( 'Reusable blocks', () => { expect( reusableBlockWithParagraph ).toBeTruthy(); // Convert back to regular blocks. - await clickBlockToolbarButton( 'Select Reusable block' ); + await clickBlockToolbarButton( 'Select Pattern' ); await clickBlockToolbarButton( 'Convert to regular block' ); await page.waitForXPath( selector, { hidden: true, @@ -382,6 +389,9 @@ describe( 'Reusable blocks', () => { ); await nameInput.click(); await page.keyboard.type( 'Block with styles' ); + const syncToggle = await page.waitForSelector( syncToggleSelector ); + syncToggle.click(); + await page.waitForSelector( syncToggleSelectorChecked ); await page.keyboard.press( 'Enter' ); const reusableBlock = await canvas().waitForSelector( '.block-editor-block-list__block[aria-label="Block: Pattern"]' From ec7056beb958c637055574206e5349ac2bb52e23 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 19 Jun 2023 16:24:39 +1200 Subject: [PATCH 61/68] Reorder pattern tabs, with synced only in the old reusable blocks tab --- .../components/inserter/block-patterns-tab.js | 44 ++++++++++++++++--- .../inserter/reusable-blocks-tab.js | 9 ++-- .../src/components/inserter/tabs.js | 2 +- packages/block-editor/src/store/selectors.js | 4 ++ packages/e2e-test-utils/src/inserter.js | 14 +++--- 5 files changed, 57 insertions(+), 16 deletions(-) diff --git a/packages/block-editor/src/components/inserter/block-patterns-tab.js b/packages/block-editor/src/components/inserter/block-patterns-tab.js index 49a5939107bb1..73162b6d4cfcf 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-tab.js +++ b/packages/block-editor/src/components/inserter/block-patterns-tab.js @@ -27,6 +27,7 @@ import usePatternsState from './hooks/use-patterns-state'; import BlockPatternList from '../block-patterns-list'; import PatternsExplorerModal from './block-patterns-explorer/explorer'; import MobileTabNavigation from './mobile-tab-navigation'; +import useBlockTypesState from './hooks/use-block-types-state'; const noop = () => {}; @@ -49,6 +50,14 @@ function usePatternsCategories( rootClientId ) { rootClientId ); + const [ unsyncedPatterns ] = useBlockTypesState( rootClientId ); + const filteredUnsyncedPatterns = useMemo( () => { + return unsyncedPatterns.filter( + ( { category: unsyncedPatternCategory, syncStatus } ) => + unsyncedPatternCategory === 'reusable' && + syncStatus === 'unsynced' + ); + }, [ unsyncedPatterns ] ); const hasRegisteredCategory = useCallback( ( pattern ) => { if ( ! pattern.categories || ! pattern.categories.length ) { @@ -93,9 +102,20 @@ function usePatternsCategories( rootClientId ) { label: _x( 'Uncategorized' ), } ); } + if ( filteredUnsyncedPatterns.length > 0 ) { + categories.push( { + name: 'reusable', + label: _x( 'Your patterns' ), + } ); + } return categories; - }, [ allPatterns, allCategories ] ); + }, [ + allCategories, + allPatterns, + filteredUnsyncedPatterns.length, + hasRegisteredCategory, + ] ); return populatedCategories; } @@ -144,6 +164,14 @@ export function BlockPatternsCategoryPanel( { onInsert, rootClientId ); + const [ unsyncedPatterns ] = useBlockTypesState( rootClientId, onInsert ); + const filteredUnsyncedPatterns = useMemo( () => { + return unsyncedPatterns.filter( + ( { category: unsyncedPatternCategory, syncStatus } ) => + unsyncedPatternCategory === 'reusable' && + syncStatus === 'unsynced' + ); + }, [ unsyncedPatterns ] ); const availableCategories = usePatternsCategories( rootClientId ); const currentCategoryPatterns = useMemo( @@ -167,13 +195,19 @@ export function BlockPatternsCategoryPanel( { } ), [ allPatterns, category ] ); - - const currentShownPatterns = useAsyncList( currentCategoryPatterns ); + const patterns = + category.name === 'reusable' + ? filteredUnsyncedPatterns + : currentCategoryPatterns; + const currentShownPatterns = useAsyncList( patterns ); // Hide block pattern preview on unmount. useEffect( () => () => onHover( null ), [] ); - if ( ! currentCategoryPatterns.length ) { + if ( + ! currentCategoryPatterns.length && + ! filteredUnsyncedPatterns.length + ) { return null; } @@ -185,7 +219,7 @@ export function BlockPatternsCategoryPanel( {

{ category.description }

{ - return items.filter( ( { category } ) => category === 'reusable' ); + return items.filter( + ( { category, syncStatus } ) => + category === 'reusable' && syncStatus !== 'unsynced' + ); }, [ items ] ); if ( filteredItems.length === 0 ) { @@ -29,12 +32,12 @@ function ReusableBlocksList( { onHover, onInsert, rootClientId } ) { } return ( - + ); diff --git a/packages/block-editor/src/components/inserter/tabs.js b/packages/block-editor/src/components/inserter/tabs.js index 78a606f70407a..f11ce9d31ab5d 100644 --- a/packages/block-editor/src/components/inserter/tabs.js +++ b/packages/block-editor/src/components/inserter/tabs.js @@ -19,7 +19,7 @@ const patternsTab = { const reusableBlocksTab = { name: 'reusable', /* translators: Locally created Patterns tab title in the block inserter. */ - title: __( 'Your Patterns' ), + title: __( 'Synced Patterns' ), icon: reusableBlockIcon, }; const mediaTab = { diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 4b5ffbbb45f7a..6987c45f865aa 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -2027,6 +2027,10 @@ export const getInserterItems = createSelector( utility: 1, // Deprecated. frecency, syncStatus: reusableBlock.meta?.sync_status, + content: reusableBlock.content.raw, + blocks: parse( reusableBlock.content.raw, { + __unstableSkipMigrationLogs: true, + } ), }; }; diff --git a/packages/e2e-test-utils/src/inserter.js b/packages/e2e-test-utils/src/inserter.js index cc03f17f34284..075e74ee623af 100644 --- a/packages/e2e-test-utils/src/inserter.js +++ b/packages/e2e-test-utils/src/inserter.js @@ -106,8 +106,8 @@ export async function selectGlobalInserterTab( label ) { case 'Media': labelSelector = `. = "${ label }"`; break; - case 'Your Patterns': - // Your Patterns tab label is an icon, hence the different selector. + case 'Synced Patterns': + // Synced Patterns tab label is an icon, hence the different selector. labelSelector = `@aria-label = "${ label }"`; break; } @@ -180,7 +180,7 @@ export async function searchGlobalInserter( category, searchTerm ) { switch ( category ) { case 'Blocks': case 'Patterns': - case 'Your Patterns': { + case 'Synced Patterns': { waitForInsertElement = async () => { return await page.waitForXPath( `//*[@role='option' and contains(., '${ searchTerm }')]` @@ -220,7 +220,7 @@ export async function searchGlobalInserter( category, searchTerm ) { * If the entity is not instantly available in the open inserter, a search will * be performed. If the search returns no results, an error will be thrown. * - * Available categories: Blocks, Patterns, Your Patterns and Block Directory. + * Available categories: Blocks, Patterns, Synced Patterns and Block Directory. * * @param {string} category The category to insert from. * @param {string} searchTerm The term by which to find the entity to insert. @@ -231,7 +231,7 @@ export async function insertFromGlobalInserter( category, searchTerm ) { let insertButton; - if ( [ 'Blocks', 'Your Patterns' ].includes( category ) ) { + if ( [ 'Blocks', 'Synced Patterns' ].includes( category ) ) { // If it's a block, see if it's insertable without searching... try { insertButton = ( @@ -260,7 +260,7 @@ export async function insertFromGlobalInserter( category, searchTerm ) { await insertButton.click(); // Extra wait for the reusable block to be ready. - if ( category === 'Your Patterns' ) { + if ( category === 'Synced Patterns' ) { await canvas().waitForSelector( '.block-library-block__reusable-block-container' ); @@ -347,7 +347,7 @@ export async function insertPattern( searchTerm ) { * insert. */ export async function insertReusableBlock( searchTerm ) { - await insertFromGlobalInserter( 'Your Patterns', searchTerm ); + await insertFromGlobalInserter( 'Synced Patterns', searchTerm ); } /** From f1975c63a06befff83bd8e564f809d1450df4d07 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 20 Jun 2023 10:50:04 +1200 Subject: [PATCH 62/68] Moving parsing of blocks to patterns panel to avoid parsing reusable blocks when not needed --- .../components/inserter/block-patterns-tab.js | 18 +++++++--- packages/block-editor/src/store/selectors.js | 3 -- .../block-editor/src/store/test/selectors.js | 34 +++++++++---------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/packages/block-editor/src/components/inserter/block-patterns-tab.js b/packages/block-editor/src/components/inserter/block-patterns-tab.js index 73162b6d4cfcf..b99640b85feff 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-tab.js +++ b/packages/block-editor/src/components/inserter/block-patterns-tab.js @@ -18,6 +18,7 @@ import { Button, } from '@wordpress/components'; import { Icon, chevronRight, chevronLeft } from '@wordpress/icons'; +import { parse } from '@wordpress/blocks'; import { focus } from '@wordpress/dom'; /** @@ -166,11 +167,18 @@ export function BlockPatternsCategoryPanel( { ); const [ unsyncedPatterns ] = useBlockTypesState( rootClientId, onInsert ); const filteredUnsyncedPatterns = useMemo( () => { - return unsyncedPatterns.filter( - ( { category: unsyncedPatternCategory, syncStatus } ) => - unsyncedPatternCategory === 'reusable' && - syncStatus === 'unsynced' - ); + return unsyncedPatterns + .filter( + ( { category: unsyncedPatternCategory, syncStatus } ) => + unsyncedPatternCategory === 'reusable' && + syncStatus === 'unsynced' + ) + .map( ( syncedPattern ) => ( { + ...syncedPattern, + blocks: parse( syncedPattern.content, { + __unstableSkipMigrationLogs: true, + } ), + } ) ); }, [ unsyncedPatterns ] ); const availableCategories = usePatternsCategories( rootClientId ); diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 6987c45f865aa..773c4eebc20bd 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -2028,9 +2028,6 @@ export const getInserterItems = createSelector( frecency, syncStatus: reusableBlock.meta?.sync_status, content: reusableBlock.content.raw, - blocks: parse( reusableBlock.content.raw, { - __unstableSkipMigrationLogs: true, - } ), }; }; diff --git a/packages/block-editor/src/store/test/selectors.js b/packages/block-editor/src/store/test/selectors.js index dca9b847bc5a2..270bceaad447f 100644 --- a/packages/block-editor/src/store/test/selectors.js +++ b/packages/block-editor/src/store/test/selectors.js @@ -3326,36 +3326,36 @@ describe( 'selectors', () => { ( item ) => item.id === 'core/test-block-a' ); expect( testBlockAItem ).toEqual( { + category: 'design', + description: undefined, + example: undefined, + frecency: 0, + icon: { src: 'test' }, id: 'core/test-block-a', - name: 'core/test-block-a', initialAttributes: {}, - title: 'Test Block A', - icon: { - src: 'test', - }, - category: 'design', - keywords: [ 'testing' ], - variations: [], isDisabled: false, + keywords: [ 'testing' ], + name: 'core/test-block-a', + title: 'Test Block A', utility: 1, - frecency: 0, + variations: [], } ); const reusableBlockItem = items.find( ( item ) => item.id === 'core/block/1' ); expect( reusableBlockItem ).toEqual( { + category: 'reusable', + content: '', + frecency: 0, + icon: { src: 'test' }, id: 'core/block/1', - name: 'core/block', initialAttributes: { ref: 1 }, - title: 'Reusable Block 1', - icon: { - src: 'test', - }, - category: 'reusable', - keywords: [], isDisabled: false, + keywords: [], + name: 'core/block', + syncStatus: undefined, + title: 'Reusable Block 1', utility: 1, - frecency: 0, } ); } ); From c5845c31692324e1aca1b1f5d5388bcfb8173ebf Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Mon, 19 Jun 2023 15:45:54 +0800 Subject: [PATCH 63/68] Update copy --- .../reusable-blocks-menu-items/reusable-block-convert-button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a723d784d89b6..08a3e1fd93b31 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 @@ -138,7 +138,7 @@ export default function ReusableBlockConvertButton( { { isModalOpen && ( { setIsModalOpen( false ); setTitle( '' ); From 1bbe290c29631d7f1e9b3c4e4a20512e165948b0 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 20 Jun 2023 10:44:30 +1200 Subject: [PATCH 64/68] Changes from review --- docs/reference-guides/core-blocks.md | 2 +- lib/compat/wordpress-6.3/blocks.php | 26 ++++++++++++++++--- packages/block-library/src/pattern/block.json | 2 +- .../reusable-block-convert-button.js | 12 +++------ 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index eb634c5ac7647..0a6519576da3a 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -473,7 +473,7 @@ Start with the basic building block of all narrative. ([Source](https://github.c - **Supports:** __unstablePasteTextInline, anchor, color (background, gradients, link, text), spacing (margin, padding), typography (fontSize, lineHeight), ~~className~~ - **Attributes:** align, content, direction, dropCap, placeholder -## Pattern +## Pattern placeholder Show a block pattern. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/pattern)) diff --git a/lib/compat/wordpress-6.3/blocks.php b/lib/compat/wordpress-6.3/blocks.php index 470175ffd86f8..6902a258c5c3d 100644 --- a/lib/compat/wordpress-6.3/blocks.php +++ b/lib/compat/wordpress-6.3/blocks.php @@ -28,8 +28,7 @@ function gutenberg_add_selectors_property_to_block_type_settings( $settings, $me add_filter( 'block_type_metadata_settings', 'gutenberg_add_selectors_property_to_block_type_settings', 10, 2 ); /** - * Adds custom fields support to the wp_block post type so an unsynced option can be added and renames - * from Reusable block to Pattern. + * Renames Reusable block CPT to Pattern. * * Note: This should be removed when the minimum required WP version is >= 6.3. * @@ -40,7 +39,7 @@ function gutenberg_add_selectors_property_to_block_type_settings( $settings, $me * * @return array Register post type args. */ -function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ) { +function gutenberg_rename_reusable_block_cpt_to_pattern( $args, $post_type ) { if ( 'wp_block' === $post_type ) { $args['labels']['name'] = _x( 'Patterns', 'post type general name' ); $args['labels']['singular_name'] = _x( 'Pattern', 'post type singular name' ); @@ -60,6 +59,27 @@ function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ) { $args['labels']['item_reverted_to_draft'] = __( 'Pattern reverted to draft.' ); $args['labels']['item_scheduled'] = __( 'Pattern scheduled.' ); $args['labels']['item_updated'] = __( 'Pattern updated.' ); + } + + return $args; +} + +add_filter( 'register_post_type_args', 'gutenberg_rename_reusable_block_cpt_to_pattern', 10, 2 ); + +/** + * Adds custom fields support to the wp_block post type so an unsynced option can be added. + * + * Note: This should be removed when the minimum required WP version is >= 6.3. + * + * @see https://github.com/WordPress/gutenberg/pull/51144 + * + * @param array $args Register post type args. + * @param string $post_type The post type string. + * + * @return array Register post type args. + */ +function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ) { + if ( 'wp_block' === $post_type ) { array_push( $args['supports'], 'custom-fields' ); } diff --git a/packages/block-library/src/pattern/block.json b/packages/block-library/src/pattern/block.json index 16428e2969ca2..1fc319b8fb33d 100644 --- a/packages/block-library/src/pattern/block.json +++ b/packages/block-library/src/pattern/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 3, "name": "core/pattern", - "title": "Pattern", + "title": "Pattern placeholder", "category": "theme", "description": "Show a block pattern.", "supports": { 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 08a3e1fd93b31..02e468725b173 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 @@ -18,7 +18,7 @@ import { } from '@wordpress/components'; import { symbol } from '@wordpress/icons'; import { useDispatch, useSelect } from '@wordpress/data'; -import { __, sprintf } from '@wordpress/i18n'; +import { __ } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; import { store as coreStore } from '@wordpress/core-data'; @@ -96,13 +96,9 @@ export default function ReusableBlockConvertButton( { syncType ); createSuccessNotice( - sprintf( - // translators: %s: The sync status of the block that is created. - __( '%s created.' ), - syncType === 'fully' - ? __( 'Synced Pattern' ) - : __( 'Unsynced Pattern' ) - ), + syncType === 'fully' + ? __( 'Synced Pattern created' ) + : __( 'Unsynced Pattern created' ), { type: 'snackbar', } From ee75c262b10ec33b7e4b24a57a2cc3fa26a57a81 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 20 Jun 2023 11:49:29 +1200 Subject: [PATCH 65/68] Move the sync status filter to the selector --- .../data/data-core-block-editor.md | 1 + .../components/inserter/block-patterns-tab.js | 23 ++++++++++++------- .../inserter/hooks/use-block-types-state.js | 7 +++--- .../inserter/reusable-blocks-tab.js | 5 +--- packages/block-editor/src/store/selectors.js | 13 ++++++++--- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/docs/reference-guides/data/data-core-block-editor.md b/docs/reference-guides/data/data-core-block-editor.md index 8b0f24e60fb7b..20d6ebfe5291a 100644 --- a/docs/reference-guides/data/data-core-block-editor.md +++ b/docs/reference-guides/data/data-core-block-editor.md @@ -538,6 +538,7 @@ _Parameters_ - _state_ `Object`: Editor state. - _rootClientId_ `?string`: Optional root client ID of block list. +- _syncStatus_ `?string`: Optional sync status to filter pattern blocks by. _Returns_ diff --git a/packages/block-editor/src/components/inserter/block-patterns-tab.js b/packages/block-editor/src/components/inserter/block-patterns-tab.js index b99640b85feff..049545025c72e 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-tab.js +++ b/packages/block-editor/src/components/inserter/block-patterns-tab.js @@ -51,12 +51,16 @@ function usePatternsCategories( rootClientId ) { rootClientId ); - const [ unsyncedPatterns ] = useBlockTypesState( rootClientId ); + const [ unsyncedPatterns ] = useBlockTypesState( + rootClientId, + undefined, + 'unsynced' + ); + const filteredUnsyncedPatterns = useMemo( () => { return unsyncedPatterns.filter( - ( { category: unsyncedPatternCategory, syncStatus } ) => - unsyncedPatternCategory === 'reusable' && - syncStatus === 'unsynced' + ( { category: unsyncedPatternCategory } ) => + unsyncedPatternCategory === 'reusable' ); }, [ unsyncedPatterns ] ); const hasRegisteredCategory = useCallback( @@ -165,13 +169,16 @@ export function BlockPatternsCategoryPanel( { onInsert, rootClientId ); - const [ unsyncedPatterns ] = useBlockTypesState( rootClientId, onInsert ); + const [ unsyncedPatterns ] = useBlockTypesState( + rootClientId, + onInsert, + 'unsynced' + ); const filteredUnsyncedPatterns = useMemo( () => { return unsyncedPatterns .filter( - ( { category: unsyncedPatternCategory, syncStatus } ) => - unsyncedPatternCategory === 'reusable' && - syncStatus === 'unsynced' + ( { category: unsyncedPatternCategory } ) => + unsyncedPatternCategory === 'reusable' ) .map( ( syncedPattern ) => ( { ...syncedPattern, diff --git a/packages/block-editor/src/components/inserter/hooks/use-block-types-state.js b/packages/block-editor/src/components/inserter/hooks/use-block-types-state.js index 0b7c8040af8d3..9272a00994321 100644 --- a/packages/block-editor/src/components/inserter/hooks/use-block-types-state.js +++ b/packages/block-editor/src/components/inserter/hooks/use-block-types-state.js @@ -19,9 +19,10 @@ import { store as blockEditorStore } from '../../../store'; * * @param {string=} rootClientId Insertion's root client ID. * @param {Function} onInsert function called when inserter a list of blocks. + * @param {?string} syncStatus Optional sync status to filter pattern blocks by. * @return {Array} Returns the block types state. (block types, categories, collections, onSelect handler) */ -const useBlockTypesState = ( rootClientId, onInsert ) => { +const useBlockTypesState = ( rootClientId, onInsert, syncStatus ) => { const { categories, collections, items } = useSelect( ( select ) => { const { getInserterItems } = select( blockEditorStore ); @@ -30,10 +31,10 @@ const useBlockTypesState = ( rootClientId, onInsert ) => { return { categories: getCategories(), collections: getCollections(), - items: getInserterItems( rootClientId ), + items: getInserterItems( rootClientId, syncStatus ), }; }, - [ rootClientId ] + [ rootClientId, syncStatus ] ); const onSelectItem = useCallback( 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 e76875d2d5e3e..519a7835fec7b 100644 --- a/packages/block-editor/src/components/inserter/reusable-blocks-tab.js +++ b/packages/block-editor/src/components/inserter/reusable-blocks-tab.js @@ -21,10 +21,7 @@ function ReusableBlocksList( { onHover, onInsert, rootClientId } ) { ); const filteredItems = useMemo( () => { - return items.filter( - ( { category, syncStatus } ) => - category === 'reusable' && syncStatus !== 'unsynced' - ); + return items.filter( ( { category } ) => category === 'reusable' ); }, [ items ] ); if ( filteredItems.length === 0 ) { diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 773c4eebc20bd..6a62f50c2a2f7 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1945,6 +1945,7 @@ const buildBlockTypeItem = * * @param {Object} state Editor state. * @param {?string} rootClientId Optional root client ID of block list. + * @param {?string} syncStatus Optional sync status to filter pattern blocks by. * * @return {WPEditorInserterItem[]} Items that appear in inserter. * @@ -1961,7 +1962,7 @@ const buildBlockTypeItem = * @property {number} frecency Heuristic that combines frequency and recency. */ export const getInserterItems = createSelector( - ( state, rootClientId = null ) => { + ( state, rootClientId = null, syncStatus ) => { const buildBlockTypeInserterItem = buildBlockTypeItem( state, { buildScope: 'inserter', } ); @@ -2026,7 +2027,6 @@ export const getInserterItems = createSelector( isDisabled: false, utility: 1, // Deprecated. frecency, - syncStatus: reusableBlock.meta?.sync_status, content: reusableBlock.content.raw, }; }; @@ -2042,7 +2042,14 @@ export const getInserterItems = createSelector( 'core/block', rootClientId ) - ? getReusableBlocks( state ).map( buildReusableBlockInserterItem ) + ? getReusableBlocks( state ) + .filter( + ( reusableBlock ) => + syncStatus === reusableBlock.meta?.sync_status || + ( ! syncStatus && + reusableBlock.meta?.sync_status === '' ) + ) + .map( buildReusableBlockInserterItem ) : []; const items = blockTypeInserterItems.reduce( ( accumulator, item ) => { From 88f48f30e551a3f07ec29013a196e70388918d74 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 20 Jun 2023 11:50:44 +1200 Subject: [PATCH 66/68] Put full stop back --- .../reusable-block-convert-button.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 02e468725b173..c8203fdd73c40 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 @@ -97,8 +97,8 @@ export default function ReusableBlockConvertButton( { ); createSuccessNotice( syncType === 'fully' - ? __( 'Synced Pattern created' ) - : __( 'Unsynced Pattern created' ), + ? __( 'Synced Pattern created.' ) + : __( 'Unsynced Pattern created.' ), { type: 'snackbar', } From d477199535195a3a59365c145e54840eb95b7ac9 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 20 Jun 2023 14:24:33 +1200 Subject: [PATCH 67/68] Change labels --- .../src/components/inserter/block-patterns-tab.js | 2 +- .../src/components/inserter/reusable-blocks-tab.js | 6 +++--- .../block-editor/src/components/inserter/tabs.js | 2 +- packages/e2e-test-utils/src/inserter.js | 14 +++++++------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/block-editor/src/components/inserter/block-patterns-tab.js b/packages/block-editor/src/components/inserter/block-patterns-tab.js index 049545025c72e..578791e880269 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-tab.js +++ b/packages/block-editor/src/components/inserter/block-patterns-tab.js @@ -110,7 +110,7 @@ function usePatternsCategories( rootClientId ) { if ( filteredUnsyncedPatterns.length > 0 ) { categories.push( { name: 'reusable', - label: _x( 'Your patterns' ), + label: _x( 'Custom 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 519a7835fec7b..65930fa9fcd4a 100644 --- a/packages/block-editor/src/components/inserter/reusable-blocks-tab.js +++ b/packages/block-editor/src/components/inserter/reusable-blocks-tab.js @@ -29,12 +29,12 @@ function ReusableBlocksList( { onHover, onInsert, rootClientId } ) { } return ( - + ); @@ -67,7 +67,7 @@ export function ReusableBlocksTab( { rootClientId, onInsert, onHover } ) { post_type: 'wp_block', } ) } > - { __( 'Manage Your Patterns' ) } + { __( 'Manage custom patterns' ) } diff --git a/packages/block-editor/src/components/inserter/tabs.js b/packages/block-editor/src/components/inserter/tabs.js index f11ce9d31ab5d..1ff8b529707a4 100644 --- a/packages/block-editor/src/components/inserter/tabs.js +++ b/packages/block-editor/src/components/inserter/tabs.js @@ -19,7 +19,7 @@ const patternsTab = { const reusableBlocksTab = { name: 'reusable', /* translators: Locally created Patterns tab title in the block inserter. */ - title: __( 'Synced Patterns' ), + title: __( 'Synced patterns' ), icon: reusableBlockIcon, }; const mediaTab = { diff --git a/packages/e2e-test-utils/src/inserter.js b/packages/e2e-test-utils/src/inserter.js index 075e74ee623af..cdd1c534d928d 100644 --- a/packages/e2e-test-utils/src/inserter.js +++ b/packages/e2e-test-utils/src/inserter.js @@ -106,8 +106,8 @@ export async function selectGlobalInserterTab( label ) { case 'Media': labelSelector = `. = "${ label }"`; break; - case 'Synced Patterns': - // Synced Patterns tab label is an icon, hence the different selector. + case 'Synced patterns': + // Synced patterns tab label is an icon, hence the different selector. labelSelector = `@aria-label = "${ label }"`; break; } @@ -180,7 +180,7 @@ export async function searchGlobalInserter( category, searchTerm ) { switch ( category ) { case 'Blocks': case 'Patterns': - case 'Synced Patterns': { + case 'Synced patterns': { waitForInsertElement = async () => { return await page.waitForXPath( `//*[@role='option' and contains(., '${ searchTerm }')]` @@ -220,7 +220,7 @@ export async function searchGlobalInserter( category, searchTerm ) { * If the entity is not instantly available in the open inserter, a search will * be performed. If the search returns no results, an error will be thrown. * - * Available categories: Blocks, Patterns, Synced Patterns and Block Directory. + * Available categories: Blocks, Patterns, Synced patterns and Block Directory. * * @param {string} category The category to insert from. * @param {string} searchTerm The term by which to find the entity to insert. @@ -231,7 +231,7 @@ export async function insertFromGlobalInserter( category, searchTerm ) { let insertButton; - if ( [ 'Blocks', 'Synced Patterns' ].includes( category ) ) { + if ( [ 'Blocks', 'Synced patterns' ].includes( category ) ) { // If it's a block, see if it's insertable without searching... try { insertButton = ( @@ -260,7 +260,7 @@ export async function insertFromGlobalInserter( category, searchTerm ) { await insertButton.click(); // Extra wait for the reusable block to be ready. - if ( category === 'Synced Patterns' ) { + if ( category === 'Synced patterns' ) { await canvas().waitForSelector( '.block-library-block__reusable-block-container' ); @@ -347,7 +347,7 @@ export async function insertPattern( searchTerm ) { * insert. */ export async function insertReusableBlock( searchTerm ) { - await insertFromGlobalInserter( 'Synced Patterns', searchTerm ); + await insertFromGlobalInserter( 'Synced patterns', searchTerm ); } /** From a30956215f2eaa3dca894467e3fe7d10d9134e55 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 20 Jun 2023 15:19:06 +1200 Subject: [PATCH 68/68] Remove the synced to unsynced conversion call --- packages/block-library/src/block/edit.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/packages/block-library/src/block/edit.js b/packages/block-library/src/block/edit.js index 093d9e5f6c597..cc1ec16aeedc2 100644 --- a/packages/block-library/src/block/edit.js +++ b/packages/block-library/src/block/edit.js @@ -29,7 +29,6 @@ import { } from '@wordpress/block-editor'; import { store as reusableBlocksStore } from '@wordpress/reusable-blocks'; import { ungroup } from '@wordpress/icons'; -import { cloneBlock } from '@wordpress/blocks'; export default function ReusableBlockEdit( { attributes: { ref }, clientId } ) { const hasAlreadyRendered = useHasRecursion( ref ); @@ -55,25 +54,12 @@ export default function ReusableBlockEdit( { attributes: { ref }, clientId } ) { const { __experimentalConvertBlockToStatic: convertBlockToStatic } = useDispatch( reusableBlocksStore ); - const { replaceBlocks } = useDispatch( blockEditorStore ); - const [ blocks, onInput, onChange ] = useEntityBlockEditor( 'postType', 'wp_block', { id: ref } ); - if ( - hasResolved && - record?.meta?.sync_status === 'unsynced' && - blocks.length > 0 - ) { - replaceBlocks( - clientId, - blocks.map( ( block ) => cloneBlock( block ) ) - ); - } - const [ title, setTitle ] = useEntityProp( 'postType', 'wp_block',