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

[RNMobile] Add convert to regular blocks action to Reusable block #31012

Merged
Merged
Changes from 2 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 @@ -19,13 +19,17 @@ import {
rawHandler,
createBlock,
isUnmodifiedDefaultBlock,
isReusableBlock,
} from '@wordpress/blocks';
import { __, sprintf } from '@wordpress/i18n';
import { withDispatch, withSelect } from '@wordpress/data';
import { withInstanceId, compose } from '@wordpress/compose';
import { moreHorizontalMobile } from '@wordpress/icons';
import { useRef, useState } from '@wordpress/element';
import { store as noticesStore } from '@wordpress/notices';
import { store as reusableBlocksStore } from '@wordpress/reusable-blocks';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
Expand All @@ -41,11 +45,13 @@ const BlockActionsMenu = ( {
isEmptyDefaultBlock,
isFirst,
isLast,
reusableBlock,
rootClientId,
selectedBlockClientId,
selectedBlockPossibleTransformations,
// Dispatch
createSuccessNotice,
convertBlockToStatic,
duplicateBlock,
onMoveDown,
onMoveUp,
Expand All @@ -58,6 +64,7 @@ const BlockActionsMenu = ( {
onDelete,
wrapBlockMover,
wrapBlockSettings,
isReusableBlockType,
} ) => {
const [ clipboard, setCurrentClipboard ] = useState( getClipboard() );
const blockActionsMenuPickerRef = useRef();
Expand Down Expand Up @@ -175,6 +182,21 @@ const BlockActionsMenu = ( {
);
},
},
convertToRegularBlocks: {
id: 'convertToRegularBlocksOption',
label: __( 'Convert to regular blocks' ),
value: 'convertToRegularBlocksOption',
onSelect: () => {
createSuccessNotice(
sprintf(
/* translators: %s: name of the reusable block */
__( '%s converted to regular blocks' ),
reusableBlock?.title?.raw || blockTitle
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the reusable block's title is not defined it will fallback to "Reusable block".

Copy link
Contributor Author

@fluiddot fluiddot Apr 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally I realised that the notice component doesn't handle content overflow (see attached screenshot).

Block selected Block converted to regular blocks

I'll fix this issue in a separate PR 🔧 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created the fix in this PR.

)
);
convertBlockToStatic( selectedBlockClientId );
},
},
};

const options = compact( [
Expand All @@ -187,6 +209,7 @@ const BlockActionsMenu = ( {
allOptions.cutButton,
isPasteEnabled && allOptions.pasteButton,
allOptions.duplicateButton,
isReusableBlockType && allOptions.convertToRegularBlocks,
allOptions.delete,
] );

Expand Down Expand Up @@ -297,6 +320,15 @@ export default compose(
? getBlockTransformItems( [ selectedBlock ], rootClientId )
: [];

const isReusableBlockType = block ? isReusableBlock( block ) : false;
const reusableBlock = isReusableBlockType
? select( coreStore ).getEntityRecord(
'postType',
'wp_block',
block?.attributes.ref
)
: undefined;

return {
blockTitle,
canInsertBlockType,
Expand All @@ -305,6 +337,8 @@ export default compose(
isEmptyDefaultBlock,
isFirst: firstIndex === 0,
isLast: lastIndex === blockOrder.length - 1,
isReusableBlockType,
reusableBlock,
rootClientId,
selectedBlockClientId,
selectedBlockPossibleTransformations,
Expand All @@ -326,8 +360,13 @@ export default compose(
);
const { createSuccessNotice } = dispatch( noticesStore );

const {
__experimentalConvertBlockToStatic: convertBlockToStatic,
} = dispatch( reusableBlocksStore );

return {
createSuccessNotice,
convertBlockToStatic,
duplicateBlock() {
return duplicateBlocks( clientIds );
},
Expand Down