From dbcd8cb776aaba00cdca32645cd7638421891654 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 28 Jun 2023 15:10:02 +1200 Subject: [PATCH 1/9] Update the title of Pattern block in the block inspector card to indicate the sync status --- packages/block-editor/src/components/block-card/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/block-card/index.js b/packages/block-editor/src/components/block-card/index.js index 48f08f06f368cf..dc4fbc74787c97 100644 --- a/packages/block-editor/src/components/block-card/index.js +++ b/packages/block-editor/src/components/block-card/index.js @@ -43,7 +43,9 @@ function BlockCard( { title, icon, description, blockType, className } ) { }, [] ); const { selectBlock } = useDispatch( blockEditorStore ); - + // Only synced patterns are selectable in the editor so change the title to show the sync status. + const blockTitle = + title === __( 'Pattern' ) ? __( 'Synced Pattern' ) : title; return (
{ parentNavBlockClientId && ( // This is only used by the Navigation block for now. It's not ideal having Navigation block specific code here. @@ -61,7 +63,9 @@ function BlockCard( { title, icon, description, blockType, className } ) { ) }
-

{ title }

+

+ { blockTitle } +

{ description } From c314e29e4aedc084bcd0b93d99945dc051d51880 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 28 Jun 2023 17:00:58 +1200 Subject: [PATCH 2/9] Update comment --- packages/block-editor/src/components/block-card/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/block-card/index.js b/packages/block-editor/src/components/block-card/index.js index dc4fbc74787c97..bba1b7a4fdb413 100644 --- a/packages/block-editor/src/components/block-card/index.js +++ b/packages/block-editor/src/components/block-card/index.js @@ -43,7 +43,8 @@ function BlockCard( { title, icon, description, blockType, className } ) { }, [] ); const { selectBlock } = useDispatch( blockEditorStore ); - // Only synced patterns are selectable in the editor so change the title to show the sync status. + // As with Navigation block it's not ideal having Pattern block specific code here, but only synced patterns are selectable in the editor + // currently and finding the sync status higher up involves a call to the core-data store which isn't allowed in the block editor. const blockTitle = title === __( 'Pattern' ) ? __( 'Synced Pattern' ) : title; return ( From f66e16311068866c6c98d5a7c95c56f258410d9f Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 10 Jul 2023 16:06:12 +1200 Subject: [PATCH 3/9] Show the pattern title in inspector block card --- .../src/components/block-card/index.js | 9 ++------- .../use-block-display-information/index.js | 15 ++++++++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/block-editor/src/components/block-card/index.js b/packages/block-editor/src/components/block-card/index.js index bba1b7a4fdb413..48f08f06f368cf 100644 --- a/packages/block-editor/src/components/block-card/index.js +++ b/packages/block-editor/src/components/block-card/index.js @@ -43,10 +43,7 @@ function BlockCard( { title, icon, description, blockType, className } ) { }, [] ); const { selectBlock } = useDispatch( blockEditorStore ); - // As with Navigation block it's not ideal having Pattern block specific code here, but only synced patterns are selectable in the editor - // currently and finding the sync status higher up involves a call to the core-data store which isn't allowed in the block editor. - const blockTitle = - title === __( 'Pattern' ) ? __( 'Synced Pattern' ) : title; + return (
{ parentNavBlockClientId && ( // This is only used by the Navigation block for now. It's not ideal having Navigation block specific code here. @@ -64,9 +61,7 @@ function BlockCard( { title, icon, description, blockType, className } ) { ) }
-

- { blockTitle } -

+

{ title }

{ description } diff --git a/packages/block-editor/src/components/use-block-display-information/index.js b/packages/block-editor/src/components/use-block-display-information/index.js index 87909cea45f637..6f5e1c9a44ab53 100644 --- a/packages/block-editor/src/components/use-block-display-information/index.js +++ b/packages/block-editor/src/components/use-block-display-information/index.js @@ -67,8 +67,11 @@ export default function useBlockDisplayInformation( clientId ) { return useSelect( ( select ) => { if ( ! clientId ) return null; - const { getBlockName, getBlockAttributes } = - select( blockEditorStore ); + const { + getBlockName, + getBlockAttributes, + __experimentalGetReusableBlockTitle, + } = select( blockEditorStore ); const { getBlockType, getActiveBlockVariation } = select( blocksStore ); const blockName = getBlockName( clientId ); @@ -76,12 +79,14 @@ export default function useBlockDisplayInformation( clientId ) { if ( ! blockType ) return null; const attributes = getBlockAttributes( clientId ); const match = getActiveBlockVariation( blockName, attributes ); - const isSynced = - isReusableBlock( blockType ) || isTemplatePart( blockType ); + const isReusable = isReusableBlock( blockType ); + const isSynced = isReusable || isTemplatePart( blockType ); const positionLabel = getPositionTypeLabel( attributes ); const blockTypeInfo = { isSynced, - title: blockType.title, + title: isReusable + ? __experimentalGetReusableBlockTitle( attributes.ref ) + : blockType.title, icon: blockType.icon, description: blockType.description, anchor: attributes?.anchor, From 06535a79c7b5eef637555747944ca115eeeea36d Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 10 Jul 2023 16:17:54 +1200 Subject: [PATCH 4/9] Allow for title being undefined while block is still saving --- .../src/components/use-block-display-information/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/use-block-display-information/index.js b/packages/block-editor/src/components/use-block-display-information/index.js index 6f5e1c9a44ab53..14944742795e17 100644 --- a/packages/block-editor/src/components/use-block-display-information/index.js +++ b/packages/block-editor/src/components/use-block-display-information/index.js @@ -77,16 +77,18 @@ export default function useBlockDisplayInformation( clientId ) { const blockName = getBlockName( clientId ); const blockType = getBlockType( blockName ); if ( ! blockType ) return null; + let title = blockType.title; const attributes = getBlockAttributes( clientId ); const match = getActiveBlockVariation( blockName, attributes ); const isReusable = isReusableBlock( blockType ); + if ( isReusable ) { + title = __experimentalGetReusableBlockTitle( attributes.ref ); + } const isSynced = isReusable || isTemplatePart( blockType ); const positionLabel = getPositionTypeLabel( attributes ); const blockTypeInfo = { isSynced, - title: isReusable - ? __experimentalGetReusableBlockTitle( attributes.ref ) - : blockType.title, + title: title ? title : blockType.title, icon: blockType.icon, description: blockType.description, anchor: attributes?.anchor, From 0dbc1278274dd058aaf003dd2cc6196828f935e8 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Mon, 10 Jul 2023 17:19:34 +1200 Subject: [PATCH 5/9] Fix ternary --- .../src/components/use-block-display-information/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/use-block-display-information/index.js b/packages/block-editor/src/components/use-block-display-information/index.js index 14944742795e17..48e8a9541b36e0 100644 --- a/packages/block-editor/src/components/use-block-display-information/index.js +++ b/packages/block-editor/src/components/use-block-display-information/index.js @@ -82,13 +82,15 @@ export default function useBlockDisplayInformation( clientId ) { const match = getActiveBlockVariation( blockName, attributes ); const isReusable = isReusableBlock( blockType ); if ( isReusable ) { - title = __experimentalGetReusableBlockTitle( attributes.ref ); + title = + __experimentalGetReusableBlockTitle( attributes.ref ) || + blockType.title; } const isSynced = isReusable || isTemplatePart( blockType ); const positionLabel = getPositionTypeLabel( attributes ); const blockTypeInfo = { isSynced, - title: title ? title : blockType.title, + title, icon: blockType.icon, description: blockType.description, anchor: attributes?.anchor, From 918427ba79bf42348a091887dee6d632ba648747 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 12 Jul 2023 11:03:34 +1200 Subject: [PATCH 6/9] rebase --- packages/e2e-tests/specs/editor/various/reusable-blocks.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0a18c75528930c..2f237822b1ccc8 100644 --- a/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/reusable-blocks.test.js @@ -352,7 +352,7 @@ describe( 'Reusable blocks', () => { expect( reusableBlockWithParagraph ).toBeTruthy(); // Convert back to regular blocks. - await clickBlockToolbarButton( 'Select Pattern' ); + await clickBlockToolbarButton( 'Select Edited block' ); await clickBlockToolbarButton( 'Detach pattern' ); await page.waitForXPath( selector, { hidden: true, From 9ff50d878a7d34a1c1762f36189e05b9381658a8 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 12 Jul 2023 10:54:27 +1200 Subject: [PATCH 7/9] Update block description --- docs/reference-guides/core-blocks.md | 2 +- packages/block-library/src/block/block.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 44561fdecfcf70..d0033da9632cba 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -38,7 +38,7 @@ Add a user’s avatar. ([Source](https://github.com/WordPress/gutenberg/tree/tru ## Pattern -Create and save content to reuse across your site. Update the block, and the changes apply everywhere it’s used. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/block)) +Create and save content to reuse across your site. Update the pattern, and the changes apply everywhere it’s used. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/block)) - **Name:** core/block - **Category:** reusable diff --git a/packages/block-library/src/block/block.json b/packages/block-library/src/block/block.json index 5846e7ead0c9b6..01d858f5928348 100644 --- a/packages/block-library/src/block/block.json +++ b/packages/block-library/src/block/block.json @@ -4,7 +4,7 @@ "name": "core/block", "title": "Pattern", "category": "reusable", - "description": "Create and save content to reuse across your site. Update the block, and the changes apply everywhere it’s used.", + "description": "Create and save content to reuse across your site. Update the pattern, and the changes apply everywhere it’s used.", "textdomain": "default", "attributes": { "ref": { From f80054625f3cd85ddd2154954914ddaab53eec92 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 12 Jul 2023 11:50:54 +1200 Subject: [PATCH 8/9] Tidy up title assignment --- .../components/use-block-display-information/index.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/block-editor/src/components/use-block-display-information/index.js b/packages/block-editor/src/components/use-block-display-information/index.js index 48e8a9541b36e0..28b1f07307600d 100644 --- a/packages/block-editor/src/components/use-block-display-information/index.js +++ b/packages/block-editor/src/components/use-block-display-information/index.js @@ -77,15 +77,13 @@ export default function useBlockDisplayInformation( clientId ) { const blockName = getBlockName( clientId ); const blockType = getBlockType( blockName ); if ( ! blockType ) return null; - let title = blockType.title; const attributes = getBlockAttributes( clientId ); const match = getActiveBlockVariation( blockName, attributes ); const isReusable = isReusableBlock( blockType ); - if ( isReusable ) { - title = - __experimentalGetReusableBlockTitle( attributes.ref ) || - blockType.title; - } + const resusableTitle = isReusableBlock( blockType ) + ? __experimentalGetReusableBlockTitle( attributes.ref ) + : undefined; + const title = resusableTitle || blockType.title; const isSynced = isReusable || isTemplatePart( blockType ); const positionLabel = getPositionTypeLabel( attributes ); const blockTypeInfo = { From 3e92024282637bfc799b30778856983b994a39bf Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Wed, 12 Jul 2023 11:53:20 +1200 Subject: [PATCH 9/9] Remove duplicate use of isReusable block --- .../src/components/use-block-display-information/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/use-block-display-information/index.js b/packages/block-editor/src/components/use-block-display-information/index.js index 28b1f07307600d..1cff9da4bc04a9 100644 --- a/packages/block-editor/src/components/use-block-display-information/index.js +++ b/packages/block-editor/src/components/use-block-display-information/index.js @@ -80,7 +80,7 @@ export default function useBlockDisplayInformation( clientId ) { const attributes = getBlockAttributes( clientId ); const match = getActiveBlockVariation( blockName, attributes ); const isReusable = isReusableBlock( blockType ); - const resusableTitle = isReusableBlock( blockType ) + const resusableTitle = isReusable ? __experimentalGetReusableBlockTitle( attributes.ref ) : undefined; const title = resusableTitle || blockType.title;