Skip to content

Product creation: Add search functionality into category selection #11102

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
Jun 18, 2024

Conversation

hafizrahman
Copy link
Contributor

@hafizrahman hafizrahman commented Mar 18, 2024

Closes: https://github.com/woocommerce/woomobile-private/issues/340

Description

This is a quick HACK Week project (1 day size) to add search to product category selection in product creation.

What it does:

  1. Adds a search icon with SearchView to the product category selection screen,
  2. Does API call to search when search is entered
  3. Adds a "flat list" functionality where if the current category list has orphans (e.g: if search result returns only child categories), then display the whole list as a flat list instead of hierarchical.

Technical discussion

1. Implementation
Currently, there are two implementations of category selection:

  1. ProductCategoriesFragment used in product creation,
  2. ProductCategorySelectorFragment used in coupon creation.

The latter one is more modern and has a component that already has a search functionality added. Initially I thought to implement its component to ProductCategoriesFragment, but I found the task to be non-trivial and definitely not a one-day HACK week work for me. One reason is that ProductCategoriesFragment is tightly coupled with the product creation process (e.g: each category selection automatically updates product draft without leaving the category screen).

So instead, I chose to replicate the search functionality from ProductCategorySelectorFragment, into ProductCategoriesFragment.

For future improvement, it'd be great to refactor ProductCategoriesFragment to use the component on ProductCategorySelectorFragment.

2. Searching limitation

The search is hardcoded to return maximum of 100 results, and doesn't support load more functionality. I think this is fine for a v1, and supporting more than 100 results can be considered an edge case.


Testing instructions

  1. Prepare a demo site with multiple categories and parent/sub-categories. It'd be good to have some parent and child categories that have similar names, for testing purposes.
  2. Open app, then go to Products and select a Product,
  3. Edit the product category,
  4. Ensure search icon appears on top right,
  5. Tap the icon, ensure that the search box appears,
  6. Enter a search term, ensure that after a little bit, the search is being done and shows the result
  7. Delete the search term, ensure that the list of categories are shown as before
  8. Enter a search term where the result should be a mix of parent and child categories. Ensure the result is shown in a flat list.
  9. Play around and check the selection state, it should remain consistent when searching and clearing search.

Images/gif

Screen_recording_20240318_220803.webm
  • 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.

@hafizrahman hafizrahman added the feature: product details Related to adding or editing products, includes product settings. label Mar 18, 2024
@hafizrahman hafizrahman added this to the 17.9 milestone Mar 18, 2024
.withIndex()
.filterNot {
// Skip the first time customer focuses the Search View
it.index == 1 && it.value == ""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

starts from 1 because index 0 happens when the parent product details screen is shown (since this is a shared viewmodel).

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 marked outdated because after merging trunk, it got shifted to a different line, but the logic is still there:

https://github.com/woocommerce/woocommerce-android/pull/11102/files#diff-7696cd0f556208deab716a3491d22562cdfb3c6ad5f04ff7d1e17737e03b34e2R2552-R2553

@@ -104,7 +104,7 @@ class ProductCategoriesAdapter(
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldList[oldItemPosition]
val newItem = newList[newItemPosition]
return oldItem.category == newItem.category
return oldItem.category == newItem.category && oldItem.margin == newItem.margin
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also checks for margin differences to allow for redrawing when changing from hierarchical to flat list, or otherwise.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Mar 18, 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
Commitb98ec68
Direct Downloadwoocommerce-prototype-build-pr11102-b98ec68.apk

@backwardstruck backwardstruck modified the milestones: 17.9, 18.0 Mar 22, 2024
@kidinov kidinov removed this from the 18.0 milestone Mar 29, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 35.93750% with 41 lines in your changes missing coverage. Please review.

Project coverage is 40.21%. Comparing base (9a7ef14) to head (b98ec68).
Report is 113 commits behind head on trunk.

Files Patch % Lines
...roid/ui/products/details/ProductDetailViewModel.kt 51.11% 17 Missing and 5 partials ⚠️
...products/categories/ProductCategoriesRepository.kt 0.00% 19 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #11102      +/-   ##
============================================
- Coverage     40.22%   40.21%   -0.01%     
- Complexity     5311     5313       +2     
============================================
  Files          1128     1128              
  Lines         64985    65044      +59     
  Branches       8977     8988      +11     
============================================
+ Hits          26141    26160      +19     
- Misses        36456    36491      +35     
- Partials       2388     2393       +5     

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

@woocommerce woocommerce deleted a comment from mraadi4141 Jun 12, 2024
@hafizrahman hafizrahman added this to the 19.1 milestone Jun 12, 2024
@hafizrahman hafizrahman marked this pull request as ready for review June 12, 2024 10:16
@JorgeMucientes JorgeMucientes self-assigned this Jun 13, 2024
@@ -64,16 +70,68 @@ class ProductCategoriesFragment :
viewModel.fetchProductCategories()

setupTabletSecondPaneToolbar(
title = getString(R.string.product_price),
title = getString(R.string.product_categories),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch!

Co-authored-by: Jorge Mucientes <jorge.mucientes@automattic.com>
@toupper toupper modified the milestones: 19.1, 19.2 Jun 14, 2024
@JorgeMucientes JorgeMucientes merged commit f040b34 into trunk Jun 18, 2024
15 of 16 checks passed
@JorgeMucientes JorgeMucientes deleted the feat/search-category-in-product-creation branch June 18, 2024 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: product details Related to adding or editing products, includes product settings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants