Skip to content

Conversation

@malinajirka
Copy link
Contributor

@malinajirka malinajirka commented Nov 4, 2025

Fixes WOOMOB-1075

Do not merge - target branch must be trunk.

Description

This PR completes the local catalog search implementation by integrating the search infrastructure (from part 1) with existing UI components and ViewModels.

Key Changes:

  • Add search interface definitions to WooPosProductsDataSourceInterface
  • Integrate local search functionality in WooPosProductsDataSource
  • Refactor WooPosItemsSearchViewModel to use unified search approach
  • Update all related tests for modified components

This is part 2 of 2, building on the search infrastructure added in part 1. The feature is now fully functional end-to-end.

Test Steps

Test with site with local catalog enabled

  • Test search works when you enter a valid query
  • Test empty result is shown when you enter a query that has no results
  • Compare results returned by this version of the app compared to production version

Test the above on site with local catalog disabled. Also verify the search returns cached result first and then results from remote.

Images/gif

No user facing changes - just faster search with local catalog.

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

@malinajirka malinajirka added this to the 23.7 milestone Nov 4, 2025
@malinajirka malinajirka changed the base branch from trunk to issue/woomob-1075-woo-poslocal-catalog-implement-local-search-for-products-v2-step-1 November 4, 2025 16:55
@malinajirka malinajirka added the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Nov 4, 2025
@malinajirka malinajirka marked this pull request as ready for review November 4, 2025 16:57
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 4, 2025

📲 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 NameWooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commita201391
Direct Downloadwoocommerce-wear-prototype-build-pr14900-a201391.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 4, 2025

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

App NameWooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commita201391
Direct Downloadwoocommerce-prototype-build-pr14900-a201391.apk

…search-for-products-v2-step-1' into issue/woomob-1075-woo-poslocal-catalog-implement-local-search-for-products-v2-step-2
@malinajirka malinajirka requested a review from Copilot November 4, 2025 17:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the search functionality to use a unified Flow-based API instead of separate local and remote search methods. The main changes consolidate search logic into a single searchProducts() method that emits SearchProductsResult.Local and SearchProductsResult.Remote sequentially, improving code organization and reducing duplication.

  • Replaced separate searchLocalProducts() and searchRemoteProducts() methods with a unified searchProducts() Flow API
  • Updated ViewModel to use collectLatest for handling search results instead of managing separate coroutine jobs
  • Modified test mocks to return Flows with sequential emissions of Local and Remote results

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
WooPosItemsSearchViewModelTest.kt Updated all test mocks to use the new Flow-based search API and adjusted timing with advanceUntilIdle()
WooPosProductsInDbDataSourceTest.kt Added new constructor parameter for search data source dependency
WooPosProductsRemoteDataSourceTest.kt Changed test class name and added new tests for Flow-based search behavior
WooPosItemsSearchViewModel.kt Refactored search logic to use single Flow collection with collectLatest instead of separate jobs
WooPosProductsDataSourceInterface.kt Added SearchProductsResult sealed class and new search-related methods to interface
WooPosProductsDataSource.kt Implemented Flow-based search in both InDb and Remote data sources

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +160 to +165
if (query == currentQuery.get()) {
childToParentEventSender.sendToParent(ChildToParentEvent.SearchEvent.Finished)
if (_viewState.value is WooPosItemsSearchViewState.Loading) {
_viewState.value = WooPosItemsSearchViewState.Empty
}
}
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The 'Finished' event and Empty state handling are placed after collectLatest completes, but collectLatest will be cancelled if a new emission arrives. This code may not execute consistently. Move this logic inside the Remote result handling (after line 156) to ensure it always runs when the Remote result is processed.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is a false positive -> the block is after the collectLatest block so will be performed exactly once when the flow terminates. @samiuelson Could you double check my train of thoughts here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. I also tested cashed+remote results multiple times and didn't find any issues.

}
}
}
delay(SEARCH_DEBOUNCING_TIME)
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 a behavioral change: Before, we'd immediately search in in-memory cache and use debounce only for remote requests. However, now we debounce all requests, since the VM doesn't know whether the request is expensive or not - moreover, even in-memory and SQL requests aren't free, so this saves battery.

…search-for-products-v2-step-1' into issue/woomob-1075-woo-poslocal-catalog-implement-local-search-for-products-v2-step-2
…search-for-products-v2-step-1' into issue/woomob-1075-woo-poslocal-catalog-implement-local-search-for-products-v2-step-2
@samiuelson samiuelson self-assigned this Nov 5, 2025
Copy link
Contributor

@samiuelson samiuelson left a comment

Choose a reason for hiding this comment

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

LGTM! I tests agains regression using store incompatible with local catalog as well as local catalog-enabled store.

Base automatically changed from issue/woomob-1075-woo-poslocal-catalog-implement-local-search-for-products-v2-step-1 to trunk November 5, 2025 17:30
@malinajirka malinajirka removed the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Nov 5, 2025
@malinajirka malinajirka enabled auto-merge November 5, 2025 17:31
@malinajirka malinajirka merged commit 63bd413 into trunk Nov 5, 2025
19 of 20 checks passed
@malinajirka malinajirka deleted the issue/woomob-1075-woo-poslocal-catalog-implement-local-search-for-products-v2-step-2 branch November 5, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants