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

[HACK week] Adds favorite products filter #14001

Merged
merged 20 commits into from
Sep 26, 2024

Conversation

selanthiraiyan
Copy link
Contributor

@selanthiraiyan selanthiraiyan commented Sep 19, 2024

Part of: #12274

Description

Adds new option to filter favorite products in product lists screen and product selector screen.

I plan to enable the feature flag after a few weeks of testing.

Changes

  • Code to load favorite product IDs.
  • Send the favorite product IDs to sync products request if the favorite product filter is on.
  • Update the core data predicate to load only favorite product IDs when applicable.
  • Unit tests.

Steps to reproduce

Prerequisites

  • Use a Woo store with more than 100 products.
  • You can create a JN store and generate 100+ products using Woo Smooth generator.
  • Using the smooth generator helps to generate products with different types, status and category. (Helps with testing filters)
  • Follow instructions from this PR and mark a few products as favorites.

Products list

  • Login into the app if needed
  • Navigate to Products tab
  • Tap "Filter"
  • Validate that you see the "Favorite Products" filter.
  • Select the "Favorite Products" filter -> Switch to "Favorite Products" from "Any"
  • Tap "Show Products"
  • Validate that favorite products are loaded correctly.
  • Apply other filters and ensure that they work as before.

Product selector

  • Login into the app if needed
  • Navigate to Orders tab
  • Tap "+" -> "Add products"
  • Tap "Filter"
  • Validate that you see the "Favorite Products" filter.
  • Select the "Favorite Products" filter -> Switch to "Favorite Products" from "Any"
  • Tap "Show Products"
  • Validate that favorite products are loaded correctly.
  • Apply other filters and ensure that they work as before.

Testing information

  • Tested the product filtering works when applying the favorite product filter.
  • Tested that product filtering works correctly when applying multiple filters along with the favorite product filter.
  • Tested that product filtering works correctly in both product selector and product list screens.

Screenshots

Gif

iPhone

Product list Product selector
Simulator Screen Recording - iPhone 15 Pro Max - 2024-09-20 at 13 38 31 Simulator Screen Recording - iPhone 15 Pro Max - 2024-09-20 at 13 38 47

iPad

Product list Product selector
Simulator Screen Recording - iPad Pro 13-inch (M4) - 2024-09-20 at 13 42 02 Simulator Screen Recording - iPad Pro 13-inch (M4) - 2024-09-20 at 13 43 33

Video recording

Product list Product selector
https://github.com/user-attachments/assets/65e16089-5594-4497-974b-aa52a766ee20 https://github.com/user-attachments/assets/07fb837d-37a1-41ca-8fc2-c357f0588971

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

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 all devices (phone/tablet) and no regressions are added.

@selanthiraiyan selanthiraiyan added the feature: product list Related to the product list. label Sep 19, 2024
@selanthiraiyan selanthiraiyan added this to the 20.6 milestone Sep 19, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Sep 19, 2024

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr14001-0180b75
Version20.5
Bundle IDcom.automattic.alpha.woocommerce
Commit0180b75
App Center BuildWooCommerce - Prototype Builds #11021
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@selanthiraiyan selanthiraiyan marked this pull request as ready for review September 20, 2024 08:37
@pmusolino pmusolino self-assigned this Sep 23, 2024
Copy link
Member

@pmusolino pmusolino left a comment

Choose a reason for hiding this comment

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

Thank you, Sharma, for opening this PR.

While testing it, I found two issues:

  1. If I filter by favourite products and then remove one of these products from being a favourite, it will not be removed from the list until I refresh it.
  2. This is less obvious. If I filter by favourite products and then add a product to favourites from another point (e.g., order detail or dashboard), the product list does not refresh with the new products until I do it manually using pull to refresh. I noticed that for status changes of a product (e.g., from published to draft), they work as expected.

My suggestion would be to add an observer on Core Data so that it can observe changes in the favourites, but I believe .

@@ -1,6 +1,10 @@
*** PLEASE FOLLOW THIS FORMAT: [<priority indicator, more stars = higher priority>] <description> [<PR URL>]
*** Use [*****] to indicate smoke tests of all critical flows should be run on the final IPA before release (e.g. major library or OS update).

20.6
-----
- [internal] Ability to mark and filter favorite products. [https://github.com/woocommerce/woocommerce-ios/pull/14001]
Copy link
Member

Choose a reason for hiding this comment

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

It's worth mentioning that this has not been released yet, but it affects product filtering logic.

@@ -34,11 +35,14 @@ private extension FavoriteProductsFilter {
struct DefaultFavoriteProductsUseCase: FavoriteProductsUseCase {
Copy link
Member

Choose a reason for hiding this comment

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

Do you believe it's worth writing some unit tests for FavouriteProductsUseCase or the one in ProductSelectorViewModelTests should be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch. I added tests in a previous PR. It looks like I removed that file during a merge conflict. Added it back in 5563db9

@selanthiraiyan
Copy link
Contributor Author

Thanks for the review and testing, Paolo!

My suggestion would be to add an observer on Core Data so that it can observe changes in the favourites

We can't listen to core data to solve this issue because the favorite product IDs are stored in AppSettingsStore and not in core data. We don't store it in core data because the favorite logic is mobile only, and API doesn't support marking a product as a favorite.

I will check other options to address the issues that you reported.

@selanthiraiyan
Copy link
Contributor Author

selanthiraiyan commented Sep 25, 2024

Thanks for the review, @pmusolino! The PR is ready for another look. 🙇

While testing it, I found two issues:

  1. If I filter by favourite products and then remove one of these products from being a favourite, it will not be removed from the list until I refresh it.
  2. This is less obvious. If I filter by favourite products and then add a product to favourites from another point (e.g., order detail or dashboard), the product list does not refresh with the new products until I do it manually using pull to refresh. I noticed that for status changes of a product (e.g., from published to draft), they work as expected.

My suggestion would be to add an observer on Core Data so that it can observe changes in the favourites, but I believe .

  • To address these issues, I started reloading the products screen from view did appear after checking a few conditions c468a3e.
  • I decided not to add this reload for the ProductSelectorViewModel as the product selector screen is presented as a modal and these issues won't happen there as we can't navigate to other screens before dismissing the product selector screen.

Kindly let me know your thoughts.

Copy link
Member

@pmusolino pmusolino left a comment

Choose a reason for hiding this comment

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

Thanks, Sharma, for fixing them. Now everything works as expected 🎉

Base automatically changed from feat/12274-favorite-remote-storage to trunk September 26, 2024 05:45
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is assigned to the milestone 20.6. This milestone is due in less than 2 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@selanthiraiyan selanthiraiyan merged commit ed87ae5 into trunk Sep 26, 2024
14 checks passed
@selanthiraiyan selanthiraiyan deleted the feat/12274-favorite-products-logic branch September 26, 2024 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: product list Related to the product list.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants