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] File and Audio block simplify media flow #31025

Merged
merged 9 commits into from
Apr 23, 2021
12 changes: 11 additions & 1 deletion packages/block-library/src/audio/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import {
MediaPlaceholder,
MediaUpload,
MediaUploadProgress,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __, sprintf } from '@wordpress/i18n';
import { audio as icon, replace } from '@wordpress/icons';
import { useState } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';

/**
Expand All @@ -55,6 +56,14 @@ function AudioEdit( {
setAttributes( { id: mediaId, src: mediaUrl } );
};

const { wasBlockJustInserted } = useSelect( ( select ) => {
return {
wasBlockJustInserted: select(
blockEditorStore
).wasBlockJustInserted( clientId, 'inserter_menu' ),
};
} );
fluiddot marked this conversation as resolved.
Show resolved Hide resolved

const { createErrorNotice } = useDispatch( noticesStore );

const onError = () => {
Expand Down Expand Up @@ -104,6 +113,7 @@ function AudioEdit( {
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ attributes }
onFocus={ onFocus }
autoOpenMediaUpload={ isSelected && wasBlockJustInserted }
/>
</View>
);
Expand Down
9 changes: 7 additions & 2 deletions packages/block-library/src/file/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
MediaUpload,
InspectorControls,
MEDIA_TYPE_ANY,
store as blockEditorStore,
} from '@wordpress/block-editor';
import {
ToolbarButton,
Expand Down Expand Up @@ -552,7 +553,7 @@ export class FileEdit extends Component {
}

render() {
const { attributes } = this.props;
const { attributes, wasBlockJustInserted, isSelected } = this.props;
const { href } = attributes;

if ( ! href ) {
Expand All @@ -566,6 +567,7 @@ export class FileEdit extends Component {
onSelect={ this.onSelectFile }
onFocus={ this.props.onFocus }
allowedTypes={ [ MEDIA_TYPE_ANY ] }
autoOpenMediaUpload={ isSelected && wasBlockJustInserted }
/>
);
}
Expand All @@ -585,7 +587,7 @@ export class FileEdit extends Component {

export default compose( [
withSelect( ( select, props ) => {
const { attributes, isSelected } = props;
const { attributes, isSelected, clientId } = props;
const { id, href } = attributes;
const { isEditorSidebarOpened } = select( 'core/edit-post' );
const isNotFileHref = id && getProtocol( href ) !== 'file:';
Expand All @@ -594,6 +596,9 @@ export default compose( [
? select( coreStore ).getMedia( id )
: undefined,
isSidebarOpened: isSelected && isEditorSidebarOpened(),
wasBlockJustInserted: select(
blockEditorStore
).wasBlockJustInserted( clientId, 'inserter_menu' ),
};
} ),
withDispatch( ( dispatch ) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ export class ImageEdit extends Component {
icon={ this.getPlaceholderIcon() }
onFocus={ this.props.onFocus }
autoOpenMediaUpload={
isSelected && ! url && wasBlockJustInserted
isSelected && wasBlockJustInserted
}
/>
</View>
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/video/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class VideoEdit extends Component {
icon={ this.getIcon( ICON_TYPE.PLACEHOLDER ) }
onFocus={ this.props.onFocus }
autoOpenMediaUpload={
isSelected && ! src && wasBlockJustInserted
isSelected && wasBlockJustInserted
jd-alexander marked this conversation as resolved.
Show resolved Hide resolved
}
/>
</View>
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ For each user feature we should also add a importance categorization label to i

- [*] Image block: Add a "featured" banner. (Android only) [#30806]
- [**] The media upload options of the Image, Video and Gallery block automatically opens when the respective block is inserted. [#29546]
- [**] The media upload options of the File and Audio block automatically opens when the respective block is inserted. [#31025]



## 1.51.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { isAndroid } from './helpers/utils';
describe( 'Gutenberg Editor Audio Block tests', () => {
it( 'should be able to add an audio block', async () => {
await editorPage.addNewBlock( blockNames.audio );

await editorPage.driver.sleep( 1000 );
await editorPage.closePicker();

const block = await editorPage.getFirstBlockVisible();
await expect( block ).toBeTruthy();
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { isAndroid } from './helpers/utils';
describe( 'Gutenberg Editor File Block tests', () => {
it( 'should be able to add a file block', async () => {
await editorPage.addNewBlock( blockNames.file );

await editorPage.driver.sleep( 1000 );
await editorPage.closePicker();

const block = await editorPage.getFirstBlockVisible();
await expect( block ).toBeTruthy();
} );
Expand Down