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

Add a "Set as Featured Image" Button to Image Block #14052

Merged
merged 40 commits into from
Apr 20, 2021

Conversation

SiobhyB
Copy link
Contributor

@SiobhyB SiobhyB commented Feb 12, 2021

With this PR, we'll be implementing a "set as featured image" button with the purpose of making it easier for users to assign a new featured image directly from the post area.

Fixes wordpress-mobile/gutenberg-mobile#1011

gutenberg-mobile: wordpress-mobile/gutenberg-mobile#3116
gutenberg: WordPress/gutenberg#28854

Please refer to the Gutenberg PR as the central place for steps to tests and screenshots.

PR submission checklist:

  • I have considered adding unit tests where possible.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Feb 12, 2021

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Mar 3, 2021

You can test the changes on this Pull Request by downloading the APK here.

Siobhan added 3 commits March 5, 2021 13:09
This commit is mostly for testing purposes, I've updated GutenbergEditorFragment.java with a function called "onSetFeaturedImageButtonClicked" and want to test the results.
This commit updated reference to latest gutenberg-mobile commit.
This commit introduces code that sets a featured image when the "set as featured" button is clicked from an image block. A function within "EditPostSettingsFragment" is currently utilised for this purpose, though this is likely not the optimal approach.
@SiobhyB SiobhyB force-pushed the update/image-block-with-featured-image-setting branch from 2850cff to b251e4b Compare March 5, 2021 13:11
@SiobhyB
Copy link
Contributor Author

SiobhyB commented Mar 17, 2021

The PR is still in draft mode because, though the code technically works to set a featured image, the approach I’ve taken feels fragile/error-prone.

I’ve added a new updateFeaturedImage method under the EditorFragmentListener methods section in EditPostsActivity. That method utilizes the existing updateFeaturedImage function here in EditPostSettingsFragment. I then call this function in GutenbergEditorFragment.

By calling the function in this way, our data tools won't distinguish between any clicks to the image block's new featured image button and the button within the Post Settings screen. It also feels fragile, like any issues with EditPostSettingsFragment may then lead to issues with the image block's button.

I'm looking to explore other patterns/ways to set the featured image from GutenbergEditorFragment.

cc-ing @hypest (who noted he'd be able to take a look over this later in the week) and @jd-alexander (who has familiarity with the code from buddying me with it these past weeks). Thanks in advance for your thoughts and any pointers!

@hypest
Copy link
Contributor

hypest commented Mar 18, 2021

Looks like the bundling job fails with error index.js: Cannot find module 'babel-plugin-transform-remove-console' and that's the error I also see locally while trying to build WPAndroid on this PR. Will try to understand what's going on there.

}

private void featuredImageSet(int mediaId) {
mEditorFragmentListener.updateFeaturedImage(mediaId, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the code that uses the imagePicked parameter (passed as true here), my impression is that it uses that param just to trigger a Tracks event during the media picking flow.

During the set-feature-image flow from inside an image block, I'd expect to pass false so to avoid triggering that event so, I'm not sure why the true here @SiobhyB , can you elaborate?

This also seems related to the concern you expressed in the comment.

@hypest
Copy link
Contributor

hypest commented Mar 22, 2021

It also feels fragile, like any issues with EditPostSettingsFragment may then lead to issues with the image block's button.

Can you elaborate on that @SiobhyB ? Like, what could be an example of an issue with EditPostSettingsFragment that'd break the image block button?

In the meantime, in case that's what you have in mind too, it is a bit awkward that the editor fragment needs to call a function in the Post Settings fragment just to update the featured image id. Feels like such a function could live in a headless "service" fragment inside the EditPostActivity instead of lying inside a UI fragment.

I still think that the current PR is a good first take on implementing the set-featured-image functionality, and a cleaner approach (perhaps by extracting the shared code that sets the featured image id in the local DB) could be worked on in a follow up PR.

Siobhan added 2 commits March 23, 2021 09:39
This commit introduces an "OnSetFeaturedImageListener" and moves new featured image related functions to it from "OnMediaLibraryButtonListener".
Siobhan added 6 commits March 23, 2021 21:34
…turedImageId"

This commit introduces a "removeFeaturedImage" function to allow users to remove a featured image directly from the image block. It also updates the name of the "onGetFeaturedImageId" to "checkIfFeaturedImage" in order to better reflect its current purpose.
…uredImageId"

This commit updates "onRequestFeaturedImageId" to "sendToJSFeaturedImageId", in order to clarify the purpose of the function.
The SnackBar is currently necessary for when a featured image is removed, so removing for now.
This commit enables tracking for the image block's two new featured image buttons ("set as featured image" and "remove as featured image").
@hypest
Copy link
Contributor

hypest commented Mar 30, 2021

👋 @SiobhyB , looks like this PR is not up-to-date with the latest from the gutenberg-mobile/Gutenebrg side PRs and won't compile correctly. Can you update it? While at it, I wonder if it might be a better strategy to test/develop by using the WPAndroid app anyway (instead of the gb-mobile demo apps), since the feature includes many changes in the bridge anyway.

@SiobhyB
Copy link
Contributor Author

SiobhyB commented Mar 30, 2021

I've updated this PR now, thanks again for looking!

While at it, I wonder if it might be a better strategy to test/develop by using the WPAndroid app anyway (instead of the gb-mobile demo apps), since the feature includes many changes in the bridge anyway.

I've been developing/testing using the WPAndroid app in order to allow me to test the changes I'm making. I'm still actively working on and committing to this issue while it's in draft mode, which I think is why you caught the PR while it's out-of-date. Let me know if I'm missing something else here.

Edited to add: I'm aware that there are merge conflicts here, it's on my list to look into!

Siobhan added 7 commits March 31, 2021 07:33
The native Snackbar is going to be replaced by the new Compact Notice on the JS side.
This commits tidies up some functions that had not yet been renamed to "sendToJSFeaturedImageId", and also sends notices to the JS side when images are set or removed as featured.
@SiobhyB SiobhyB marked this pull request as ready for review April 1, 2021 17:58
@peril-wordpress-mobile
Copy link

Warnings
⚠️ PR is not assigned to a milestone.

Generated by 🚫 dangerJS

@hypest hypest merged commit 181c7d1 into develop Apr 20, 2021
@hypest hypest deleted the update/image-block-with-featured-image-setting branch April 20, 2021 15:22
@hypest
Copy link
Contributor

hypest commented Apr 21, 2021

Just a quick note: we weren't exactly trying to merge this PR but got merged automatically because we merged a PR that wholly included the commits already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Editing and display of Gutenberg blocks. [Type] Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Proposal] Allow easier setting of Featured Image
2 participants