-
Notifications
You must be signed in to change notification settings - Fork 132
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
Product creation: Add search functionality into category selection #11102
Conversation
Not functional yet.
…t categories. Specifically, display the result as a flat list instead of nested items of parent-child hierarchy.
.withIndex() | ||
.filterNot { | ||
// Skip the first time customer focuses the Search View | ||
it.index == 1 && it.value == "" |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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:
@@ -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 |
There was a problem hiding this comment.
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.
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
Codecov ReportAttention: Patch coverage is
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. |
@@ -64,16 +70,68 @@ class ProductCategoriesFragment : | |||
viewModel.fetchProductCategories() | |||
|
|||
setupTabletSecondPaneToolbar( | |||
title = getString(R.string.product_price), | |||
title = getString(R.string.product_categories), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
...mmerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailViewModel.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Jorge Mucientes <jorge.mucientes@automattic.com>
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:
SearchView
to the product category selection screen,Technical discussion
1. Implementation
Currently, there are two implementations of category selection:
ProductCategoriesFragment
used in product creation,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 thatProductCategoriesFragment
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
, intoProductCategoriesFragment
.For future improvement, it'd be great to refactor
ProductCategoriesFragment
to use the component onProductCategorySelectorFragment
.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
Images/gif
Screen_recording_20240318_220803.webm
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.