- 
                Notifications
    You must be signed in to change notification settings 
- Fork 134
[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()andrefreshVariations()with documentation | 
| WooPosProductsDataSource.kt | Implemented refresh methods in main data source and both local/remote implementations | 
| WooPosProductsViewModel.kt | Refactored handlePullToRefresh()to use newrefreshProducts()method, removed feature flag dependencies | 
| WooPosVariationsViewModel.kt | Refactored handlePullToRefresh()to use newrefreshVariations()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:
 | 
        
          
                ...ain/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsDataSource.kt
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                ...ain/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsDataSource.kt
              
                Outdated
          
            Show resolved
            Hide resolved
        
      …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.
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.
Thanks @samiuelson !
As we discussed I haven't tested this PR since I'll test it when we update the behavior of cleaning cache on PTR.
I've left some suggestions/questions but it looks good overall and I believe can be merged as is.
        
          
                ...ain/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsDataSource.kt
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                ...ain/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsDataSource.kt
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                ...ain/kotlin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsDataSource.kt
          
            Show resolved
            Hide resolved
        
              
          
                .../kotlin/com/woocommerce/android/ui/woopos/home/items/variations/WooPosVariationsViewModel.kt
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | import com.woocommerce.android.ui.woopos.common.data.WooPosVariation | ||
| import com.woocommerce.android.ui.woopos.common.data.models.WooPosProductModel | ||
|  | ||
| sealed class WooPosHybridSyncResult : WooPosSyncResult() | 
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 think I understand the idea here, but I would consider doing it the other way round. The current implementation returns a result which can be either ProductsResult or VariationsResults (for hybrid approach). That is a bit misleading and forces us to ignore variationsResult in product VM and product result in Variations VM.
Instead, we could have two almost identical copies for local Catalog:
sealed class WooPosSyncProductResult
sealed class WooPosSyncVariationResult
Local:
sealed class PosLocalCatalogProductSyncResult : WooPosSyncProductResult() {
        val value: PosLocalCatalogSyncResult    
}
sealed class PosLocalCatalogSyncResult : WooPosSyncVariationResult() {
    val value: PosLocalCatalogSyncResult
}
sealed class PosLocalCatalogSyncResult {
    data class Success(
        val productsSynced: Int,
        val variationsSynced: Int,
        val syncDurationMs: Long
    ) : PosLocalCatalogSyncResult()
    sealed class Failure(val error: String) : PosLocalCatalogSyncResult() {
        class CatalogTooLarge(error: String, val totalPages: Int, val maxPages: Int) : Failure(error)
        class UnexpectedError(error: String) : Failure(error)
    }
}
Hybrid:
sealed class WooPosHybridProductSyncResult : WooPosSyncProductResult()
sealed class WooPosHybridVariationSyncResult : WooPosSyncVariationResult()
Wdyt?
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.
No need to update this - the more I think about it the more I feel like perhaps the downside of the current approach aren't that significant to justify this refactoring.
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.
Works as expected!
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.