Skip to content

Commit e102f08

Browse files
committed
OrderSearchStarterVC: Use CellViewModel for OrdersVC initialization
1 parent 573e900 commit e102f08

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

WooCommerce/Classes/ViewRelated/Search/Order/OrderSearchStarterViewController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,12 @@ extension OrderSearchStarterViewController: UITableViewDelegate {
8484

8585
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
8686
let cellViewModel = viewModel.cellViewModel(at: indexPath)
87-
let orderStatus = viewModel.orderStatus(at: indexPath)
8887

8988
analytics.trackSelectionOf(orderStatusSlug: cellViewModel.slug)
9089

9190
let ordersViewController = OrdersViewController(
92-
title: orderStatus.name ?? NSLocalizedString("Orders", comment: "Default title for Orders List shown when tapping on the Search filter."),
93-
statusFilter: orderStatus
91+
title: cellViewModel.name ?? NSLocalizedString("Orders", comment: "Default title for Orders List shown when tapping on the Search filter."),
92+
statusFilter: cellViewModel.orderStatus
9493
)
9594

9695
navigationController?.pushViewController(ordersViewController, animated: true)

WooCommerce/Classes/ViewRelated/Search/Order/OrderSearchStarterViewModel.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ final class OrderSearchStarterViewModel {
1919
struct CellViewModel {
2020
let name: String?
2121
let slug: String
22+
2223
/// The total displayed on the right side.
2324
///
2425
/// If this is above 99, this will be “99+”.
2526
let total: String
27+
28+
/// The source `OrderStatus` used to create this `ViewModel`.
29+
///
30+
/// This should only be used for initializing `OrdersViewController`.
31+
///
32+
let orderStatus: OrderStatus
2633
}
2734

2835
private lazy var resultsController: ResultsController<StorageOrderStatus> = {
@@ -72,12 +79,6 @@ extension OrderSearchStarterViewModel {
7279
resultsController.numberOfObjects
7380
}
7481

75-
/// The `OrderStatus` located at `indexPath`.
76-
///
77-
func orderStatus(at indexPath: IndexPath) -> OrderStatus {
78-
resultsController.object(at: indexPath)
79-
}
80-
8182
/// The `CellViewModel` located at `indexPath`.
8283
///
8384
func cellViewModel(at indexPath: IndexPath) -> CellViewModel {
@@ -87,6 +88,7 @@ extension OrderSearchStarterViewModel {
8788

8889
return CellViewModel(name: orderStatus.name,
8990
slug: orderStatus.slug,
90-
total: total)
91+
total: total,
92+
orderStatus: orderStatus)
9193
}
9294
}

0 commit comments

Comments
 (0)