-
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
[RNMobile] Simplify media insertion flow - Part 3 component integration #29548
Changes from all commits
5c44900
2333337
c10bc3f
4c286e5
1d445b7
dd7859f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ import { __, sprintf } from '@wordpress/i18n'; | |
import { getProtocol, hasQueryArg } from '@wordpress/url'; | ||
import { doAction, hasAction } from '@wordpress/hooks'; | ||
import { compose, withPreferredColorScheme } from '@wordpress/compose'; | ||
import { withSelect } from '@wordpress/data'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { | ||
image as placeholderIcon, | ||
textColor, | ||
|
@@ -399,7 +399,13 @@ export class ImageEdit extends Component { | |
|
||
render() { | ||
const { isCaptionSelected } = this.state; | ||
const { attributes, isSelected, image, clientId } = this.props; | ||
const { | ||
attributes, | ||
isSelected, | ||
image, | ||
clientId, | ||
wasBlockJustInserted, | ||
} = this.props; | ||
const { align, url, alt, id, sizeSlug, className } = attributes; | ||
|
||
const sizeOptionsValid = find( this.sizeOptions, [ | ||
|
@@ -461,6 +467,9 @@ export class ImageEdit extends Component { | |
onSelect={ this.onSelectMediaUploadOption } | ||
icon={ this.getPlaceholderIcon() } | ||
onFocus={ this.props.onFocus } | ||
autoOpenMediaUpload={ | ||
isSelected && ! url && wasBlockJustInserted() | ||
} | ||
/> | ||
</View> | ||
); | ||
|
@@ -579,5 +588,21 @@ export default compose( [ | |
imageSizes, | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, { clientId }, { select } ) => { | ||
return { | ||
wasBlockJustInserted() { | ||
const { clearLastBlockInserted } = dispatch( 'core/editor' ); | ||
const { wasBlockJustInserted } = select( 'core/editor' ); | ||
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. I am getting a warning about using the string literals to access the data store. I haven't seen a store definition for 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. I just found the PR that replaced store names and I saw that the 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. 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. I didn't see this error pop up for me so you probably have it fixed now. This sounds similar to an issue solved in this PR where a setting was removed that the mobile side counted on. |
||
|
||
const result = wasBlockJustInserted( clientId ); | ||
|
||
if ( result ) { | ||
clearLastBlockInserted(); | ||
return true; | ||
} | ||
return false; | ||
}, | ||
}; | ||
} ), | ||
withPreferredColorScheme, | ||
] )( ImageEdit ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ import { blockNames } from './pages/editor-page'; | |
describe( 'Gutenberg Editor Gallery Block tests', () => { | ||
it( 'should be able to add a gallery block', async () => { | ||
await editorPage.addNewBlock( blockNames.gallery ); | ||
await editorPage.driver.sleep( 1000 ); | ||
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 delay and the one below ensures the picker has been opened before attempting to close it. |
||
await editorPage.closePicker(); | ||
|
||
const galleryBlock = await editorPage.getBlockAtPosition( | ||
blockNames.gallery | ||
); | ||
|
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 repeated this
withDispatch
logic in three places. I am not sure how to make this reusable hence the duplication. Instinctively, I thought of hooks but these are class components so they are incompatible and the nature of this PR is not to do this conversion for these components. Let me know if you have any thoughts on this.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 also wondered if this logic could somehow live within the store, but I wasn't sure about this either.
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 agree finding a way to reuse this would be a nice plus. I'd need to take time to play around with it to make a suggestion though as I've been out of the RN side for a little while now.