-
Couldn't load subscription status.
- Fork 133
[Woo POS][Local Catalog] Refactor and fix pull-to-refresh logic in products and variations #14816
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
base: trunk
Are you sure you want to change the base?
[Woo POS][Local Catalog] Refactor and fix pull-to-refresh logic in products and variations #14816
Conversation
…w models Key changes: - A new `refreshProducts` and `refreshVariations` method has been introduced in the `WooPosProductsDataSource` layer to encapsulate the refresh logic. - The view models now call these new methods, removing the need for feature flag checks and direct interaction with sync repositories. - The `WooPosProductsInDbDataSource` now handles incremental sync logic when pull-to-refresh is triggered, falling back to a remote fetch if incremental sync isn't applicable.
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.
Pull Request Overview
This PR refactors pull-to-refresh logic for both products and variations in the WooCommerce POS local catalog feature. The changes consolidate different refresh behaviors by introducing new refreshProducts() and refreshVariations() methods that intelligently delegate to either local catalog incremental sync or remote data source refresh based on feature flags and sync requirements.
Key Changes:
- Introduced
refreshProducts()andrefreshVariations()methods in the data source interface to standardize pull-to-refresh behavior - Removed feature flag checks and related dependencies from ViewModels, moving the logic into data sources
- Updated all tests to use the new refresh methods instead of
fetchFirstPage(forceRefresh = true)
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| WooPosProductsDataSourceInterface.kt | Added new interface methods refreshProducts() and refreshVariations() with documentation |
| WooPosProductsDataSource.kt | Implemented refresh methods in main data source and both local/remote implementations |
| WooPosProductsViewModel.kt | Refactored handlePullToRefresh() to use new refreshProducts() method, removed feature flag dependencies |
| WooPosVariationsViewModel.kt | Refactored handlePullToRefresh() to use new refreshVariations() method, removed feature flag dependencies |
| WooPosProductsViewModelTest.kt | Updated tests to use refreshProducts() and removed unused mocks |
| WooPosVariationsViewModelTest.kt | Updated tests to use refreshVariations() and removed unused mocks |
| WooPosProductsDataSourceTest.kt | Added test coverage for new refresh methods |
| WooPosProductsInDbDataSourceTest.kt | Added missing constructor parameters for test setup |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
.../kotlin/com/woocommerce/android/ui/woopos/home/items/variations/WooPosVariationsViewModel.kt
Outdated
Show resolved
Hide resolved
...main/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsViewModel.kt
Outdated
Show resolved
Hide resolved
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
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.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsViewModel.kt:1
- Missing closing brace for the
WooPosProductsUIEvent.PullToRefreshTriggeredwhen block. ThehandlePullToRefreshcall and analytics tracking should be wrapped in braces.
package com.woocommerce.android.ui.woopos.home.items.products
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…ncremental-sync-even-on
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## trunk #14816 +/- ##
============================================
- Coverage 38.27% 38.26% -0.02%
- Complexity 10103 10108 +5
============================================
Files 2132 2133 +1
Lines 120582 120617 +35
Branches 16530 16547 +17
============================================
Hits 46158 46158
- Misses 69747 69764 +17
- Partials 4677 4695 +18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| } | ||
| }.flowOn(Dispatchers.IO) | ||
|
|
||
| private suspend fun shouldUseIncrementalSync(): Boolean { |
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.
❓ I'm not sure I follow the code - why do we invoke fetchFirstVariationsPage from refreshVariations 😕 ?
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.
Fixed: 801786d
|
|
||
| override fun canLoadMoreVariations(numOfVariations: Int): Boolean = false | ||
|
|
||
| override suspend fun refreshProducts(): Flow<WooPosProductsDataSource.ProductsResult> = flow { |
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.
❓ It feels a bit off that refresh returns a flow, especially since it always emits just one response. Have you considered returning Result<Unit> and relying on Room updating getProductsFromDatabaseFlow that is being observed? Alternatively, we could return Result which isn't optimal but might simplify implementing the remote approach.
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.
@malinajirka, thanks for your question. This is not obvious how to marry the Hybrid and LocalCatalog incremental sync results. Technically, the Hybrid returns a flow of Cached (intermediate) and Remote (final) results. However, in case forceRefresh=true, the cache gets cleared, I believe we can be interested solely in the last emitted result and can return it as a result. Could you please take a look at my refactor commit here: a7fd7db and let me know what you think about the approach of updating/consolidating the data sync result models?
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.
This is not obvious how to marry the Hybrid and LocalCatalog incremental sync results.
Yeah you are right, it's not trivial. I think ideally both approaches would return data from cache - the only difference should be whether it's persistent db or in-memory cache. The fact that we return the response directly isn't optimal, as it means we have multiple sources of truth. Having said that, I understand that's out of scope. Moreover, the VM logic currently determines whether to hide/show progress/error-screen, based on whether the returned data are cache/remote, so it's not something we could easily refactor.
Could you please take a look at my refactor commit here: a7fd7db and let me know what you think about the approach of updating/consolidating the data sync result models?
I like it!
…ooPosProductsInDbDataSource`
Generated by 🚫 Danger |
This commit refactors the data synchronization and observation logic within the WooPOS items list. Key changes: - Introduced `WooPosSyncResult` as a common sealed interface for different synchronization results. - Moved `ProductsResult` and `VariationsResult` into a new `WooPosHybridSyncResult` file, which inherits from `WooPosSyncResult`, to centralize result type definitions. - Modified `refreshProducts` and `refreshVariations` in data sources and ViewModels to return `Result<WooPosSyncResult>`, simplifying the handling of refresh outcomes. - Implemented continuous observation of products and variations in `WooPosProductsViewModel` and `WooPosVariationsViewModel` to ensure the UI immediately reflects data from the cache upon initialization.
…ncremental-sync-even-on
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.
Pull Request Overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../kotlin/com/woocommerce/android/ui/woopos/home/items/variations/WooPosVariationsViewModel.kt
Outdated
Show resolved
Hide resolved
...main/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsViewModel.kt
Outdated
Show resolved
Hide resolved
.../kotlin/com/woocommerce/android/ui/woopos/home/items/variations/WooPosVariationsViewModel.kt
Show resolved
Hide resolved
...main/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsViewModel.kt
Show resolved
Hide resolved
...ain/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsDataSource.kt
Show resolved
Hide resolved
...ain/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsDataSource.kt
Show resolved
Hide resolved
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.
Pull Request Overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
WOOMOB-1556
Description
This PR refactors pull-to-refresh logic for both products and variations in the WooCommerce POS local catalog feature. The changes consolidate different refresh behaviors by introducing new
refreshProducts()andrefreshVariations()methods that delegate to either local catalog incremental sync or remote data source refresh based on feature flags and sync requirements.Test Steps
Images/gif
N/A
RELEASE-NOTES.txtif necessary. Use the "[Internal]" label for non-user-facing changes.