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] Audio block capability now enables/disables media upload's media sources #31966

Merged
merged 72 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
0519567
Basics of Audio block working
etoledom Dec 1, 2020
690224d
Add audio support to MediaUpload
etoledom Dec 1, 2020
b7965fd
Add handling of file uploads and replace
etoledom Dec 1, 2020
f2ccb18
WPMediaLibrary support for Audio block
etoledom Dec 1, 2020
2a02b83
Avoid removing media info on error state
etoledom Dec 1, 2020
276b07d
Linting
etoledom Dec 1, 2020
8a8b550
Added an AUDIO file to the test requestMediaPickFromMediaLibrary func
jd-alexander Dec 9, 2020
9e03e63
Fixed typo in ToolbarButton of Audio Block.
jd-alexander Dec 9, 2020
349aa19
Removed auto help behavior present on web that's not used on mobile.
jd-alexander Dec 9, 2020
04a39b4
Merge branch 'master' into rnmobile/audio-block-I-b
jd-alexander Dec 9, 2020
32029e0
[Android] Wired the click of the Audio Media Library button.
jd-alexander Dec 16, 2020
a18b8ac
Added Audio media options for choosing audio file locally.
jd-alexander Dec 16, 2020
af6cb99
[RNMobile] Audio Block: Proper caption field (#27689)
ceyhun Dec 17, 2020
193339f
Add alert prompt to insert from URL
ceyhun Dec 18, 2020
4ab2988
Set entered URL in audio block attributes
ceyhun Dec 18, 2020
d9a6041
Merge branch 'master' into rnmobile/audio-block-I-b
jd-alexander Jan 7, 2021
1a46994
Merge branch 'master' into rnmobile/audio-block-I-b
jd-alexander Jan 14, 2021
f09c955
Merge branch 'master' into rnmobile/audio-block-I-b
jd-alexander Jan 18, 2021
fff09be
initial integration with react native prompt.
jd-alexander Jan 20, 2021
d4209e8
updated prompt lib.
jd-alexander Jan 20, 2021
9d61d49
Merge branch 'rnmobile/audio-block-I-b' into rnmobile/audio-block-IV-…
jd-alexander Jan 20, 2021
f0a1034
updated commit hash of prompt lib.
jd-alexander Jan 20, 2021
1eb58d2
Updated package-lock.json.
jd-alexander Jan 20, 2021
17dea27
Added RNPromptPackage to Glue Code.
jd-alexander Jan 20, 2021
c7154d3
Merge branch 'master' into rnmobile/audio-block-IV-from-url
jd-alexander Feb 18, 2021
0f597f3
fixed merge conflicts between the edit.native.js files of the branches
jd-alexander Feb 18, 2021
e4dec03
added onSelectURL to the media-upload component
jd-alexander Feb 20, 2021
f77a861
added onSelectURL to the media-placeholder
jd-alexander Feb 20, 2021
cad8e8a
updated onSelectURL support with notice and URL validation
jd-alexander Feb 20, 2021
ef478bb
sync package-lock.json
jd-alexander Feb 20, 2021
ee9a536
Merge remote-tracking branch 'origin/master' into rnmobile/audio-bloc…
jd-alexander Feb 23, 2021
6b6221f
updated package-lock.json
jd-alexander Feb 23, 2021
377ceae
updated package-lock.json
jd-alexander Feb 23, 2021
01242f5
Merge branch 'trunk' into rnmobile/audio-block-IV-from-url
jd-alexander Apr 7, 2021
5911b09
updated react-native-prompt-android setup due to binary dep changes.
jd-alexander Apr 7, 2021
cebdf5f
sync package-lock.json
jd-alexander Apr 7, 2021
2dd3b6c
Integrated RNPromptPackage with the glue code.
jd-alexander Apr 7, 2021
f348df3
sync package-lock.json
jd-alexander Apr 7, 2021
b81dd77
package-lock.json fix
jd-alexander Apr 7, 2021
d4ad088
sync package-lock.json
jd-alexander Apr 8, 2021
754b999
Added the globe icon to the Insert from URL source.Only shown on Android
jd-alexander Apr 8, 2021
e7ab21b
Extract filename from all URL types and optimized extension logic.
jd-alexander Apr 20, 2021
1834b58
Merge branch 'trunk' into rnmobile/audio-block-IV-from-url
jd-alexander Apr 20, 2021
614d57b
Merge branch 'trunk' into rnmobile/audio-block-IV-from-url
jd-alexander Apr 29, 2021
6170600
Merge branch 'trunk' into rnmobile/audio-block-IV-from-url
jd-alexander May 13, 2021
5acc1f2
Removed hook that would show/hide the audio block. It is not needed.
jd-alexander May 19, 2021
b5dac20
Only show the Insert from URL option when the audio block cap is false
jd-alexander May 19, 2021
4d5b001
Added changelog entry for the Audio block URL prompt on free sites
jd-alexander May 19, 2021
51494e3
Removed exclamation mark.
jd-alexander May 19, 2021
1e550e6
Merge branch 'trunk' into rnmobile/audio-block-IV-from-url
jd-alexander May 19, 2021
e68550e
Reduced onPress -> onSelectURL logic since the parameters match.
jd-alexander May 19, 2021
024ecad
Added entry to CHANGELOG.md
jd-alexander May 19, 2021
2d1414b
Merge branch 'rnmobile/audio-block-IV-from-url' into rnmobile/add/aud…
jd-alexander May 19, 2021
0e8db0f
simplified isAudioBlockEnabled's usage of getSettings.
jd-alexander May 19, 2021
ac6565a
exported the Insert from URL option so that the test can be utilize it.
jd-alexander May 20, 2021
ace7cc5
Added test that verifies the Insert From URL option with the audio type
jd-alexander May 20, 2021
0153578
isAudioBlockMediaUploadEnabled now represents the Audio block capability
jd-alexander May 21, 2021
cec0331
placed the audio block capability in a single filter callback function
jd-alexander May 21, 2021
6dec79a
Merge branch 'trunk' into rnmobile/add/audio-block-capability
jd-alexander May 21, 2021
8010194
Added release notes entry under unreleased.
jd-alexander May 21, 2021
39f1bf9
Merge branch 'trunk' into rnmobile/add/audio-block-capability
jd-alexander May 22, 2021
9cb564e
Merge branch 'trunk' into rnmobile/add/audio-block-capability
jd-alexander May 26, 2021
245a895
added logic that verifies that the source being enabled supports audio
jd-alexander May 27, 2021
f4aa392
formatted code changes.
jd-alexander May 27, 2021
d9a5da1
Merge branch 'trunk' into rnmobile/add/audio-block-capability
jd-alexander May 27, 2021
e94abc3
Changed the order of the props to match the order throughout the file.
jd-alexander May 27, 2021
7d0ad16
Fixed order of ios capabilities
jd-alexander May 27, 2021
11a79e7
Fix indent issues on Gutenberg props
fluiddot May 31, 2021
d382a9b
Merge branch 'trunk' into rnmobile/add/audio-block-capability
fluiddot Jun 1, 2021
b40012e
Merge branch 'trunk' into rnmobile/add/audio-block-capability
fluiddot Jun 3, 2021
8422815
Merge branch 'trunk' into rnmobile/add/audio-block-capability
fluiddot Jun 3, 2021
1ca8ae2
Merge branch 'trunk' into rnmobile/add/audio-block-capability
fluiddot Jun 3, 2021
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
42 changes: 33 additions & 9 deletions packages/block-editor/src/components/media-upload/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import {
mobile,
globe,
} from '@wordpress/icons';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { compose } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';

export const MEDIA_TYPE_IMAGE = 'image';
export const MEDIA_TYPE_VIDEO = 'video';
Expand All @@ -35,6 +38,9 @@ export const MEDIA_TYPE_ANY = 'any';
export const OPTION_TAKE_VIDEO = __( 'Take a Video' );
export const OPTION_TAKE_PHOTO = __( 'Take a Photo' );
export const OPTION_TAKE_PHOTO_OR_VIDEO = __( 'Take a Photo or Video' );
export const OPTION_INSERT_FROM_URL = __( 'Insert from URL' );

const URL_MEDIA_SOURCE = 'URL';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mediaSources being used throughout this component lives within the bridge. I opted not to put this there since inserting from the URL is not bridge-related.


const PICKER_OPENING_DELAY = 200;

Expand Down Expand Up @@ -115,8 +121,8 @@ export class MediaUpload extends Component {
};

const urlSource = {
id: 'URL',
value: 'URL',
id: URL_MEDIA_SOURCE,
value: URL_MEDIA_SOURCE,
label: __( 'Insert from URL' ),
types: [ MEDIA_TYPE_AUDIO ],
icon: globe,
Expand All @@ -137,15 +143,25 @@ export class MediaUpload extends Component {
const {
allowedTypes = [],
__experimentalOnlyMediaLibrary,
isAudioBlockMediaUploadEnabled,
} = this.props;

return this.getAllSources()
.filter( ( source ) => {
return __experimentalOnlyMediaLibrary
? source.mediaLibrary
: allowedTypes.some( ( allowedType ) =>
source.types.includes( allowedType )
);
if ( __experimentalOnlyMediaLibrary ) {
return source.mediaLibrary;
} else if (
allowedTypes.every(
( allowedType ) => allowedType === MEDIA_TYPE_AUDIO
) &&
source.id !== URL_MEDIA_SOURCE
) {
return isAudioBlockMediaUploadEnabled === true;
}

return allowedTypes.some( ( allowedType ) =>
source.types.includes( allowedType )
);
} )
.map( ( source ) => {
return {
Expand Down Expand Up @@ -185,7 +201,7 @@ export class MediaUpload extends Component {
multiple = false,
} = this.props;

if ( value === 'URL' ) {
if ( value === URL_MEDIA_SOURCE ) {
prompt(
SiobhyB marked this conversation as resolved.
Show resolved Hide resolved
__( 'Type a URL' ), // title
undefined, // message
Expand Down Expand Up @@ -286,4 +302,12 @@ export class MediaUpload extends Component {
}
}

export default MediaUpload;
export default compose( [
withSelect( ( select ) => {
return {
isAudioBlockMediaUploadEnabled:
select( blockEditorStore ).getSettings( 'capabilities' )
.isAudioBlockMediaUploadEnabled === true,
};
} ),
] )( MediaUpload );
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import {
MediaUpload,
MEDIA_TYPE_IMAGE,
MEDIA_TYPE_VIDEO,
MEDIA_TYPE_AUDIO,
OPTION_TAKE_VIDEO,
OPTION_TAKE_PHOTO,
OPTION_INSERT_FROM_URL,
} from '../index';

const MEDIA_URL = 'http://host.media.type';
Expand Down Expand Up @@ -73,6 +75,7 @@ describe( 'MediaUpload component', () => {
};
expectOptionForMediaType( MEDIA_TYPE_IMAGE, OPTION_TAKE_PHOTO );
expectOptionForMediaType( MEDIA_TYPE_VIDEO, OPTION_TAKE_VIDEO );
expectOptionForMediaType( MEDIA_TYPE_AUDIO, OPTION_INSERT_FROM_URL );
} );

const expectMediaPickerForOption = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class GutenbergProps @JvmOverloads constructor(
val enableXPosts: Boolean,
val enableUnsupportedBlockEditor: Boolean,
val canEnableUnsupportedBlockEditor: Boolean,
val enableAudioBlock: Boolean,
val isAudioBlockMediaUploadEnabled: Boolean,
val enableReusableBlock: Boolean,
val localeSlug: String,
val postType: String,
Expand Down Expand Up @@ -45,8 +45,8 @@ data class GutenbergProps @JvmOverloads constructor(
putBoolean(PROP_CAPABILITIES_MEDIAFILES_COLLECTION_BLOCK, enableMediaFilesCollectionBlocks)
putBoolean(PROP_CAPABILITIES_UNSUPPORTED_BLOCK_EDITOR, enableUnsupportedBlockEditor)
putBoolean(PROP_CAPABILITIES_CAN_ENABLE_UNSUPPORTED_BLOCK_EDITOR, canEnableUnsupportedBlockEditor)
putBoolean(PROP_CAPABILITIES_AUDIO_BLOCK, enableAudioBlock)
putBoolean(PROP_CAPABILITIES_REUSABLE_BLOCK, enableReusableBlock)
putBoolean(PROP_CAPABILITIES_IS_AUDIO_BLOCK_MEDIA_UPLOAD_ENABLED, isAudioBlockMediaUploadEnabled)
jd-alexander marked this conversation as resolved.
Show resolved Hide resolved
putBoolean(PROP_CAPABILITIES_CAN_VIEW_EDITOR_ONBOARDING, canViewEditorOnboarding)
}

Expand Down Expand Up @@ -75,8 +75,8 @@ data class GutenbergProps @JvmOverloads constructor(
const val PROP_CAPABILITIES_XPOSTS = "xposts"
const val PROP_CAPABILITIES_UNSUPPORTED_BLOCK_EDITOR = "unsupportedBlockEditor"
const val PROP_CAPABILITIES_CAN_ENABLE_UNSUPPORTED_BLOCK_EDITOR = "canEnableUnsupportedBlockEditor"
const val PROP_CAPABILITIES_AUDIO_BLOCK = "audioBlock"
const val PROP_CAPABILITIES_REUSABLE_BLOCK = "reusableBlock"
const val PROP_CAPABILITIES_IS_AUDIO_BLOCK_MEDIA_UPLOAD_ENABLED = "isAudioBlockMediaUploadEnabled"
const val PROP_CAPABILITIES_CAN_VIEW_EDITOR_ONBOARDING = "canViewEditorOnboarding"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public enum Capabilities: String {
case xposts
case unsupportedBlockEditor
case canEnableUnsupportedBlockEditor
case audioBlock
case reusableBlock
case isAudioBlockMediaUploadEnabled
case canViewEditorOnboarding
}

Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For each user feature we should also add a importance categorization label to i
- [*] Fix missing title for some unsupported blocks [#31743]
- [*] The BottomSheet Cell component now supports the help prop so that a hint can be supplied to all Cell based components. [#30885]
- [***] Enable reusable block only in WP.com sites [#31744]
- [***] Audio block now available on WP.com sites on the free plan. [#31966]

## 1.53.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected Bundle getLaunchOptions() {
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_MENTIONS, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_XPOSTS, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_UNSUPPORTED_BLOCK_EDITOR, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_AUDIO_BLOCK, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_REUSABLE_BLOCK, false);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_IS_AUDIO_BLOCK_MEDIA_UPLOAD_ENABLED, true);
capabilities.putBoolean(GutenbergProps.PROP_CAPABILITIES_CAN_VIEW_EDITOR_ONBOARDING, false);
bundle.putBundle(GutenbergProps.PROP_CAPABILITIES, capabilities);
return bundle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
.unsupportedBlockEditor: unsupportedBlockEnabled,
.canEnableUnsupportedBlockEditor: unsupportedBlockCanBeActivated,
.mediaFilesCollectionBlock: true,
.audioBlock: true,
.reusableBlock: false,
.isAudioBlockMediaUploadEnabled: true,
.canViewEditorOnboarding: false
]
}
Expand Down
16 changes: 0 additions & 16 deletions packages/react-native-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
validateThemeColors,
validateThemeGradients,
} from '@wordpress/block-editor';
import { dispatch } from '@wordpress/data';
import { unregisterBlockType } from '@wordpress/blocks';

const reactNativeSetup = () => {
Expand Down Expand Up @@ -107,21 +106,6 @@ const setupInitHooks = () => {
};
}
);

wpHooks.addAction(
'native.render',
'core/react-native-editor',
( props ) => {
const isAudioBlockEnabled =
props.capabilities && props.capabilities.audioBlock;

if ( isAudioBlockEnabled === true ) {
dispatch( 'core/edit-post' ).showBlockTypes( [ 'core/audio' ] );
} else {
dispatch( 'core/edit-post' ).hideBlockTypes( [ 'core/audio' ] );
}
}
);
};

let blocksRegistered = false;
Expand Down