forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace 'Remove from Reusable blocks' with 'Manage Reusable blocks'.
* 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
Showing
4 changed files
with
58 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 0 additions & 98 deletions
98
...reusable-blocks/src/components/reusable-blocks-menu-items/reusable-block-delete-button.js
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
...eusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |