woocommerce / woocommerce-android

WooCommerce Android app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
277 stars 135 forks source link

Fix order refreshing after search #12948

Closed atorresveiga closed 2 days ago

atorresveiga commented 2 days ago

Closes: #12941

Description

This pull request addresses the issue of the PTR (Pull-to-Refresh) getting stuck in the user interface after exiting the search view while the search is still in progress.

When we subscribe to the new pagedListWrapper in the activatePagedListWrapper function, the new LiveData starts off as null and does not emit any value until the list changes. We also remove the previous source by calling clearLiveDataSources. However, because _isFetchingFirstPage is a MediatorLiveData, it retains the last cached value. This leads to a problem: when we exit the search view and switch to the new activatePagedListWrapper, the screen state remains stuck in a refreshing state. This occurs because _isFetchingFirstPage does not reflect the state of the current activatePagedListWrapper (which is null), but rather the last cached value.

To resolve this issue, I have chosen to reset the LiveData to its default values within the clearLiveDataSources function.

I considered an alternative solution that involved adding an initial value to the PagedListWrapper LiveData. However, since this class is utilized in other projects as well, I opted for the current solution to minimize the impact on our code and prevent any regressions in those other projects.

Steps to reproduce

  1. Go to Orders
  2. Tap on Search
  3. Search anything
  4. Get back to order while PTR is still displayed
  5. Notice that PTR is there forever now, and PTR is not possible for the orders at all

Testing information

The tests that have been performed

Images/gif

https://github.com/user-attachments/assets/8e3ef9b5-2e6c-4419-b441-648fa1b749d6

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:

wpmobilebot commented 2 days ago
📲 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
Commit6fe67594b9553f7de02f4c3e2ee0801b8d4020b9
Direct Downloadwoocommerce-wear-prototype-build-pr12948-6fe6759.apk
wpmobilebot commented 2 days ago

📲 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
Commit6fe67594b9553f7de02f4c3e2ee0801b8d4020b9
Direct Downloadwoocommerce-prototype-build-pr12948-6fe6759.apk
codecov-commenter commented 2 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 39.66%. Comparing base (9a83bcc) to head (6fe6759). Report is 5 commits behind head on trunk.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## trunk #12948 +/- ## ========================================= Coverage 39.65% 39.66% - Complexity 5949 5952 +3 ========================================= Files 1261 1261 Lines 72890 72893 +3 Branches 9973 9973 ========================================= + Hits 28904 28910 +6 + Misses 41413 41411 -2 + Partials 2573 2572 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features: