-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[Mobile] Fix crash when appending media (Android) #56791
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f3f6c4c
Mobile - Fix subscribeMediaAppend to skip adding unsupported types of…
a32186a
Mock requestMediaImport
70be200
Mobile - Edit Post tests - Remove old unsupported block test and adds…
4dc14c1
Merge branch 'trunk' into fix/append-unsupported-media
6b90b4b
Update Changelog
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
packages/edit-post/src/test/__snapshots__/editor.native.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Editor appends media correctly for allowed types 1`] = ` | ||
"<!-- wp:image --> | ||
<figure class="wp-block-image"><img src="https://test-site.files.wordpress.com/local-image-1.jpeg" alt=""/></figure> | ||
<!-- /wp:image --> | ||
|
||
<!-- wp:image --> | ||
<figure class="wp-block-image"><img src="https://test-site.files.wordpress.com/local-image-3.jpeg" alt=""/></figure> | ||
<!-- /wp:image -->" | ||
`; | ||
|
||
exports[`Editor appends media correctly for allowed types and skips unsupported ones 1`] = ` | ||
"<!-- wp:image --> | ||
<figure class="wp-block-image"><img src="https://test-site.files.wordpress.com/local-image-1.jpeg" alt=""/></figure> | ||
<!-- /wp:image --> | ||
|
||
<!-- wp:video --> | ||
<figure class="wp-block-video"><video controls src="file:///local-video-4.mp4"></video></figure> | ||
<!-- /wp:video -->" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import { | |
parse, | ||
serialize, | ||
getUnregisteredTypeHandlerName, | ||
getBlockType, | ||
createBlock, | ||
} from '@wordpress/blocks'; | ||
import { withDispatch, withSelect } from '@wordpress/data'; | ||
|
@@ -35,6 +36,7 @@ import { applyFilters } from '@wordpress/hooks'; | |
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
import { getGlobalStyles, getColorsAndGradients } from '@wordpress/components'; | ||
import { NEW_BLOCK_TYPES } from '@wordpress/block-library'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
const postTypeEntities = [ | ||
{ name: 'post', baseURL: '/wp/v2/posts' }, | ||
|
@@ -94,6 +96,7 @@ class NativeEditorProvider extends Component { | |
componentDidMount() { | ||
const { | ||
capabilities, | ||
createErrorNotice, | ||
locale, | ||
hostAppNamespace, | ||
updateEditorSettings, | ||
|
@@ -136,17 +139,26 @@ class NativeEditorProvider extends Component { | |
this.subscriptionParentMediaAppend = subscribeMediaAppend( | ||
( payload ) => { | ||
const blockName = 'core/' + payload.mediaType; | ||
const newBlock = createBlock( blockName, { | ||
id: payload.mediaId, | ||
[ payload.mediaType === 'image' ? 'url' : 'src' ]: | ||
payload.mediaUrl, | ||
} ); | ||
|
||
const indexAfterSelected = this.props.selectedBlockIndex + 1; | ||
const insertionIndex = | ||
indexAfterSelected || this.props.blockCount; | ||
|
||
this.props.insertBlock( newBlock, insertionIndex ); | ||
const blockType = getBlockType( blockName ); | ||
|
||
if ( blockType && blockType?.name ) { | ||
const newBlock = createBlock( blockType.name, { | ||
id: payload.mediaId, | ||
[ payload.mediaType === 'image' ? 'url' : 'src' ]: | ||
payload.mediaUrl, | ||
} ); | ||
|
||
const indexAfterSelected = | ||
this.props.selectedBlockIndex + 1; | ||
const insertionIndex = | ||
indexAfterSelected || this.props.blockCount; | ||
|
||
this.props.insertBlock( newBlock, insertionIndex ); | ||
} else { | ||
createErrorNotice( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will serve as a fallback, a few changes were done in wordpress-mobile/WordPress-Android#19754 to prevent passing unsupported files when sharing files to the editor. |
||
__( 'File type not supported as a media file.' ) | ||
); | ||
} | ||
} | ||
); | ||
|
||
|
@@ -389,14 +401,16 @@ const ComposedNativeProvider = compose( [ | |
dispatch( blockEditorStore ); | ||
const { switchEditorMode } = dispatch( editPostStore ); | ||
const { addEntities, receiveEntityRecords } = dispatch( coreStore ); | ||
const { createSuccessNotice } = dispatch( noticesStore ); | ||
const { createSuccessNotice, createErrorNotice } = | ||
dispatch( noticesStore ); | ||
|
||
return { | ||
updateBlockEditorSettings: updateSettings, | ||
updateEditorSettings, | ||
addEntities, | ||
insertBlock, | ||
createSuccessNotice, | ||
createErrorNotice, | ||
editTitle( title ) { | ||
editPost( { title } ); | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed this test because we have others that cover the Unsupported blocks functionality