[Hack Week] Refactor connection checks to a list-driven architecture#15606
[Hack Week] Refactor connection checks to a list-driven architecture#15606hichamboushaba wants to merge 8 commits intohack-week/troubleshooting-screen-m4from
Conversation
…Type enum + single data class
…ant collection conversions
Generated by 🚫 Danger |
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## hack-week/troubleshooting-screen-m4 #15606 +/- ##
=========================================================================
- Coverage 39.65% 39.62% -0.04%
- Complexity 11362 11363 +1
=========================================================================
Files 2263 2263
Lines 130803 130681 -122
Branches 18331 18321 -10
=========================================================================
- Hits 51874 51781 -93
+ Misses 73620 73605 -15
+ Partials 5309 5295 -14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c539ba6 to
1dcd4c8
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the Troubleshoot Connection “connection checks” flow from a step-based/state-machine approach into a list-driven architecture, aiming to reduce boilerplate and make it easier to add/maintain checks while also fixing process-death callback restoration issues.
Changes:
- Introduces
ConnectivityCheckType+ConnectivityCheckCardDatato centralize UI/analytics metadata and represent checks as a list. - Replaces multiple per-check
StateFlows with a singlechecksFlow, and updates the ViewModel to execute checks sequentially from that list. - Updates Compose UI and unit tests to render/assert against the dynamic checks list.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/connectivitytool/ConnectivityToolViewModel.kt |
Replaces state machine + per-check flows with a single list-backed checksFlow and sequential execution logic. |
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/connectivitytool/ConnectivityToolScreen.kt |
Renders connectivity cards by iterating the checks list and wires actions to ViewModel callbacks. |
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/connectivitytool/ConnectivityCheckCardData.kt |
Replaces sealed card data hierarchy with enum-driven check definitions and a simple parcelable card model. |
WooCommerce/src/test/kotlin/com/woocommerce/android/ui/connectivitytool/ConnectivityToolViewModelTest.kt |
Updates tests to assert against checks list and new completion logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -168,101 +98,55 @@ class ConnectivityToolViewModel @Inject constructor( | |||
| triggerEvent(Exit) | |||
| } | |||
|
|
|||
| private fun handleRetryConnectionClick(step: ConnectivityCheckStep) { | |||
| when (step) { | |||
| InternetCheck -> internetCheckFlow.update { it.copy(connectivityCheckStatus = NotStarted) } | |||
| WPComCheck -> wpComCheckFlow.update { it.copy(connectivityCheckStatus = NotStarted) } | |||
| StoreCheck -> storeCheckFlow.update { it.copy(connectivityCheckStatus = NotStarted) } | |||
| StoreOrdersCheck -> ordersCheckFlow.update { it.copy(connectivityCheckStatus = NotStarted) } | |||
| StoreProductsCheck -> productsCheckFlow.update { it.copy(connectivityCheckStatus = NotStarted) } | |||
| Finished -> { /* No-op */ } | |||
| fun onRetryClicked(type: ConnectivityCheckType) { | |||
| checksFlow.update { checks -> | |||
| checks.map { | |||
| if (it.type == type) it.copy(status = NotStarted) else it | |||
| } | |||
| } | |||
| launch { | |||
| executeNextCheck() | |||
| } | |||
| stateMachine.update { step } | |||
| } | |||
There was a problem hiding this comment.
startConnectionChecks()/onRetryClicked launch executeNextCheck() without guarding against an already-running execution. If startConnectionChecks gets called again while a check is InProgress (e.g., Fragment view recreation on configuration change), you can end up running the same cold Flow twice, duplicating network requests and analytics events. Consider tracking a Job for the current execution and returning early (or cancelling/restarting) when it’s active, or otherwise ensuring only one executeNextCheck loop can run at a time.
There was a problem hiding this comment.
The retry button is shown only when the current step is not running, so we are safe I think.

Description
Note
Depends on #15597
This PR refactors the connection checks state machine to use a dynamic, list-driven architecture, significantly reducing boilerplate and making the code more scalable for future checks.
Key Changes:
ConnectivityCheckCardDatasealed class with a cleanerConnectivityCheckTypeenum that encapsulates all UI and analytics constants (title, icon, suggestion, analytics value, operation name).StateFlows into a singlechecksFlowrepresenting the sequential list of checks.ConnectivityToolScreento iterate over thecheckslist dynamically instead of hardcoding each connectivity card sequentially.@IgnoredOnParcel. The new architecture hoists these events to the ViewModel and passes them directly to the Composables, bypassing Parcelable limitations completely.Test Steps
RELEASE-NOTES.txtif necessary. Use the "[Internal]" label for non-user-facing changes.