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] Block title in unsupported block #18268

Merged
merged 29 commits into from Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e7d8e59
WC: #479: Adding help icon and modal to unsupported block. Also putti…
illusaen Oct 14, 2019
a23f7a3
WC: #479: Adding in unit tests for the component.
illusaen Oct 14, 2019
766ce90
WC: #479: Changing the help icon press surface to the whole block bec…
illusaen Oct 14, 2019
756b5e8
WC: #479: Changing accessibility label and adding comment.
illusaen Oct 15, 2019
3a9cf57
WC: #479: Adding in text/buttons to match later design.
illusaen Oct 16, 2019
47b491b
WC: issue #479: Changing only the question mark icon to be tappable f…
illusaen Nov 4, 2019
056b1bd
Merge branch 'master' into rnmobile/block-title-in-unsupported-block
hypest Nov 4, 2019
28b6a08
Display 'unsupported' on all unsupported blocks on mobile
hypest Nov 4, 2019
40ec6da
Update the test snapshot of Unsupported block on mobile
hypest Nov 4, 2019
eab0ba3
Need to mock styling on mobile
hypest Nov 4, 2019
6bb7dcb
Adjust tests to latest changes
hypest Nov 4, 2019
e5a2433
Display the block name in quotes, for clarity
hypest Nov 4, 2019
5a9e429
Dark mode of info text, title and description
hypest Nov 5, 2019
4c2b904
sprintf to compose string, separate strings per platform
hypest Nov 5, 2019
f7c8582
Wrap JSX in the grouping operator, as usual
hypest Nov 5, 2019
32d4887
Remove dismiss button, not used in other bottom-sheets
hypest Nov 5, 2019
4627420
Remove unused import
hypest Nov 5, 2019
6815b3c
Revise sprintf format to green the linter
hypest Nov 5, 2019
83bba75
Update tests after removing the Close button
hypest Nov 5, 2019
91e74a9
Merge branch 'master' into rnmobile/block-title-in-unsupported-block
hypest Nov 6, 2019
b2bbd73
Merge branch 'master' into rnmobile/block-title-in-unsupported-block
hypest Nov 6, 2019
e863087
Wrap more JSX in the grouping operator, as usual
hypest Nov 6, 2019
92d7e71
Adjust the info-icon color
hypest Nov 7, 2019
c4bc0c8
Merge branch 'master' into rnmobile/block-title-in-unsupported-block
hypest Nov 7, 2019
d150383
Merge branch 'master' into rnmobile/block-title-in-unsupported-block
hypest Nov 7, 2019
69998f0
Merge branch 'master' into rnmobile/block-title-in-unsupported-block
hypest Nov 7, 2019
e26a61b
Different colors for the icon on the sheet
hypest Nov 7, 2019
0569a38
Remove local mock, using the global styleMock.js instead
hypest Nov 7, 2019
973c2f8
Enable testing both mobile platforms
hypest Nov 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 74 additions & 5 deletions packages/block-library/src/missing/edit.native.js
@@ -1,43 +1,112 @@
/**
* External dependencies
*/
import { View, Text } from 'react-native';
import { Platform, View, Text, TouchableWithoutFeedback } from 'react-native';

/**
* WordPress dependencies
*/
import { Icon } from '@wordpress/components';
import { BottomSheet, Icon } from '@wordpress/components';
import { withPreferredColorScheme } from '@wordpress/compose';
import { coreBlocks } from '@wordpress/block-library';
import { normalizeIconObject } from '@wordpress/blocks';
import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import styles from './style.scss';

export class UnsupportedBlockEdit extends Component {
constructor( props ) {
super( props );
this.state = { showHelp: false };
}

toggleSheet() {
this.setState( {
showHelp: ! this.state.showHelp,
} );
}

renderHelpIcon() {
const infoIconStyle = this.props.getStylesFromColorScheme( styles.infoIcon, styles.infoIconDark );

return (
<TouchableWithoutFeedback
accessibilityLabel={ __( 'Help icon' ) }
accessibilityRole={ 'button' }
accessibilityHint={ __( 'Tap here to show help' ) }
onPress={ this.toggleSheet.bind( this ) }
>
<View style={ styles.helpIconContainer } >
<Icon
className="unsupported-icon-help"
label={ __( 'Help icon' ) }
icon="editor-help"
color={ infoIconStyle.color }
/>
</View>
</TouchableWithoutFeedback>
);
}

renderSheet( title ) {
const { getStylesFromColorScheme } = this.props;
const infoTextStyle = getStylesFromColorScheme( styles.infoText, styles.infoTextDark );
const infoTitleStyle = getStylesFromColorScheme( styles.infoTitle, styles.infoTitleDark );
const infoDescriptionStyle = getStylesFromColorScheme( styles.infoDescription, styles.infoDescriptionDark );
const infoIconStyle = getStylesFromColorScheme( styles.infoIcon, styles.infoIconDark );

// translators: %s: Name of the block
const titleFormat = Platform.OS === 'android' ? __( '\'%s\' isn\'t yet supported on WordPress for Android' ) :
__( '\'%s\' isn\'t yet supported on WordPress for iOS' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Not an issue for this PR, but noting for the future: I just realized this might be used in other apps, so we should find a way to inject the app name from the apps instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

const infoTitle = sprintf(
titleFormat,
title,
);

return (
<BottomSheet
isVisible={ this.state.showHelp }
hideHeader
onClose={ this.toggleSheet.bind( this ) }
>
<View style={ styles.infoContainer } >
<Icon icon="editor-help" color={ infoIconStyle.color } size={ styles.infoIcon.size } />
<Text style={ [ infoTextStyle, infoTitleStyle ] }>
{ infoTitle }
</Text>
<Text style={ [ infoTextStyle, infoDescriptionStyle ] }>
{ __( 'We are working hard to add more blocks with each release. In the meantime, you can also edit this post on the web.' ) }
</Text>
</View>
</BottomSheet>
);
}

render() {
const { originalName } = this.props.attributes;
const { getStylesFromColorScheme, preferredColorScheme } = this.props;
const blockType = coreBlocks[ originalName ];

const title = blockType ? blockType.settings.title : __( 'Unsupported' );
const title = blockType ? blockType.settings.title : originalName;
const titleStyle = getStylesFromColorScheme( styles.unsupportedBlockMessage, styles.unsupportedBlockMessageDark );

const subTitleStyle = getStylesFromColorScheme( styles.unsupportedBlockSubtitle, styles.unsupportedBlockSubtitleDark );
const subtitle = blockType ? <Text style={ subTitleStyle }>{ __( 'Unsupported' ) }</Text> : null;
const subtitle = <Text style={ subTitleStyle }>{ __( 'Unsupported' ) }</Text>;

const icon = blockType ? normalizeIconObject( blockType.settings.icon ) : 'admin-plugins';
const iconStyle = getStylesFromColorScheme( styles.unsupportedBlockIcon, styles.unsupportedBlockIconDark );
const iconClassName = 'unsupported-icon' + '-' + preferredColorScheme;
return (
<View style={ getStylesFromColorScheme( styles.unsupportedBlock, styles.unsupportedBlockDark ) }>
{ this.renderHelpIcon() }
<Icon className={ iconClassName } icon={ icon && icon.src ? icon.src : icon } color={ iconStyle.color } />
<Text style={ titleStyle }>{ title }</Text>
{ subtitle }
{ this.renderSheet( title ) }
</View>
);
}
Expand Down
71 changes: 70 additions & 1 deletion packages/block-library/src/missing/style.native.scss
@@ -1,7 +1,76 @@
/** @format */
.content {
padding-top: 8;
padding-bottom: 0;
padding-left: 24;
padding-right: 24;
align-items: center;
justify-content: space-evenly;
}

.helpIconContainer {
position: absolute;
top: 0;
right: 0;
height: 48;
width: 48;
padding-top: 12;
padding-right: 12;
justify-content: flex-start;
align-items: flex-end;
}

.infoContainer {
flex-direction: column;
align-items: center;
justify-content: flex-end;
}

.infoIcon {
size: 36;
height: 36;
padding-top: 8;
padding-bottom: 8;
color: $gray-darken-20;
}

.infoIconDark {
color: $gray-20;
}

.infoText {
text-align: center;
color: $gray-dark;
}

.infoTextDark {
color: $white;
}

.infoTitle {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we must create a infoTitleDark class and update the color.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed with 5a9e429.

padding-top: 8;
padding-bottom: 12;
font-size: 20;
font-weight: bold;
color: $gray-dark;
}

.infoTitleDark {
color: $white;
}

.infoDescription {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as for infoTitle, we should create a infoDescriptionDark class and update the color.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed with 5a9e429.

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

.infoDescriptionDark {
color: $gray-20;
}

.unsupportedBlock {
background-color: #e9eff3; // grey lighten 30
background-color: $gray-lighten-30;
padding-top: 24;
padding-bottom: 24;
padding-left: 8;
Expand Down
@@ -0,0 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Missing block renders without crashing 1`] = `
<View>
<View
accessibilityHint="Tap here to show help"
accessibilityLabel="Help icon"
accessibilityRole="button"
accessible={true}
clickable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
Svg
</View>
Svg
<Text>
missing/block/title
</Text>
<Text>
Unsupported
</Text>
Modal
</View>
`;
87 changes: 87 additions & 0 deletions packages/block-library/src/missing/test/edit.native.js
@@ -0,0 +1,87 @@
/**
* External dependencies
*/
import renderer from 'react-test-renderer';
import { Text } from 'react-native';
jest.mock( 'Platform', () => {
const Platform = require.requireActual( 'Platform' );
Platform.OS = 'ios';
return Platform;
} );

/**
* WordPress dependencies
*/
import { BottomSheet, Icon } from '@wordpress/components';
jest.mock( '@wordpress/blocks' );
jest.mock( '../styles.scss', () => {
return {
infoIcon: { size: 32 },
unsupportedBlockIcon: { color: 'white' },
};
} );

/**
* Internal dependencies
*/
import UnsupportedBlockEdit from '../edit.native.js';

const defaultAttributes = {
originalName: 'missing/block/title',
};

const getTestComponentWithContent = ( attributes = defaultAttributes ) => {
return renderer.create( <UnsupportedBlockEdit attributes={ attributes } /> );
};

describe( 'Missing block', () => {
it( 'renders without crashing', () => {
const component = getTestComponentWithContent();
const rendered = component.toJSON();
expect( rendered ).toMatchSnapshot();
} );

describe( 'help modal', () => {
it( 'renders help icon', () => {
const component = getTestComponentWithContent();
const testInstance = component.root;
const icons = testInstance.findAllByType( Icon );
expect( icons.length ).toBe( 2 );
expect( icons[ 0 ].props.icon ).toBe( 'editor-help' );
} );

it( 'renders info icon on modal', () => {
const component = getTestComponentWithContent();
const testInstance = component.root;
const bottomSheet = testInstance.findByType( BottomSheet );
const children = bottomSheet.props.children.props.children;
expect( children.length ).toBe( 3 ); // 4 children in the bottom sheet: the icon, the "isn't yet supported" title and the "We are working hard..." message
expect( children[ 0 ].props.icon ).toBe( 'editor-help' );
} );

it( 'renders unsupported text on modal', () => {
const component = getTestComponentWithContent();
const testInstance = component.root;
const bottomSheet = testInstance.findByType( BottomSheet );
const children = bottomSheet.props.children.props.children;
expect( children[ 1 ].props.children ).toBe( '\'' + defaultAttributes.originalName + '\' isn\'t yet supported on WordPress for iOS' );
} );
} );

it( 'renders admin plugins icon', () => {
const component = getTestComponentWithContent();
const testInstance = component.root;
const icons = testInstance.findAllByType( Icon );
expect( icons.length ).toBe( 2 );
expect( icons[ 1 ].props.icon ).toBe( 'admin-plugins' );
} );

it( 'renders title text without crashing', () => {
const component = getTestComponentWithContent();
const testInstance = component.root;
const texts = testInstance.findAllByType( Text );
expect( texts.length ).toBe( 2 );
expect( texts[ 0 ].props.children ).toBe( 'missing/block/title' );
expect( texts[ 1 ].props.children ).toBe( 'Unsupported' );
} );
} );
3 changes: 3 additions & 0 deletions test/native/__mocks__/styleMock.js
Expand Up @@ -75,4 +75,7 @@ module.exports = {
unsupportedBlockIcon: {
color: 'white',
},
infoIcon: {
size: 36,
},
};