Skip to content

Commit d66ab4e

Browse files
committed
Fix customer name display when filtering from order details
When clicking "View customer orders" from order details, the filter view now shows the customer name instead of ID. Implemented by passing the customer object through a temporary repository field that triggers the existing onCustomerSelected() logic when the filter screen opens.
1 parent 2cdb4db commit d66ab4e

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/filters/OrderFilterCategoriesFragment.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class OrderFilterCategoriesFragment :
101101
handleResult<Order.Customer>(KEY_CUSTOMER_RESULT) {
102102
viewModel.onCustomerSelected(it)
103103
}
104+
105+
viewModel.checkPendingCustomerResult()
104106
}
105107

106108
fun onPrepareMenu(menu: Menu) {

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/filters/OrderFilterCategoriesViewModel.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ class OrderFilterCategoriesViewModel @Inject constructor(
9191
savedState[OLD_FILTER_SELECTION_KEY] = oldFilterSelection
9292
}
9393
}
94-
95-
launch {
96-
orderFilterRepository.customerSelectedEvent.collect { customer ->
97-
onCustomerSelected(customer)
98-
}
99-
}
10094
}
10195

10296
fun onFilterCategorySelected(filterCategory: OrderFilterCategoryUiModel) {
@@ -353,6 +347,13 @@ class OrderFilterCategoriesViewModel @Inject constructor(
353347
}
354348
}
355349

350+
fun checkPendingCustomerResult() {
351+
orderFilterRepository.pendingCustomerResult?.let { customer ->
352+
orderFilterRepository.pendingCustomerResult = null
353+
onCustomerSelected(customer)
354+
}
355+
}
356+
356357
fun onProductSelected(productId: Long) {
357358
orderFilterRepository.productFilter = productId
358359
onFilterOptionsUpdated(

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/filters/data/OrderFiltersRepository.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import com.woocommerce.android.tools.SelectedSite
77
import com.woocommerce.android.ui.orders.filters.data.OrderListFilterCategory.CUSTOMER
88
import com.woocommerce.android.ui.orders.filters.data.OrderListFilterCategory.PRODUCT
99
import kotlinx.coroutines.CoroutineScope
10-
import kotlinx.coroutines.flow.MutableSharedFlow
11-
import kotlinx.coroutines.flow.SharedFlow
12-
import kotlinx.coroutines.flow.asSharedFlow
1310
import kotlinx.coroutines.flow.distinctUntilChanged
1411
import kotlinx.coroutines.flow.launchIn
1512
import kotlinx.coroutines.flow.onEach
@@ -26,12 +23,7 @@ class OrderFiltersRepository @Inject constructor(
2623

2724
var customerFilter: Long? = null
2825

29-
private val _customerSelectedEvent = MutableSharedFlow<Order.Customer>(replay = 0)
30-
val customerSelectedEvent: SharedFlow<Order.Customer> = _customerSelectedEvent.asSharedFlow()
31-
32-
suspend fun selectCustomer(customer: Order.Customer) {
33-
_customerSelectedEvent.emit(customer)
34-
}
26+
var pendingCustomerResult: Order.Customer? = null
3527

3628
init {
3729
selectedSite.observe()

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/list/OrderListFragment.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import androidx.core.view.doOnPreDraw
2020
import androidx.core.view.isVisible
2121
import androidx.fragment.app.activityViewModels
2222
import androidx.fragment.app.viewModels
23-
import androidx.lifecycle.lifecycleScope
2423
import androidx.navigation.findNavController
2524
import androidx.navigation.fragment.NavHostFragment
2625
import androidx.navigation.fragment.findNavController
@@ -78,7 +77,6 @@ import com.woocommerce.android.util.StringUtils
7877
import com.woocommerce.android.viewmodel.MultiLiveEvent
7978
import com.woocommerce.android.widgets.WCEmptyView.EmptyViewType
8079
import dagger.hilt.android.AndroidEntryPoint
81-
import kotlinx.coroutines.launch
8280
import org.wordpress.android.util.ToastUtils
8381
import javax.inject.Inject
8482
import org.wordpress.android.util.ActivityUtils as WPActivityUtils
@@ -927,9 +925,8 @@ class OrderListFragment :
927925

928926
fun applyCustomerFilter(customer: Order.Customer) {
929927
searchQuery = ""
930-
viewLifecycleOwner.lifecycleScope.launch {
931-
orderFiltersRepository.selectCustomer(customer)
932-
}
928+
orderFiltersRepository.customerFilter = customer.customerId
929+
orderFiltersRepository.pendingCustomerResult = customer
933930
viewModel.loadOrders()
934931

935932
uiMessageResolver.showSnack(R.string.order_list_customer_filter_applied)

0 commit comments

Comments
 (0)