-
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
[RNMobile] Simplify media insertion flow - Part 3 component integration #29548
Conversation
withDispatch( ( dispatch, { clientId }, { select } ) => { | ||
return { | ||
wasBlockJustInserted() { | ||
const { clearLastBlockInserted } = dispatch( 'core/editor' ); | ||
const { wasBlockJustInserted } = select( 'core/editor' ); | ||
|
||
const result = wasBlockJustInserted( clientId ); | ||
|
||
if ( result ) { | ||
clearLastBlockInserted(); | ||
return true; | ||
} | ||
return false; | ||
}, | ||
}; | ||
} ), |
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.
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 comment
The 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 core-editor
in other parts of the codebase as yet.
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 just found the PR that replaced store names and I saw that the core/editor
is now editorStore
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.
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 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.
Size Change: +89 B (0%) Total Size: 1.4 MB
ℹ️ View Unchanged
|
@@ -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 comment
The 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.
…to rnmobile/simplify_image_insertion_flow-component-integration
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.
Nice work @jd-alexander! Tested this out on iOS and Android using the demo apps and everything works as expected. I agree with your comment to reuse the withDispatch
changes but I've been away from RN so I didn't have a good suggestion there yet.
One other thought, I wonder if we should auto-open on File
and Audio
as well. WDYT?
withDispatch( ( dispatch, { clientId }, { select } ) => { | ||
return { | ||
wasBlockJustInserted() { | ||
const { clearLastBlockInserted } = dispatch( 'core/editor' ); | ||
const { wasBlockJustInserted } = select( 'core/editor' ); | ||
|
||
const result = wasBlockJustInserted( clientId ); | ||
|
||
if ( result ) { | ||
clearLastBlockInserted(); | ||
return true; | ||
} | ||
return false; | ||
}, | ||
}; | ||
} ), |
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.
Thanks for the review 🙇🏾
Good point, I think it would make sense to open them as well. I am going to create another PR with that implementation once these have been finalized and merged in. |
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.
Good point, I think it would make sense to open them as well. I am going to create another PR with that implementation once these have been finalized and merged in.
This sounds like a good plan to me 👍
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.
Tested on iOS and Android and things are looking good!
The demo app on Android doesn't allow inserting images from the device, so it's hard to test the full user flow here, but I think we're good.
…to rnmobile/simplify_image_insertion_flow-component-integration
Thanks much for all the reviews and comments @guarani 🙇🏾 . I have synced all branches with trunk and I will be resolving the test issues and merging. A label in the e2e test says "Dismiss" instead of "Cancel" so I will update that. |
232a0cd
into
rnmobile/simplify_image_insertion_flow-media-upload
* added autoOpenMediaUpload prop to the MediaPlaceholder * Added the auto-opening capabilities to the MediaUpload component. * Added documentation for the new autoOpenMediaUpload prop * renamed autoOpenMediaUpload to autoOpen in the MediaUpload component. * [RNMobile] Simplify media insertion flow - Part 3 component integration (#29548) * Track the clientId of the block that is inserted. * implemented auto opening utilizing last block inserted from the store * added dismissal support for the auto opening picker to the UI tests. * Updated Dismiss button in closePicker function to Cancel
* created actions for adding and clearing last inserted block event. * added reducer for determining new state based on the action * added selector to query the state for the last block inserted * [RNMobile] Simplify media insertion flow Part 2 - media upload (#29547) * added autoOpenMediaUpload prop to the MediaPlaceholder * Added the auto-opening capabilities to the MediaUpload component. * Added documentation for the new autoOpenMediaUpload prop * renamed autoOpenMediaUpload to autoOpen in the MediaUpload component. * [RNMobile] Simplify media insertion flow - Part 3 component integration (#29548) * Track the clientId of the block that is inserted. * implemented auto opening utilizing last block inserted from the store * added dismissal support for the auto opening picker to the UI tests. * Updated Dismiss button in closePicker function to Cancel * Added release notes for auto-opening. * [RNMobile] Refactor simplify media flow redux store changes (#30123) * Moved the last block inserted actions from editor to the block-editor * Moved the last block inserted reducer from editor to the block-editor * Moved the last block inserted selector from editor to the block-editor * Fixed es-lint error. * Moved last block inserted actions test from editor to the block-editor * Moved last block inserted reducer test from editor to the block-editor * Moved last block inserted selector test from editor to the block-editor * Moved all calls to last block inserted from editor to block-editor * last block inserter usage in menu native migrated : editor to block-editor * [RNMobile] Refactor: Simplify media flow redux migration (#30238) * Add meta argument to insertBlock action * Add inserter menu source * Update last block inserted reducer Instead of using specific actions for tracking the last block inserted, it uses the actions related to the insertion flow. * Add get last block inserted selector * Refactor gallery edit component withSelect and withDispatch logic has been refactored to use useSelect and useDispatch hooks * Refactor image edit component wasBlockJustInserted is now calculated with getLastBlockInserted * Refactor video edit component wasBlockJustInserted is now calculated with getLastBlockInserted * Fix reset blocks action in last block inserted reducer * Add source param to wasBlockJustInserted selector * Simplify withSelect part of video block * Removed add/clear last block inserted actions and tests due to refactor * Removed addLastBlockInserted from the insert menu's onPress. * rewrote the tests for the lastBlockInserted reducer. * rewrote tests for wasBlockJustInserted selector. * optimized clientId * removed unneeded clientId. * put the expectedSource inside the test meta object. * used expectedState insted {} for state related tests. * used expectedState instead {} for state related tests. * removed parentheses from describe name. * return the same state instead of empty state. * made changes to test name so its intent is clearer. * made the insertion source optional. Co-authored-by: Carlos Garcia <fluiddot@gmail.com> * added wasBlockJustInserted prop needed after merge with trunk. * removed updateSelection from reducer so it's updated at all times. Co-authored-by: Carlos Garcia <fluiddot@gmail.com>
gutenberg-mobile
PR wordpress-mobile/gutenberg-mobile#2700Builds on top of #29547 - Do not merge until this PR has been merged and the base branch is updated to
trunk
.Description
This change simplifies the media insertion flow by showing the media options sheet when you tap
Image
,Video
orGallery
to add the media placeholder to the canvas. Before you would have to add the media placeholder and clickAdd Image / Video / Media
for it to be shown after insertion.Testing
Image
Video
Gallery
Regression Testing
Checklist: