Skip to content

Commit 1385645

Browse files
committed
Revert changes made to SearchUICommand and related files
1 parent 7962628 commit 1385645

File tree

11 files changed

+12
-112
lines changed

11 files changed

+12
-112
lines changed

Modules/Sources/Yosemite/Model/Storage/Coupon+ReadOnlyConvertible.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,3 @@ extension Storage.Coupon: ReadOnlyConvertible {
6464
usedBy: usedBy ?? [])
6565
}
6666
}
67-
68-
extension Storage.Coupon: ListItemConvertible {
69-
public func toListItem() -> Yosemite.Coupon {
70-
toReadOnly()
71-
}
72-
}

Modules/Sources/Yosemite/Model/Storage/Customer+ReadOnlyConvertible.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,3 @@ extension Storage.Customer: ReadOnlyConvertible {
132132
)
133133
}
134134
}
135-
136-
extension Storage.Customer: ListItemConvertible {
137-
public func toListItem() -> Yosemite.Customer {
138-
toReadOnly()
139-
}
140-
}

Modules/Sources/Yosemite/Model/Storage/Order+ReadOnlyConvertible.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ extension Storage.Order: ReadOnlyConvertible {
8282
let orderCustomFields = customFields?.map { $0.toReadOnly() } ?? [Yosemite.MetaData]()
8383
let orderGiftCards = appliedGiftCards?.map { $0.toReadOnly() } ?? [Yosemite.OrderGiftCard]()
8484
let orderShippingLabels = shippingLabels?.map { $0.toReadOnly() } ?? [Yosemite.ShippingLabel]()
85+
let orderShipments = shipments?.map { $0.toReadOnly() } ?? [Yosemite.WooShippingShipment]()
8586

8687
return Order(siteID: siteID,
8788
orderID: orderID,
@@ -171,10 +172,3 @@ extension Storage.Order {
171172
return items?.toTypeCheckedArray() ?? [Storage.OrderItem]()
172173
}
173174
}
174-
175-
extension StorageOrder: ListItemConvertible {
176-
public func toListItem() -> Yosemite.Order {
177-
// TODO: return simplified object to improve performance
178-
toReadOnly()
179-
}
180-
}

Modules/Sources/Yosemite/Model/Storage/ProductShippingClass+ReadOnlyConvertible.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,3 @@ extension Storage.ProductShippingClass: ReadOnlyConvertible {
2929
slug: slug)
3030
}
3131
}
32-
33-
extension Storage.ProductShippingClass: ListItemConvertible {
34-
public func toListItem() -> Yosemite.ProductShippingClass {
35-
toReadOnly()
36-
}
37-
}

Modules/Sources/Yosemite/Model/Storage/TaxClass+ReadOnlyConvertible.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,3 @@ extension Storage.TaxClass: ReadOnlyConvertible {
2020
return TaxClass(siteID: siteID, name: name, slug: slug)
2121
}
2222
}
23-
24-
extension StorageTaxClass: ListItemConvertible {
25-
public func toListItem() -> Yosemite.TaxClass {
26-
toReadOnly()
27-
}
28-
}

Modules/Sources/Yosemite/Tools/ResultsController.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,4 @@ public extension ResultsController where T: ListItemConvertible {
361361
func listItem(at indexPath: IndexPath) -> T.ListItemType {
362362
return controller.object(at: indexPath).toListItem()
363363
}
364-
365-
func listItemObjects(in section: Int) -> [T.ListItemType] {
366-
let objects = controller.sections?[safe: section].map { $0.objects }
367-
guard let objects else {
368-
return []
369-
}
370-
guard let castedObjects = objects as? [T] else {
371-
assertionFailure("Failed to cast objects into an array of \(T.self)")
372-
return []
373-
}
374-
375-
return castedObjects.map { $0.toListItem() }
376-
}
377364
}

Modules/Tests/YosemiteTests/Tools/ResultsControllerTests.swift

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -516,58 +516,6 @@ final class ResultsControllerTests: XCTestCase {
516516
XCTAssertEqual(listItem.name, "Product 2")
517517
XCTAssertEqual(listItem.price, "20.00")
518518
}
519-
520-
func test_listItemObjects_in_section_returns_list_items_for_specified_section() throws {
521-
// Given
522-
let categoryA = createSampleProductListItem(productID: 1, name: "Product A1", price: "10.00")
523-
let categoryA2 = createSampleProductListItem(productID: 2, name: "Product A2", price: "15.00")
524-
let categoryB = createSampleProductListItem(productID: 3, name: "Product B1", price: "20.00")
525-
526-
// Insert products and manually set product type for section grouping
527-
let storageProductA = storageManager.insertSampleProductListItem(item: categoryA)
528-
storageProductA.productTypeKey = "simple"
529-
let storageProductA2 = storageManager.insertSampleProductListItem(item: categoryA2)
530-
storageProductA2.productTypeKey = "simple"
531-
let storageProductB = storageManager.insertSampleProductListItem(item: categoryB)
532-
storageProductB.productTypeKey = "variable"
533-
534-
let sortDescriptor = NSSortDescriptor(key: #keyPath(StorageProduct.productID), ascending: true)
535-
let resultsController = ResultsController<StorageProduct>(viewStorage: viewStorage,
536-
sectionNameKeyPath: #keyPath(StorageProduct.productTypeKey),
537-
sortedBy: [sortDescriptor])
538-
try resultsController.performFetch()
539-
540-
// When
541-
let section0Items = resultsController.listItemObjects(in: 0)
542-
let section1Items = resultsController.listItemObjects(in: 1)
543-
544-
// Then
545-
XCTAssertEqual(section0Items.count, 2)
546-
XCTAssertEqual(section0Items[0].productID, 1)
547-
XCTAssertEqual(section0Items[0].name, "Product A1")
548-
XCTAssertEqual(section0Items[1].productID, 2)
549-
XCTAssertEqual(section0Items[1].name, "Product A2")
550-
551-
XCTAssertEqual(section1Items.count, 1)
552-
XCTAssertEqual(section1Items[0].productID, 3)
553-
XCTAssertEqual(section1Items[0].name, "Product B1")
554-
}
555-
556-
func test_listItemObjects_in_section_returns_empty_array_for_nonexistent_section() throws {
557-
// Given
558-
let product = createSampleProductListItem(productID: 1, name: "Product 1", price: "10.00")
559-
storageManager.insertSampleProductListItem(item: product)
560-
561-
let sortDescriptor = NSSortDescriptor(key: #keyPath(StorageProduct.productID), ascending: true)
562-
let resultsController = ResultsController<StorageProduct>(viewStorage: viewStorage, sortedBy: [sortDescriptor])
563-
try resultsController.performFetch()
564-
565-
// When
566-
let items = resultsController.listItemObjects(in: 5)
567-
568-
// Then
569-
XCTAssertTrue(items.isEmpty)
570-
}
571519
}
572520

573521
// MARK: - Utils

WooCommerce/Classes/ViewRelated/Products/Edit Product/Linked Products List Selector/ProductListSelector/ProductListMultiSelectorSearchUICommand.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Yosemite
44

55
/// Implementation of `SearchUICommand` for selecting linked products to a grouped product from search UI.
66
final class ProductListMultiSelectorSearchUICommand: NSObject, SearchUICommand {
7-
typealias ListItemModel = ProductListItem
87
typealias Model = Product
98
typealias CellViewModel = ProductsTabProductViewModel
109
typealias ResultsControllerModel = StorageProduct
@@ -71,8 +70,8 @@ final class ProductListMultiSelectorSearchUICommand: NSObject, SearchUICommand {
7170
}
7271
}
7372

74-
func createCellViewModel(model: ProductListItem) -> ProductsTabProductViewModel {
75-
return ProductsTabProductViewModel(product: model, isSelected: isProductSelected(model))
73+
func createCellViewModel(model: Product) -> ProductsTabProductViewModel {
74+
return ProductsTabProductViewModel(product: model.toListItem(), isSelected: isProductSelected(model))
7675
}
7776

7877
/// Synchronizes the Products matching a given Keyword
@@ -136,12 +135,12 @@ private extension ProductListMultiSelectorSearchUICommand {
136135
selectedProductIDs.isNotEmpty
137136
}
138137

139-
func isProductSelected(_ product: ProductListItem) -> Bool {
138+
func isProductSelected(_ product: Product) -> Bool {
140139
return selectedProductIDs.contains(product.productID)
141140
}
142141

143142
func onProductSelected(_ product: Product) {
144-
if isProductSelected(product.toListItem()) {
143+
if isProductSelected(product) {
145144
// Unselects the product if it is currently selected.
146145
selectedProductIDs.removeAll { $0 == product.productID }
147146
} else {

WooCommerce/Classes/ViewRelated/Search/Product/ProductSearchUICommand.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import protocol WooFoundation.Analytics
66

77
/// Implementation of `SearchUICommand` for Product search.
88
final class ProductSearchUICommand: SearchUICommand {
9-
typealias ListItemModel = ProductListItem
109
typealias Model = Product
1110
typealias CellViewModel = ProductsTabProductViewModel
1211
typealias ResultsControllerModel = StorageProduct
@@ -113,9 +112,9 @@ final class ProductSearchUICommand: SearchUICommand {
113112
viewController.configure(.simple(message: message, image: .magnifyingGlassNotFound))
114113
}
115114

116-
func createCellViewModel(model: ProductListItem) -> ProductsTabProductViewModel {
115+
func createCellViewModel(model: Product) -> ProductsTabProductViewModel {
117116
let hasPendingUploads = activeUploadIds.contains(where: { $0 == model.productID })
118-
return ProductsTabProductViewModel(product: model, hasPendingUploads: hasPendingUploads, isSKUShown: true)
117+
return ProductsTabProductViewModel(product: model.toListItem(), hasPendingUploads: hasPendingUploads, isSKUShown: true)
119118
}
120119

121120
/// Synchronizes the Products matching a given Keyword

WooCommerce/Classes/ViewRelated/Search/SearchUICommand.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import Combine
22
import UIKit
33
import Yosemite
44

5-
/// An interface for search UI associated with a generic list item model, full model, and cell view model.
5+
/// An interface for search UI associated with a generic model and cell view model.
66
protocol SearchUICommand {
7-
associatedtype ListItemModel // model to display on list items
87
associatedtype Model // model to send to selection closure
98
associatedtype CellViewModel
109
associatedtype EmptyStateViewControllerType: UIViewController = EmptyStateViewController
@@ -44,10 +43,8 @@ protocol SearchUICommand {
4443
/// Set externally to enable resyncing the models when needed. Otherwise, an empty closure can be set by default.
4544
var resynchronizeModels: (() -> Void) { get set }
4645

47-
associatedtype ResultsControllerModel: ResultsControllerMutableType & ListItemConvertible where
48-
ResultsControllerModel.ReadOnlyType == Model,
49-
ResultsControllerModel.ListItemType == ListItemModel
50-
46+
associatedtype ResultsControllerModel: ResultsControllerMutableType & ReadOnlyConvertible where
47+
ResultsControllerModel.ReadOnlyType == Model
5148
/// Creates a results controller for the search results. The result model's readonly type matches the search result model.
5249
func createResultsController() -> ResultsController<ResultsControllerModel>
5350

@@ -102,7 +99,7 @@ protocol SearchUICommand {
10299
///
103100
/// - Parameter model: search result model used to display on list items.
104101
/// - Returns: a view model based on the search result model.
105-
func createCellViewModel(model: ListItemModel) -> CellViewModel
102+
func createCellViewModel(model: Model) -> CellViewModel
106103

107104
/// Synchronizes the models matching a given keyword.
108105
func synchronizeModels(siteID: Int64,

0 commit comments

Comments
 (0)