Skip to content

Commit

Permalink
Merge pull request #13544 from woocommerce/issue/13529-remove-unsuppo…
Browse files Browse the repository at this point in the history
…rted-products-while-paginating

[Woo POS][Non-Simple Products] Remove unsupported products from paginated results
  • Loading branch information
samiuelson authored Feb 14, 2025
2 parents 8e5c811 + 50fc28c commit 5678b48
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ class ProductListHandler @Inject constructor(private val repository: ProductSele

// The implementation of loadMore has limited functionality. Essentially, more items from local cache are loaded
// only after the remote request to fetch the previous page finishes successfully.
suspend fun loadMore(orderCurrency: String? = null) = mutex.withLock {
suspend fun loadMore(
includeTypes: List<WCProductStore.IncludeType> = emptyList(),
orderCurrency: String? = null
) = mutex.withLock {
if (!canLoadMore.get()) return@withLock Result.success(Unit)
if (searchQuery.value.isEmpty()) {
fetchProducts(orderCurrency = orderCurrency)
fetchProducts(
includeTypes = includeTypes,
orderCurrency = orderCurrency
)
} else {
searchInCache()
remoteSearch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ class ProductSelectorViewModel @Inject constructor(
loadMoreJob?.cancel()
loadMoreJob = viewModelScope.launch {
loadingState.value = APPENDING
listHandler.loadMore(navArgs.orderCurrency)
listHandler.loadMore(orderCurrency = navArgs.orderCurrency)
loadingState.value = IDLE
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class WooPosProductsDataSource @Inject constructor(
}.flowOn(Dispatchers.IO).take(2)

suspend fun loadMore(): Result<List<Product>> = withContext(Dispatchers.IO) {
val result = handler.loadMore()
val result = handler.loadMore(
includeTypes = listOf(WCProductStore.IncludeType.Simple, WCProductStore.IncludeType.Variable),
)
if (result.isSuccess) {
val moreProducts = handler.productsFlow.first()
updateProductCache(moreProducts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.mockito.kotlin.any
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import org.wordpress.android.fluxc.store.WCProductStore
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -214,7 +215,12 @@ class WooPosProductsDataSourceTest {
whenever(handler.canLoadMore).thenReturn(AtomicBoolean(true))
whenever(handler.productsFlow).thenReturn(flowOf(sampleProducts))
val exception = Exception("Load more failed")
whenever(handler.loadMore()).thenReturn(Result.failure(exception))
whenever(
handler.loadMore(
includeTypes = listOf(WCProductStore.IncludeType.Simple, WCProductStore.IncludeType.Variable),
orderCurrency = null
)
).thenReturn(Result.failure(exception))
val sut = WooPosProductsDataSource(handler)

sut.loadSimpleProducts(forceRefreshProducts = false).first()
Expand Down

0 comments on commit 5678b48

Please sign in to comment.