Skip to content
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

[Bulk Update Orders] Limit selection to maximum of 100 Orders at once #13219

Merged
merged 5 commits into from
Jan 6, 2025

Conversation

hafizrahman
Copy link
Contributor

@hafizrahman hafizrahman commented Dec 30, 2024

Closes: #13217

Description

The API for bulk updating Orders only support doing 100 Orders at once, and we want to add limiter on the UI side as well.

Known issue: When selecting Orders, then scrolling down to load more Orders, then the selection state gets removed. Thus truly selecting 100 items at once will not be possible in this PR. I recommend setting a smaller limit temporarily for testing purposes. More below. (The issue itself is already fixed in this PR)

Steps to reproduce

  1. Go to OrderListViewModel and updating the value of BULK_UPDATE_COUNT_LIMIT to something reasonable like 2 or 3 then build the app.
  2. Go to Orders, then long press to select Orders. Select Orders up to the maximum limit, ensure that the Snackbar with the notice message is shown,
  3. Ensure also that you are not able to select more Orders.
  4. Ensure that you are still able to deselect selected Orders.

The tests that have been performed

I tested the steps above, see video below:

Images/gif

(The test below was done with the limit set to 2, to keep things easy)

Screen.Recording.2024-12-30.at.16.33.19.mov
  • 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.

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:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

@hafizrahman hafizrahman changed the base branch from trunk to task/13140-connect-bulk-update-func December 30, 2024 07:34
var selectMultiple = true
var currentSelectionCount = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed because the predicate does not have access to the tracker itself, thus can't get the latest selection count unless it is passed to it.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Dec 30, 2024

📲 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
Commitb5a1569
Direct Downloadwoocommerce-wear-prototype-build-pr13219-b5a1569.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Dec 30, 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
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commitb5a1569
Direct Downloadwoocommerce-prototype-build-pr13219-b5a1569.apk

@codecov-commenter
Copy link

codecov-commenter commented Dec 30, 2024

Codecov Report

Attention: Patch coverage is 53.33333% with 7 lines in your changes missing coverage. Please review.

Project coverage is 40.60%. Comparing base (d5a8872) to head (b5a1569).
Report is 139 commits behind head on trunk.

Files with missing lines Patch % Lines
...d/ui/products/MutableMultipleSelectionPredicate.kt 0.00% 6 Missing ⚠️
...merce/android/ui/orders/list/OrderListViewModel.kt 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##              trunk   #13219   +/-   ##
=========================================
  Coverage     40.60%   40.60%           
- Complexity     6373     6375    +2     
=========================================
  Files          1345     1345           
  Lines         77330    77343   +13     
  Branches      10618    10620    +2     
=========================================
+ Hits          31397    31407   +10     
- Misses        43171    43172    +1     
- Partials       2762     2764    +2     

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

Comment on lines +12 to +13
val limit = maxSelectionCount ?: return true
return !(nextState && currentSelectionCount >= limit)
Copy link
Contributor Author

@hafizrahman hafizrahman Dec 30, 2024

Choose a reason for hiding this comment

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

The official documentation recommends to set the limit logic here:

https://android.googlesource.com/platform/frameworks/support/+/support-library-27.1.0/recyclerview-selection/src/main/java/androidx/widget/recyclerview/selection/SelectionTracker.java#338

We could theoretically manage selection state better in the ViewModel, controlling what can be selected/deselected and passing this to the selection tracker. We'd need to track selection and deselection eligibility and maintain selection state, then pass both to the predicate, but this feels like a complex solution for what's ultimately an edge case.

Since bulk updating 100 items on mobile feels like a rare action given the limited screen space, this current approach where we have limits at both UI and API layers feels sufficient enough to me without spending too much time on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining this! 👍🏻 I think this is a better and cleaner solution.

@hafizrahman hafizrahman added this to the 21.4 milestone Dec 30, 2024
@hafizrahman hafizrahman added the feature: order list Related to the order list. label Dec 30, 2024
@hafizrahman hafizrahman marked this pull request as ready for review December 30, 2024 09:51
@JorgeMucientes JorgeMucientes self-assigned this Dec 31, 2024
@irfano irfano assigned irfano and unassigned JorgeMucientes Jan 3, 2025
Base automatically changed from task/13140-connect-bulk-update-func to trunk January 3, 2025 09:33
Copy link
Contributor

@irfano irfano left a comment

Choose a reason for hiding this comment

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

Nice work! LGTM! 👍🏻

Comment on lines +12 to +13
val limit = maxSelectionCount ?: return true
return !(nextState && currentSelectionCount >= limit)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining this! 👍🏻 I think this is a better and cleaner solution.

@hafizrahman hafizrahman enabled auto-merge January 6, 2025 05:26
@hafizrahman hafizrahman merged commit 4e10269 into trunk Jan 6, 2025
15 checks passed
@hafizrahman hafizrahman deleted the task/13217-max-100-selection branch January 6, 2025 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: order list Related to the order list.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure only 100 items maximum can be selected at a time.
5 participants