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

[Products] Use Authenticated WebView for previewing products #13494

Open
wants to merge 7 commits into
base: issue/13467-improve-authenticated-webview-3
Choose a base branch
from

Conversation

hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented Feb 7, 2025

Closes: #13353

Note

Depends on #13505

Description

Currently, when the user taps on the "View Product On Store", we open a Chrome Custom Tab, and given we can't ensure that the user is authenticated in the custom tab, then there could be some issues: if the product is not published or the store is not public.
So far, we have been hiding the button when the product is not public, but the issue was still present if the store is not public (either using WPCom visibility settings, or the new "coming soon" mode of Woo Core), and this PR attempts to improve the situation by using the Authenticated WebView whenever we can authenticate the user.

Given that the Product Details fragment can be hosted in a nested NavHostFragment (when the app is using a multi-pane layout), this PR adds a new way for handling the navigation from nested child fragments to destinations that are part of the root NavGraph, more details about this below in the comments.

Important: This doesn't solve all cases, because the issue will still be present for sites that don't support auto-autentication, and for this we are planning to research an alternative solution using a new API in the future.

Steps to reproduce

TC1: Can auto authenticate
  1. Use a site which supports auto authentication (Atomic site, Jetpack site with SSO or self-hosted site using site credentials natively)
  2. Open product details of an existing product or create a new one.
  3. Change the visibility of the product to private.
  4. Confirm the button "View product on store" is visible.
  5. Tap on the button.
  6. Confirm that the Authenticated WebView is launched and you can see the product.
  7. Repeat 3-6 with draft status.
  8. Open WooCommerce > Settings> Site Visibility in wp-admin, and enable the Coming Soon mode.
  9. Repeat 4-6.
TC2: Can't auto authenticate
  1. Use a site that doesn't support auto authentication (Jetpack site without SSO, or self-hosted site using web authorization).
  2. Open product details of an existing product or create a new one.
  3. Change the visibility of the product to private.
  4. Confirm the button "View product on store" is not shown.
  5. Repeat 3-4 with draft status.
TC3: Confirm non-regression for shipping labels payment screen
  1. Apply this patch (the patch will enable multi-pane layout for all devices, and will make testing the flow easier)
  2. Make sure WooCommerce Shipping & Tax is installed in your website.
  3. Open an order in the app.
  4. Tap on Create Shipping Label.
  5. This will open the payments directly due to the above patch.
  6. Tap on "Add another credit card"
  7. Confirm the WebView is opened correctly.
  8. Apply this patch (this patch will help simulating adding a new payment method, the webview will auto close upon loading)
  9. Repeat 3-6.
  10. Check logcat and confirm "DEBUG: WebView result received" was logged.

Testing information

  • Confirm that the "View Product on Store" is shown for products regardless of their visibility when we can authenticate the user.
  • Confirm that the button is not shown for non-public products when we can't authenticate the user.
  • Confirm that the Product Preview uses the Authenticated WebView when we can authenticate the user.
  • Confirm that there is no regression in order details.

The tests that have been performed

^

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

@hichamboushaba hichamboushaba added type: enhancement A request for an enhancement. status: do not merge Dependent on another PR, ready for review but not ready for merge. feature: product details Related to adding or editing products, includes product settings. labels Feb 7, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Feb 7, 2025

1 Error
🚫 This PR is tagged with status: do not merge label(s).

Generated by 🚫 Danger

Comment on lines -489 to -491
<action
android:id="@+id/action_global_AuthenticatedWebViewFragment"
app:destination="@id/AuthenticatedWebViewFragment" />
Copy link
Member Author

@hichamboushaba hichamboushaba Feb 7, 2025

Choose a reason for hiding this comment

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

Because the multi-pane setup, we previously duplicated the destination in this nested navgraph, this is because when the app is using two panes, the when calling findNavController from the details pane, it will return the nested NavController and not the main one, and this one won't know about destinations declared in the main nav graph.

With the new extension findNavController(@IdRes navHostId: Int), we don't need this duplication, and the logic is simpler. This also avoids the issues of this duplication: making the maintenance harder, because if we needed to change the list of arguments for the destination, then we need to do it for every nav graph that defines, or we might get crypted build failures or worse runtime crashes (check this PR for an example).

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 7, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commit9b387c6
Direct Downloadwoocommerce-wear-prototype-build-pr13494-9b387c6.apk

@@ -215,7 +214,7 @@ class EditShippingLabelPaymentFragment :
}

private fun setupResultHandlers() {
handleNotice(AuthenticatedWebViewFragment.WEBVIEW_RESULT) {
handleNotice(AuthenticatedWebViewFragment.WEBVIEW_RESULT, navHostId = R.id.nav_host_fragment_main) {
Copy link
Member Author

Choose a reason for hiding this comment

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

We need to set the navHostId for the result handler too to make sure we are using the correct NavController.

@hichamboushaba hichamboushaba force-pushed the issue/13353-improve-product-preview-logic branch from ffadbf6 to 9ca142e Compare February 7, 2025 12:00
@hichamboushaba hichamboushaba marked this pull request as ready for review February 7, 2025 12:13
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 7, 2025

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commit9b387c6
Direct Downloadwoocommerce-prototype-build-pr13494-9b387c6.apk

@hichamboushaba hichamboushaba marked this pull request as draft February 7, 2025 12:21
@hichamboushaba hichamboushaba force-pushed the issue/13353-improve-product-preview-logic branch from 9ca142e to f3a63c0 Compare February 7, 2025 18:04
@hichamboushaba hichamboushaba changed the base branch from issue/13467-improve-authenticated-webview-2 to issue/13467-improve-authenticated-webview-3 February 7, 2025 18:05
@hichamboushaba hichamboushaba force-pushed the issue/13353-improve-product-preview-logic branch from f3a63c0 to 3c7010d Compare February 7, 2025 18:10
@hichamboushaba hichamboushaba force-pushed the issue/13467-improve-authenticated-webview-3 branch from d04c5c1 to 80506c6 Compare February 7, 2025 18:17
The button will now be shown when we can authenticate the user in the WebView even if the product is not public
The extension is useful when the app is in two-pane layout, as it allows child fragment to retrieve the parent NavController.
@hichamboushaba hichamboushaba force-pushed the issue/13353-improve-product-preview-logic branch from 3c7010d to 9b387c6 Compare February 7, 2025 18:17
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 12.50000% with 35 lines in your changes missing coverage. Please review.

Project coverage is 37.93%. Comparing base (80506c6) to head (9b387c6).

Files with missing lines Patch % Lines
.../com/woocommerce/android/extensions/FragmentExt.kt 0.00% 34 Missing ⚠️
...roid/ui/products/details/ProductDetailViewModel.kt 83.33% 1 Missing ⚠️
Additional details and impacted files
@@                                Coverage Diff                                @@
##             issue/13467-improve-authenticated-webview-3   #13494      +/-   ##
=================================================================================
- Coverage                                          37.93%   37.93%   -0.01%     
- Complexity                                          8986     8987       +1     
=================================================================================
  Files                                               2054     2054              
  Lines                                             112180   112203      +23     
  Branches                                           14179    14185       +6     
=================================================================================
+ Hits                                               42558    42564       +6     
- Misses                                             65730    65745      +15     
- Partials                                            3892     3894       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hichamboushaba hichamboushaba marked this pull request as ready for review February 10, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: product details Related to adding or editing products, includes product settings. status: do not merge Dependent on another PR, ready for review but not ready for merge. type: enhancement A request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants