Skip to content

Commit

Permalink
Replace 'Remove from Reusable blocks' with 'Manage Reusable blocks'.
Browse files Browse the repository at this point in the history
* Removed ReusableBlockDeleteButton component and added ReusableBlocksManageButton in its place.

* On click, ReusableBlocksManageButton sends the user to the reusable blocks management screen.

* Added '@wordpress/url' dependency to the package. This is used to build the  url for the reusable blocks management screen.

Fixes WordPress#12791.
  • Loading branch information
wallstead committed Nov 19, 2020
1 parent 42f5398 commit a6badd3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 100 deletions.
1 change: 1 addition & 0 deletions packages/reusable-blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@wordpress/i18n": "file:../i18n",
"@wordpress/icons": "file:../icons",
"@wordpress/notices": "file:../notices",
"@wordpress/url": "^2.19.0",
"lodash": "^4.17.19"
},
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { withSelect } from '@wordpress/data';
* Internal dependencies
*/
import ReusableBlockConvertButton from './reusable-block-convert-button';
import ReusableBlockDeleteButton from './reusable-block-delete-button';
import ReusableBlocksManageButton from './reusable-blocks-manage-button';

function ReusableBlocksMenuItems( { clientIds, rootClientId } ) {
return (
Expand All @@ -17,7 +17,7 @@ function ReusableBlocksMenuItems( { clientIds, rootClientId } ) {
rootClientId={ rootClientId }
/>
{ clientIds.length === 1 && (
<ReusableBlockDeleteButton clientId={ clientIds[ 0 ] } />
<ReusableBlocksManageButton clientId={ clientIds[ 0 ] } />
) }
</>
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* WordPress dependencies
*/
import { MenuItem } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { isReusableBlock } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';
import { BlockSettingsMenuControls } from '@wordpress/block-editor';
import { addQueryArgs } from '@wordpress/url';

function ReusableBlocksManageButton( { clientId } ) {
const { isVisible } = useSelect(
( select ) => {
const { getBlock } = select( 'core/block-editor' );
const { canUser } = select( 'core' );
const blockObj = getBlock( clientId );

const reusableBlock =
blockObj && isReusableBlock( blockObj )
? select( 'core' ).getEntityRecord(
'postType',
'wp_block',
blockObj.attributes.ref
)
: null;

return {
isVisible:
!! reusableBlock &&
!! canUser( 'update', 'blocks', reusableBlock.id ),
};
},
[ clientId ]
);

if ( ! isVisible ) {
return null;
}

return (
<BlockSettingsMenuControls>
<MenuItem
onClick={ () => {
window.location = addQueryArgs( 'edit.php', {
post_type: 'wp_block',
} );
} }
>
{ __( 'Manage Reusable blocks' ) }
</MenuItem>
</BlockSettingsMenuControls>
);
}

export default ReusableBlocksManageButton;

0 comments on commit a6badd3

Please sign in to comment.