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] Improve unsupported block message for reusable block #32618

Merged
merged 2 commits into from
Jun 17, 2021
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
61 changes: 55 additions & 6 deletions packages/block-library/src/block/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,30 @@ import {
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { useState, useCallback } from '@wordpress/element';
import {
useEntityBlockEditor,
useEntityProp,
store as coreStore,
} from '@wordpress/core-data';
import { BottomSheet, Icon, Disabled } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import {
BottomSheet,
Icon,
Disabled,
TextControl,
} from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
import {
__experimentalUseNoRecursiveRenders as useNoRecursiveRenders,
InnerBlocks,
Warning,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { usePreferredColorSchemeStyle } from '@wordpress/compose';
import { help } from '@wordpress/icons';
import { store as reusableBlocksStore } from '@wordpress/reusable-blocks';
import { store as noticesStore } from '@wordpress/notices';

/**
* Internal dependencies
Expand Down Expand Up @@ -58,6 +65,14 @@ export default function ReusableBlockEdit( {
styles.infoSheetIcon,
styles.infoSheetIconDark
);
const infoDescriptionStyle = usePreferredColorSchemeStyle(
styles.infoDescription,
styles.infoDescriptionDark
);
const actionButtonStyle = usePreferredColorSchemeStyle(
styles.actionButton,
styles.actionButtonDark
);
const spinnerStyle = usePreferredColorSchemeStyle(
styles.spinner,
styles.spinnerDark
Expand Down Expand Up @@ -88,6 +103,12 @@ export default function ReusableBlockEdit( {
[ ref, clientId ]
);

const { createSuccessNotice } = useDispatch( noticesStore );
const {
__experimentalConvertBlockToStatic: convertBlockToStatic,
} = useDispatch( reusableBlocksStore );
const { clearSelectedBlock } = useDispatch( blockEditorStore );

const [ blocks, onInput, onChange ] = useEntityBlockEditor(
'postType',
'wp_block',
Expand All @@ -104,13 +125,30 @@ export default function ReusableBlockEdit( {
setShowHelp( false );
}

const onConvertToRegularBlocks = useCallback( () => {
createSuccessNotice(
sprintf(
/* translators: %s: name of the reusable block */
__( '%s converted to regular blocks' ),
title
)
);

clearSelectedBlock();
// Convert action is executed at the end of the current JavaScript execution block
// to prevent issues related to undo/redo actions.
setImmediate( () => convertBlockToStatic( clientId ) );
}, [ title, clientId ] );

function renderSheet() {
const infoTitle =
Platform.OS === 'android'
? __(
"Reusable blocks aren't editable on WordPress for Android"
'Editing reusable blocks is not yet supported on WordPress for Android'
)
: __( "Reusable blocks aren't editable on WordPress for iOS" );
: __(
'Editing reusable blocks is not yet supported on WordPress for iOS'
);

return (
<BottomSheet
Expand All @@ -127,6 +165,17 @@ export default function ReusableBlockEdit( {
<Text style={ [ infoTextStyle, infoTitleStyle ] }>
{ infoTitle }
</Text>
<Text style={ [ infoTextStyle, infoDescriptionStyle ] }>
{ __(
'Alternatively, you can detach and edit these blocks separately by tapping "Convert to regular blocks".'
) }
</Text>
<TextControl
label={ __( 'Convert to regular blocks' ) }
separatorType="topFullWidth"
onPress={ onConvertToRegularBlocks }
labelStyle={ actionButtonStyle }
/>
</View>
</BottomSheet>
);
Expand Down
18 changes: 18 additions & 0 deletions packages/block-library/src/block/editor.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@
color: $white;
}

.infoDescription {
padding-bottom: 24;
font-size: 16;
color: $gray-darken-20;
}

.infoDescriptionDark {
color: $gray-20;
}

.actionButton {
color: $blue-50;
}

.actionButtonDark {
color: $blue-30;
}

.spinner {
height: $grid-unit-60;
border-width: $border-width;
Expand Down