Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try: Change "Detach pattern" to "Detach" #56323

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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