From 3d0fdde8ba2a2fcf11bb6e60fc903b442d74128d Mon Sep 17 00:00:00 2001 From: jasmussen Date: Mon, 20 Nov 2023 13:39:57 +0100 Subject: [PATCH] Update: Change "Detach patterns" to singular. --- .../block-toolbar-menu.native.js | 5 +- .../block-library/src/block/edit.native.js | 18 ++--- .../editor/various/pattern-blocks.test.js | 2 +- .../src/components/patterns-manage-button.js | 71 +++++++++---------- .../reusable-blocks-manage-button.js | 71 +++++++++---------- 5 files changed, 75 insertions(+), 92 deletions(-) diff --git a/packages/block-editor/src/components/block-toolbar/block-toolbar-menu.native.js b/packages/block-editor/src/components/block-toolbar/block-toolbar-menu.native.js index b579de1f046d9b..8e8f3bd9116113 100644 --- a/packages/block-editor/src/components/block-toolbar/block-toolbar-menu.native.js +++ b/packages/block-editor/src/components/block-toolbar/block-toolbar-menu.native.js @@ -212,10 +212,7 @@ const BlockActionsMenu = ( { }, convertToRegularBlocks: { id: 'convertToRegularBlocksOption', - label: - innerBlockCount > 1 - ? __( 'Detach patterns' ) - : __( 'Detach pattern' ), + label: __( 'Detach pattern' ), value: 'convertToRegularBlocksOption', onSelect: () => { /* translators: %s: name of the synced block */ diff --git a/packages/block-library/src/block/edit.native.js b/packages/block-library/src/block/edit.native.js index ddc22c01e40def..d1d4fa3ad71c5a 100644 --- a/packages/block-library/src/block/edit.native.js +++ b/packages/block-library/src/block/edit.native.js @@ -78,7 +78,7 @@ export default function ReusableBlockEdit( { styles.spinnerDark ); - const { hasResolved, isEditing, isMissing, innerBlockCount } = useSelect( + const { hasResolved, isEditing, isMissing } = useSelect( ( select ) => { const persistedBlock = select( coreStore ).getEntityRecord( 'postType', @@ -176,20 +176,12 @@ export default function ReusableBlockEdit( { { infoTitle } - { innerBlockCount > 1 - ? __( - 'Alternatively, you can detach and edit these blocks separately by tapping “Detach patterns”.' - ) - : __( - 'Alternatively, you can detach and edit this block separately by tapping “Detach pattern”.' - ) } + { __( + 'Alternatively, you can detach and edit this block separately by tapping “Detach pattern”.' + ) } 1 - ? __( 'Detach patterns' ) - : __( 'Detach pattern' ) - } + label={ __( 'Detach pattern' ) } separatorType="topFullWidth" onPress={ onConvertToRegularBlocks } labelStyle={ actionButtonStyle } diff --git a/packages/e2e-tests/specs/editor/various/pattern-blocks.test.js b/packages/e2e-tests/specs/editor/various/pattern-blocks.test.js index 442ed2b21915a5..af6335a20ff686 100644 --- a/packages/e2e-tests/specs/editor/various/pattern-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/pattern-blocks.test.js @@ -219,7 +219,7 @@ describe( 'Pattern blocks', () => { // Convert block to a regular block. await clickBlockToolbarButton( 'Options' ); - await clickMenuItem( 'Detach patterns' ); + await clickMenuItem( 'Detach pattern' ); // Check that we have two paragraph blocks on the page. expect( await getEditedPostContent() ).toMatchSnapshot(); diff --git a/packages/patterns/src/components/patterns-manage-button.js b/packages/patterns/src/components/patterns-manage-button.js index a86208a04b6011..dc38f03f2196aa 100644 --- a/packages/patterns/src/components/patterns-manage-button.js +++ b/packages/patterns/src/components/patterns-manage-button.js @@ -16,41 +16,40 @@ import { store as patternsStore } from '../store'; import { unlock } from '../lock-unlock'; function PatternsManageButton( { clientId } ) { - const { canRemove, isVisible, innerBlockCount, managePatternsUrl } = - useSelect( - ( select ) => { - const { getBlock, canRemoveBlock, getBlockCount, getSettings } = - select( blockEditorStore ); - const { canUser } = select( coreStore ); - const reusableBlock = getBlock( clientId ); - const isBlockTheme = getSettings().__unstableIsBlockBasedTheme; + const { canRemove, isVisible, managePatternsUrl } = useSelect( + ( select ) => { + const { getBlock, canRemoveBlock, getBlockCount, getSettings } = + select( blockEditorStore ); + const { canUser } = select( coreStore ); + const reusableBlock = getBlock( clientId ); + const isBlockTheme = getSettings().__unstableIsBlockBasedTheme; - return { - canRemove: canRemoveBlock( clientId ), - isVisible: - !! reusableBlock && - isReusableBlock( reusableBlock ) && - !! canUser( - 'update', - 'blocks', - reusableBlock.attributes.ref - ), - innerBlockCount: getBlockCount( clientId ), - // The site editor and templates both check whether the user - // has edit_theme_options capabilities. We can leverage that here - // and omit the manage patterns link if the user can't access it. - managePatternsUrl: - isBlockTheme && canUser( 'read', 'templates' ) - ? addQueryArgs( 'site-editor.php', { - path: '/patterns', - } ) - : addQueryArgs( 'edit.php', { - post_type: 'wp_block', - } ), - }; - }, - [ clientId ] - ); + return { + canRemove: canRemoveBlock( clientId ), + isVisible: + !! reusableBlock && + isReusableBlock( reusableBlock ) && + !! canUser( + 'update', + 'blocks', + reusableBlock.attributes.ref + ), + innerBlockCount: getBlockCount( clientId ), + // The site editor and templates both check whether the user + // has edit_theme_options capabilities. We can leverage that here + // and omit the manage patterns link if the user can't access it. + managePatternsUrl: + isBlockTheme && canUser( 'read', 'templates' ) + ? addQueryArgs( 'site-editor.php', { + path: '/patterns', + } ) + : addQueryArgs( 'edit.php', { + post_type: 'wp_block', + } ), + }; + }, + [ clientId ] + ); // Ignore reason: false positive of the lint rule. // eslint-disable-next-line @wordpress/no-unused-vars-before-return @@ -68,9 +67,7 @@ function PatternsManageButton( { clientId } ) { convertSyncedPatternToStatic( clientId ) } > - { innerBlockCount > 1 - ? __( 'Detach patterns' ) - : __( 'Detach pattern' ) } + { __( 'Detach pattern' ) } ) } diff --git a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js index 6ca19269d40f64..3f6597137d26fb 100644 --- a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +++ b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js @@ -15,41 +15,40 @@ import { store as coreStore } from '@wordpress/core-data'; import { store as reusableBlocksStore } from '../../store'; function ReusableBlocksManageButton( { clientId } ) { - const { canRemove, isVisible, innerBlockCount, managePatternsUrl } = - useSelect( - ( select ) => { - const { getBlock, canRemoveBlock, getBlockCount, getSettings } = - select( blockEditorStore ); - const { canUser } = select( coreStore ); - const reusableBlock = getBlock( clientId ); - const isBlockTheme = getSettings().__unstableIsBlockBasedTheme; + const { canRemove, isVisible, managePatternsUrl } = useSelect( + ( select ) => { + const { getBlock, canRemoveBlock, getBlockCount, getSettings } = + select( blockEditorStore ); + const { canUser } = select( coreStore ); + const reusableBlock = getBlock( clientId ); + const isBlockTheme = getSettings().__unstableIsBlockBasedTheme; - return { - canRemove: canRemoveBlock( clientId ), - isVisible: - !! reusableBlock && - isReusableBlock( reusableBlock ) && - !! canUser( - 'update', - 'blocks', - reusableBlock.attributes.ref - ), - innerBlockCount: getBlockCount( clientId ), - // The site editor and templates both check whether the user - // has edit_theme_options capabilities. We can leverage that here - // and omit the manage patterns link if the user can't access it. - managePatternsUrl: - isBlockTheme && canUser( 'read', 'templates' ) - ? addQueryArgs( 'site-editor.php', { - path: '/patterns', - } ) - : addQueryArgs( 'edit.php', { - post_type: 'wp_block', - } ), - }; - }, - [ clientId ] - ); + return { + canRemove: canRemoveBlock( clientId ), + isVisible: + !! reusableBlock && + isReusableBlock( reusableBlock ) && + !! canUser( + 'update', + 'blocks', + reusableBlock.attributes.ref + ), + innerBlockCount: getBlockCount( clientId ), + // The site editor and templates both check whether the user + // has edit_theme_options capabilities. We can leverage that here + // and omit the manage patterns link if the user can't access it. + managePatternsUrl: + isBlockTheme && canUser( 'read', 'templates' ) + ? addQueryArgs( 'site-editor.php', { + path: '/patterns', + } ) + : addQueryArgs( 'edit.php', { + post_type: 'wp_block', + } ), + }; + }, + [ clientId ] + ); const { __experimentalConvertBlockToStatic: convertBlockToStatic } = useDispatch( reusableBlocksStore ); @@ -65,9 +64,7 @@ function ReusableBlocksManageButton( { clientId } ) { { canRemove && ( convertBlockToStatic( clientId ) }> - { innerBlockCount > 1 - ? __( 'Detach patterns' ) - : __( 'Detach pattern' ) } + { __( 'Detach pattern' ) } ) }