Skip to content

[Dynamic Dashboard] Fix issue of not updating the orders count in some scenarios #11530

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

Merged
merged 9 commits into from
May 17, 2024

Conversation

hichamboushaba
Copy link
Member

Description

In some cases, and given the fact that order status options are fetched only on app launch and when switching sites, it could happen that the app shows the performance card for stores with no orders or vice versa.

This PR fixes this by making two changes:

  1. It updates the logic of ObserveProcessingOrdersCount to always use the order status API for infering the number of processing orders, instead of using the /wc-analytics/reports/totals endpoint, this update will allow us to refresh the cache whenever any changes happen.
  2. It updates the logic of ObserveSiteOrdersState to observe the changes of order status options instead of retrieving a single snapshot.

With these two changes, the dashboard will always observe the updated state.

Testing instructions

  1. Use a store with a single order.
  2. Open the app.
  3. Notice the performance card is shown.
  4. Switch to the order list screen.
  5. Delete the order.
  6. Go back to the dashboard screen.
  7. Notice the performance card was disabled (there could be a small delay for this, and it's because of the delay of the undo action that we use before trashing the order).
  8. Repeat the test with "adding a new order"
  9. Notice the performance card was enabled.

Images/gif

Screen_recording_20240516_115549.mp4
  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

This is done by updating the logic to fetch the order status options instead of the `/wc-analytics/reports/orders/totals`
We already do a fetch when the app starts in the SiteObserver, so here we should just use the cached value initially, and then observe changes
@hichamboushaba hichamboushaba added type: enhancement A request for an enhancement. feature: dashboard Related to home screen project labels May 16, 2024
@hichamboushaba hichamboushaba added this to the 18.7 milestone May 16, 2024
@dangermattic
Copy link
Collaborator

dangermattic commented May 16, 2024

1 Message
📖

This PR contains changes to Tracks-related logic. Please ensure (author and reviewer) the following are completed:

  • The tracks events must be validated in the Tracks system.
  • Verify the internal Tracks spreadsheet has also been updated.
  • Please consider registering any new events.
  • The PR must be assigned the category: tracks label.

Generated by 🚫 Danger

Comment on lines -45 to -46
// emit updated value
fetchOrdersCount(site)?.let { emit(it) }
Copy link
Member Author

@hichamboushaba hichamboushaba May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we fetch the order status options on app launch in SiteObserver, making another fetch here is redundant, so I removed it.

Now we will start with the cached value, then observe changes and fetch when needed.

@hichamboushaba hichamboushaba requested a review from 0nko May 16, 2024 11:04
@hichamboushaba hichamboushaba marked this pull request as ready for review May 16, 2024 11:04
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 16, 2024

📲 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
FlavorJalapeno
Build TypeDebug
Commit53d9227
Direct Downloadwoocommerce-prototype-build-pr11530-53d9227.apk

@hichamboushaba hichamboushaba added the category: tracks Related to analytics, including Tracks Events. label May 16, 2024
@codecov-commenter
Copy link

codecov-commenter commented May 16, 2024

Codecov Report

Attention: Patch coverage is 41.37931% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 40.46%. Comparing base (e4cc452) to head (4be19ab).
Report is 54 commits behind head on trunk.

Current head 4be19ab differs from pull request most recent head 73e7b31

Please upload reports for the commit 73e7b31 to get more accurate results.

Files Patch % Lines
...ce/android/ui/main/ObserveProcessingOrdersCount.kt 57.14% 7 Missing and 2 partials ⚠️
...ndroid/ui/dashboard/data/ObserveSiteOrdersState.kt 0.00% 8 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #11530      +/-   ##
============================================
- Coverage     40.47%   40.46%   -0.01%     
+ Complexity     5181     5180       -1     
============================================
  Files          1075     1075              
  Lines         62873    62872       -1     
  Branches       8612     8606       -6     
============================================
- Hits          25447    25444       -3     
- Misses        35138    35141       +3     
+ Partials       2288     2287       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@0nko 0nko self-assigned this May 16, 2024
Copy link
Contributor

@0nko 0nko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started out with a store with no orders (there are some trashed orders) and the cards are still being shown, even after force-refreshing the orders and the dashboard. 🤔

Screen_recording_20240517_095857.webm

@kidinov kidinov modified the milestones: 18.7, 18.8 May 17, 2024
@hichamboushaba
Copy link
Member Author

@0nko thanks for the test, can you invite me to your store to check this? This doesn't happen on my store, trash is not returned as a status option for me, which means the trashed orders are not counted.

We skip the initial orders count, with this we don't make a redundant API call to fetch the order status options, something that SiteObserver already handles.
The function checks only the local DB, and given how pagination works, we don't remove trashed orders from the API, so when a site has trashed orders, we keep thinking that they have valid orders, and we keep showing the stats cards.
Copy link
Contributor

@0nko 0nko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well after the last change. Nice fix! :shipit:

@0nko 0nko enabled auto-merge May 17, 2024 11:03
@0nko 0nko merged commit 2b56352 into trunk May 17, 2024
14 checks passed
@0nko 0nko deleted the dashboard/improve-logic-of-has-orders branch May 17, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: tracks Related to analytics, including Tracks Events. feature: dashboard Related to home screen project type: enhancement A request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants