Skip to content

Commit

Permalink
Try: Change "Detach pattern" to "Detach" (#56323)
Browse files Browse the repository at this point in the history
* Update: Change "Detach patterns" to singular.

* Try: "Detach" instead of "Detach pattern".
  • Loading branch information
jasmussen authored Nov 20, 2023
1 parent 02c0fc6 commit 0ba206b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ const BlockActionsMenu = ( {
},
convertToRegularBlocks: {
id: 'convertToRegularBlocksOption',
label:
innerBlockCount > 1
? __( 'Detach patterns' )
: __( 'Detach pattern' ),
label: __( 'Detach' ),
value: 'convertToRegularBlocksOption',
onSelect: () => {
/* translators: %s: name of the synced block */
Expand Down
18 changes: 5 additions & 13 deletions packages/block-library/src/block/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -176,20 +176,12 @@ export default function ReusableBlockEdit( {
{ infoTitle }
</Text>
<Text style={ [ infoTextStyle, infoDescriptionStyle ] }>
{ 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”.'
) }
</Text>
<TextControl
label={
innerBlockCount > 1
? __( 'Detach patterns' )
: __( 'Detach pattern' )
}
label={ __( 'Detach' ) }
separatorType="topFullWidth"
onPress={ onConvertToRegularBlocks }
labelStyle={ actionButtonStyle }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe( 'Pattern blocks', () => {

// Convert block to a regular block.
await clickBlockToolbarButton( 'Options' );
await clickMenuItem( 'Detach pattern' );
await clickMenuItem( 'Detach' );

// Check that we have a paragraph block on the page.
const paragraphBlock = await canvas().$(
Expand Down Expand Up @@ -219,7 +219,7 @@ describe( 'Pattern blocks', () => {

// Convert block to a regular block.
await clickBlockToolbarButton( 'Options' );
await clickMenuItem( 'Detach patterns' );
await clickMenuItem( 'Detach' );

// Check that we have two paragraph blocks on the page.
expect( await getEditedPostContent() ).toMatchSnapshot();
Expand Down Expand Up @@ -352,7 +352,7 @@ describe( 'Pattern blocks', () => {
// Convert back to regular blocks.
await clickBlockToolbarButton( 'Select Edited block' );
await clickBlockToolbarButton( 'Options' );
await clickMenuItem( 'Detach pattern' );
await clickMenuItem( 'Detach' );
await page.waitForXPath( selector, {
hidden: true,
} );
Expand Down
71 changes: 34 additions & 37 deletions packages/patterns/src/components/patterns-manage-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -68,9 +67,7 @@ function PatternsManageButton( { clientId } ) {
<MenuItem
onClick={ () => convertSyncedPatternToStatic( clientId ) }
>
{ innerBlockCount > 1
? __( 'Detach patterns' )
: __( 'Detach pattern' ) }
{ __( 'Detach' ) }
</MenuItem>
) }
<MenuItem href={ managePatternsUrl }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -65,9 +64,7 @@ function ReusableBlocksManageButton( { clientId } ) {
</MenuItem>
{ canRemove && (
<MenuItem onClick={ () => convertBlockToStatic( clientId ) }>
{ innerBlockCount > 1
? __( 'Detach patterns' )
: __( 'Detach pattern' ) }
{ __( 'Detach' ) }
</MenuItem>
) }
</>
Expand Down

0 comments on commit 0ba206b

Please sign in to comment.