-
Notifications
You must be signed in to change notification settings - Fork 136
Fix navigation issue when triggering blaze from product detail #12763
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
Fix navigation issue when triggering blaze from product detail #12763
Conversation
When triggering Blaze from product detail the Blaze intro view was always shown, even when the user had plenty of campaigns created already.
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
| val navGraph = findNavController().graph.findNode(R.id.nav_graph_blaze_campaign_creation) as NavGraph | ||
| navGraph.setStartDestination(R.id.nav_graph_product_selector) |
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.
Unrelated to the fix, but this was not needed, as this is already handled inside navigateToBlazeGraph function.
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #12763 +/- ##
=========================================
Coverage 40.86% 40.86%
Complexity 5751 5751
=========================================
Files 1236 1236
Lines 69726 69725 -1
Branches 9669 9669
=========================================
Hits 28496 28496
+ Misses 38602 38601 -1
Partials 2628 2628 ☔ View full report in Codecov by Sentry. |
|
Thanks @JorgeMucientes for the investigation and the fix.
I tried to understand why this fails for product details and not for the other places, because since it works in other places, the above explanation wouldn't explain it. After checking the implementation of Regarding the mention about With the above, the fix would be easy, we just need to retrieve the current navgraph where the current destination sits, the below patch fixes the issue for me: Index: WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/BlazeCampaignCreationDispatcher.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/BlazeCampaignCreationDispatcher.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/BlazeCampaignCreationDispatcher.kt
--- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/BlazeCampaignCreationDispatcher.kt (revision 2cbe776d5a120a79298cd1aebe59b7bbb3ae06d0)
+++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/creation/BlazeCampaignCreationDispatcher.kt (date 1728064643670)
@@ -147,9 +147,6 @@
}
private fun BaseFragment.showProductSelector() {
- val navGraph = findNavController().graph.findNode(R.id.nav_graph_blaze_campaign_creation) as NavGraph
- navGraph.setStartDestination(R.id.nav_graph_product_selector)
-
findNavController().navigateToBlazeGraph(
startDestination = R.id.nav_graph_product_selector,
bundle = ProductSelectorFragmentArgs(
@@ -166,7 +163,10 @@
startDestination: Int,
bundle: android.os.Bundle? = null,
) {
- val navGraph = graph.findNode(R.id.nav_graph_blaze_campaign_creation) as NavGraph
+ // Retrieve the parent navgraph.
+ // currentDestination should never be null, but we're being cautious here by falling back to the main graph.
+ val parentGraph = currentDestination?.parent ?: graph
+ val navGraph = parentGraph.findNode(R.id.nav_graph_blaze_campaign_creation) as NavGraph
navGraph.setStartDestination(startDestination)
navigateSafely(Please let me know what you think. |
This reverts commit d1b1763.
|
Hey @hichamboushaba sorry for the late reply. Getting back to this. First of all thanks for taking the time to look into it and provide a much better/simpler solution.
The reason it worked for the other two destinations is because:
It was only when we tried navigating directly to BlazeCampaingPreview (which is nested inside blaze_graph) that the start destination override was lost. Anyway retrieving the current parent graph works like a charm. I just wished I realised about that sooner instead of applying all the prior changes 😅 |
Thanks @JorgeMucientes, that's not what I meant exactly, I meant: "why we correctly skip the intro when the Blaze creation is launched from other places (like from the dashboard)", this pushed me to question the explanation given above in the PR description 🙂, because we have the default Anyway, this is now clear as to why it happened, as the override was done the wrong graph 🤷. |
hichamboushaba
left a comment
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.
Looks good 👍
Can we update the PR description to clarify that the cause of the issue differs from what is currently stated, and include a link to the pertinent discussion below?
Closes: #12762
Description
This was way trickier than I expected considering how minor/simple it look the navigation bug.
When triggering Blaze creation flow from product detail, the intro screen is always shown, event when the user has already several campaigns created. This PR fixes that.
I'm not super happy with the final solution so I'm open to hearing alternatives suggestions, but after trying different approaches this was the only one I found that worked for all cases.
I'll try to explain the reason for the bug and the proposed solution.
Cause of the bug
With the current implementation from
trunkwe use the propertygraphof theNavController; this property points to the main graph attached to the current NavHost, which isnav_graph_main(when the app is in single pane mode, more on this later), so when we call findNode on it, we retrieve the nested graph attached to it, and not the one we want to modify.Proposed solution
Testing information
Promote with BlazeRepeat steps 1-3 on a site eligible for Blaze but without any Blazd campaigns. Verify that intro screen is displayed.
The tests that have been performed
Smoked tested triggering Blaze campaign creation flow from all possible access points.
I also verified that the events
🔵 Tracked: blaze_entry_point_tapped, Properties: {"source":"intro_view",are still tracked correctly for each of the cases.RELEASE-NOTES.txtif 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: