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

Mobile media files block #25242

Closed
wants to merge 27 commits into from
Closed

Mobile media files block #25242

wants to merge 27 commits into from

Conversation

mzorz
Copy link
Contributor

@mzorz mzorz commented Sep 11, 2020

Description

This PR adds bridge support for the jetpack Story block in mobile gutenberg
Related Jetpack PR: Automattic/jetpack#17140
Related Gutenberg-mobile PR: wordpress-mobile/gutenberg-mobile#2611
Related WPAndroid PR: wordpress-mobile/WordPress-Android#12939

How has this been tested?

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@mzorz mzorz added [Type] Enhancement A suggestion for improvement. Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) labels Sep 11, 2020
@github-actions
Copy link

github-actions bot commented Sep 11, 2020

Size Change: 0 B

Total Size: 1.21 MB

ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.78 kB 0 B
build/api-fetch/index.js 3.45 kB 0 B
build/autop/index.js 2.84 kB 0 B
build/blob/index.js 665 B 0 B
build/block-directory/index.js 8.72 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/index.js 131 kB 0 B
build/block-editor/style-rtl.css 11.1 kB 0 B
build/block-editor/style.css 11.1 kB 0 B
build/block-library/editor-rtl.css 9.06 kB 0 B
build/block-library/editor.css 9.06 kB 0 B
build/block-library/index.js 146 kB 0 B
build/block-library/style-rtl.css 7.9 kB 0 B
build/block-library/style.css 7.9 kB 0 B
build/block-library/theme-rtl.css 837 B 0 B
build/block-library/theme.css 838 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/index.js 172 kB 0 B
build/components/style-rtl.css 15.2 kB 0 B
build/components/style.css 15.2 kB 0 B
build/compose/index.js 9.81 kB 0 B
build/core-data/index.js 12.5 kB 0 B
build/data-controls/index.js 772 B 0 B
build/data/index.js 8.77 kB 0 B
build/date/index.js 31.8 kB 0 B
build/deprecated/index.js 768 B 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.46 kB 0 B
build/edit-navigation/index.js 11.2 kB 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.41 kB 0 B
build/edit-post/style.css 6.39 kB 0 B
build/edit-site/index.js 22.4 kB 0 B
build/edit-site/style-rtl.css 3.88 kB 0 B
build/edit-site/style.css 3.88 kB 0 B
build/edit-widgets/index.js 26.3 kB 0 B
build/edit-widgets/style-rtl.css 3.13 kB 0 B
build/edit-widgets/style.css 3.13 kB 0 B
build/editor/editor-styles-rtl.css 480 B 0 B
build/editor/editor-styles.css 482 B 0 B
build/editor/index.js 43.1 kB 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.85 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 7.7 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.16 kB 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 712 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.11 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.34 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.42 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 791 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/reusable-blocks/index.js 3.06 kB 0 B
build/rich-text/index.js 13.2 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.69 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.84 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@mzorz mzorz mentioned this pull request Oct 1, 2020
6 tasks
@mzorz mzorz requested review from guarani and etoledom October 2, 2020 02:47
@mzorz mzorz marked this pull request as ready for review October 2, 2020 02:50
Comment on lines 243 to 248
export function requestStoryCreatorLoad( mediaFiles, blockClientId ) {
return RNReactNativeGutenbergBridge.requestStoryCreatorLoad(
mediaFiles,
blockClientId
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Stories are a WPCom-only feature, right?
If this is the case, it might not be good to reference it directly.

It might be better to have a more generic bridge method that could be used by the Story block or eventually other blocks with similar behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be better to have a more generic bridge method that could be used by the Story block or eventually other blocks with similar behavior.

Excellent idea, here are the PRs tackling that (made them on top of the second part PRs to make the changes clearer)

Gutenberg: #26005
Jetpack: Automattic/jetpack#17456
Gutenberg mobile: wordpress-mobile/gutenberg-mobile#2706
WPAndroid: wordpress-mobile/WordPress-Android#13101

mzorz and others added 3 commits October 8, 2020 20:57
* added mobile StoryUpdateProgress component and bridge code to send/receive save progress

* updated WPAndroid bridge DeferredEventEmitter to handle Story save events separately

* changed all Save event interface methods to use String ids instead of int, and removed serverMediaId params as these don't apply while saving locally

* redefined upload/save state constants

* added onStorySaveResult handling to bridge, and renamed STORY_SAVE_STATE_* events to MEDIA_SAVE_STATE_* where appropriate

* checking for matches of mediaId in  mediaFiles while saving to send save progress updates

* added mediaModelCreated() method to the bridge, so a new ID can be assigned to a mediaFile in a Story block

* mediaId should always be a string in mediaFiles so, converting to avoid strict comparison to fail

* removed commented code

* updated documentation

* added missing implementation of method storySaveSync() in demo app

* fixed prettier warning

* Update packages/block-editor/src/components/story-update-progress/README.md

Co-authored-by: Joel Dean <[email protected]>

* Update packages/block-editor/src/components/story-update-progress/README.md

Co-authored-by: Joel Dean <[email protected]>

* Mobile Stories block (part3: refactor / rename) (#26005)

* renames for generic media files collection block and BlockMediaUpdateProgres

* referencing the right props method in finishMediaSaveWithFailure

* mistaken renames of  parameters in bridge methods

* renamed more abstract/generic method names requestMediaFilesEditorLoad

* removed extra whtie space

* renamed argument type

Co-authored-by: Joel Dean <[email protected]>
Copy link
Contributor

@guarani guarani left a comment

Choose a reason for hiding this comment

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

Hi @mzorz! 👋

I was reviewing Automattic/jetpack#17140 and had some questions, mostly about BlockMediaUpdateProgress and related methods, so I thought I'd comment here.

  1. These seems to two concepts, namely upload and save. Each has very similar methods (state reset, success, failure, progress) and I think the upload refers to the media upload itself while the save is a separate operation after uploading (please correct me if I'm wrong). Is there any room for unifying these two concepts into one, or reducing in some way the number of methods (currently eight main ones)?
  2. From its name, requestMediaFilesEditorLoad, it's not too clear to me what this native method does
  3. What does it mean for media to be reset, i.e. mediaUploadStateReset — is that when the user cancels a media upload? Reset seems to imply (to me) that the upload will start again, but I'm not too clear on this.

@mzorz
Copy link
Contributor Author

mzorz commented Oct 15, 2020

I was reviewing Automattic/jetpack#17140 and had some questions, mostly about BlockMediaUpdateProgress and related methods, so I thought I'd comment here.

  1. These seems to two concepts, namely upload and save. Each has very similar methods (state reset, success, failure, progress) and I think the upload refers to the media upload itself while the save is a separate operation after uploading (please correct me if I'm wrong). Is there any room for unifying these two concepts into one, or reducing in some way the number of methods (currently eight main ones)?

Saving happens before uploading. Unifying is something that has come up very recently and the idea is to eventually (in a later PR) replace the MediaUploadProgress component with this more general one. The key difference is that this component is to be used on blocks that hold a collection of mediaFiles such as the Story block is. The case for MediaUploadProgress is designed only for uploads and only for 1 media item per block.

Saving and Uploading both need to show progress, and that's what this component is for, with the added feature that the underlying block knows about a mediaFiles collection (which could have just 1 item, which essentially the particular case for Video or Image blocks in the future).

Right now it is not our intention to refactor this and possibly break progress updates for very common blocks such as Video or Image blocks 😅 so, will leave them out of the project scope for now.

  1. From its name, requestMediaFilesEditorLoad, it's not too clear to me what this native method does

This originally was more descriptive but also very specific requestStoryCreatorLoad :). We decided to move away from specific .com naming and use a more abstract representation (see the origins of this on this very PR #25242 (comment)). To answer your question about clarity about what the method does: in essence, a Story block is a collection of media, and we could have other blocks doing that in the future. Whatever is a tool that can edit mediaFiles so these can be edited, saved, and re-uploaded then that's what the bridge is calling (knowing the block has mediaFiles, this is a request to load the tool that allows these media files to be edited, hence requestMediaFilesEditorLoad). For more about this, see this Gutenberg PR: #26005
and related PRs:
Jetpack: Automattic/jetpack#17456
Gutenberg mobile: wordpress-mobile/gutenberg-mobile#2706
WPAndroid: wordpress-mobile/WordPress-Android#13101

  1. What does it mean for media to be reset, i.e. mediaUploadStateReset — is that when the user cancels a media upload? Reset seems to imply (to me) that the upload will start again, but I'm not too clear on this.

This comes from MediaUploadProgress and has been here for a while. In that specific scenario (upload reset) it's used to clear the file selection on the media block and allow the user to tap on the block and trigger the media picker to set the media file again. In our particular case it's not used in the Story block component for now, but will be used when / if BlockMediaUpdateProgress effectively ends up replacing MediaUploadProgress at some point.

Let me know if any other doubt arises 👍

mzorz and others added 3 commits October 16, 2020 16:32
* added mobile StoryUpdateProgress component and bridge code to send/receive save progress

* updated WPAndroid bridge DeferredEventEmitter to handle Story save events separately

* changed all Save event interface methods to use String ids instead of int, and removed serverMediaId params as these don't apply while saving locally

* redefined upload/save state constants

* added onStorySaveResult handling to bridge, and renamed STORY_SAVE_STATE_* events to MEDIA_SAVE_STATE_* where appropriate

* checking for matches of mediaId in  mediaFiles while saving to send save progress updates

* added mediaModelCreated() method to the bridge, so a new ID can be assigned to a mediaFile in a Story block

* mediaId should always be a string in mediaFiles so, converting to avoid strict comparison to fail

* removed commented code

* updated documentation

* added missing implementation of method storySaveSync() in demo app

* fixed prettier warning

* renames for generic media files collection block and BlockMediaUpdateProgres

* referencing the right props method in finishMediaSaveWithFailure

* mistaken renames of  parameters in bridge methods

* renamed more abstract/generic method names requestMediaFilesEditorLoad

* removed extra whtie space

* renamed argument type

* renamed event paramter name to easier to understand 'success' boolean, matching the native counterpart

* added cancel and retry bridge methods specific for mediaFiles collection based blocks

* added requestMediaFilesSaveCancelDialog bridge method

* renamed bridge method mediaModelCreatedForFile for more general purpose mediaIdChanged

* Add missing iOS bridge declarations

* added jsdoc like description for methods

* removed unneeded return statement in some bridge methods

* Update packages/react-native-bridge/index.js

Co-authored-by: Joel Dean <[email protected]>

* Update packages/react-native-bridge/index.js

Co-authored-by: Joel Dean <[email protected]>

* Update packages/react-native-bridge/index.js

Co-authored-by: Joel Dean <[email protected]>

* fixed typo, added punctuation

Co-authored-by: eToledo <[email protected]>
Co-authored-by: Joel Dean <[email protected]>
mzorz added 4 commits October 23, 2020 11:35
…dle building (#26247)

* added mobile StoryUpdateProgress component and bridge code to send/receive save progress

* updated WPAndroid bridge DeferredEventEmitter to handle Story save events separately

* changed all Save event interface methods to use String ids instead of int, and removed serverMediaId params as these don't apply while saving locally

* redefined upload/save state constants

* added onStorySaveResult handling to bridge, and renamed STORY_SAVE_STATE_* events to MEDIA_SAVE_STATE_* where appropriate

* checking for matches of mediaId in  mediaFiles while saving to send save progress updates

* added mediaModelCreated() method to the bridge, so a new ID can be assigned to a mediaFile in a Story block

* mediaId should always be a string in mediaFiles so, converting to avoid strict comparison to fail

* removed commented code

* updated documentation

* added missing implementation of method storySaveSync() in demo app

* fixed prettier warning

* renames for generic media files collection block and BlockMediaUpdateProgres

* referencing the right props method in finishMediaSaveWithFailure

* mistaken renames of  parameters in bridge methods

* renamed more abstract/generic method names requestMediaFilesEditorLoad

* removed extra whtie space

* renamed argument type

* renamed event paramter name to easier to understand 'success' boolean, matching the native counterpart

* added cancel and retry bridge methods specific for mediaFiles collection based blocks

* added requestMediaFilesSaveCancelDialog bridge method

* renamed bridge method mediaModelCreatedForFile for more general purpose mediaIdChanged

* added jetpack node_modules folder to cleanup step in JSbundle building tasks
* adding upload progress tests on BLockMediaUpdateProgress component (mediaFiles collection)

* added save event tests for BlockMediaUpdateProgress component

* ids in mediaFiles array are always strings, fixed that

* updated function name passed by props

* fixed mediaFiles const passing for saving, using tempMediaFiles

* fixed state change for saveReset signal, was changing upload state instead

* fixed typo

* fixed using save state var

* changed to more descriptive test names

* removed commented line

* renamed vars to match bridge signal name
* hide Story block in non-DEV builds

* prettified

* passing enableStories feature flag in GutenbergProps and hiding block from picker if false

* added space

* renamed bridge GutenbergProps property to agnostic abstraction mediaFilesCollectionBlock

* renamed var on Capabilities enum

* removed stories specific block behavior
Comment on lines +182 to +184
export function mediaSaveSync() {
return RNReactNativeGutenbergBridge.mediaSaveSync();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add JDocs descriptions to this function too? 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 good idea, added in 08e77ba

Comment on lines +74 to +77
export function subscribeMediaSave( callback ) {
return gutenbergBridgeEvents.addListener( 'mediaSave', callback );
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Also here, could we add a description of how the MediaSave event should be used? (i.e, what parameters does it expect, etc...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 added in 08e77ba

@mzorz mzorz changed the title Mobile stories block Mobile media files block Nov 5, 2020
@mzorz
Copy link
Contributor Author

mzorz commented Nov 5, 2020

Closing this in favor of #26721

@mzorz mzorz closed this Nov 5, 2020
@mzorz mzorz deleted the try/jetpack-stories-block-mobile branch November 5, 2020 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants