Skip to content

Commit 0ab5c26

Browse files
committed
Revert "Add protocol for AddProductToOrder view models"
This reverts commit 8e8ee95.
1 parent 1e5c7ac commit 0ab5c26

File tree

4 files changed

+99
-131
lines changed

4 files changed

+99
-131
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Creation/ProductsSection/AddProductToOrder.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import SwiftUI
22

3-
/// View showing a list of products or product variations to add to an order.
3+
/// View showing a list of products to add to an order.
44
///
5-
struct AddProductToOrder<ViewModel: AddProductToOrderViewModelProtocol>: View {
5+
struct AddProductToOrder: View {
66
/// Defines whether the view is presented.
77
///
88
@Binding var isPresented: Bool
99

1010
/// View model to drive the view.
1111
///
12-
@ObservedObject var viewModel: ViewModel
12+
@ObservedObject var viewModel: AddProductToOrderViewModel
1313

1414
var body: some View {
1515
NavigationView {
@@ -88,11 +88,13 @@ private struct InfiniteScrollIndicator: View {
8888
}
8989
}
9090

91-
private enum Localization {
92-
static let title = NSLocalizedString("Add Product", comment: "Title for the screen to add a product to an order")
93-
static let close = NSLocalizedString("Close", comment: "Text for the close button in the Add Product screen")
94-
static let emptyStateMessage = NSLocalizedString("No products found",
95-
comment: "Message displayed if there are no products to display in the Add Product screen")
91+
private extension AddProductToOrder {
92+
enum Localization {
93+
static let title = NSLocalizedString("Add Product", comment: "Title for the screen to add a product to an order")
94+
static let close = NSLocalizedString("Close", comment: "Text for the close button in the Add Product screen")
95+
static let emptyStateMessage = NSLocalizedString("No products found",
96+
comment: "Message displayed if there are no products to display in the Add Product screen")
97+
}
9698
}
9799

98100
struct AddProduct_Previews: PreviewProvider {

WooCommerce/Classes/ViewRelated/Orders/Order Creation/ProductsSection/AddProductToOrderViewModel.swift

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import Yosemite
22
import protocol Storage.StorageManagerType
33

4-
/// View model for `AddProductToOrder` with a list of products.
4+
/// View model for `AddProductToOrder`.
55
///
6-
final class AddProductToOrderViewModel: AddProductToOrderViewModelProtocol {
6+
final class AddProductToOrderViewModel: ObservableObject {
77
private let siteID: Int64
88

99
/// Storage to fetch product list
@@ -58,6 +58,14 @@ final class AddProductToOrderViewModel: AddProductToOrderViewModelProtocol {
5858
///
5959
@Published private(set) var shouldShowScrollIndicator = false
6060

61+
/// View models of the ghost rows used during the loading process.
62+
///
63+
var ghostRows: [ProductRowViewModel] {
64+
return Array(0..<6).map { index in
65+
ProductRowViewModel(product: sampleGhostProduct(id: index), canChangeQuantity: false)
66+
}
67+
}
68+
6169
/// Products Results Controller.
6270
///
6371
private lazy var productsResultsController: ResultsController<StorageProduct> = {
@@ -178,3 +186,82 @@ private extension AddProductToOrderViewModel {
178186
syncingCoordinator.delegate = self
179187
}
180188
}
189+
190+
// MARK: - Utils
191+
extension AddProductToOrderViewModel {
192+
/// Represents possible statuses for syncing products
193+
///
194+
enum SyncStatus {
195+
case firstPageSync
196+
case results
197+
case empty
198+
}
199+
200+
/// Used for ghost list view while syncing
201+
///
202+
private func sampleGhostProduct(id: Int64) -> Product {
203+
Product(siteID: 1,
204+
productID: id,
205+
name: "Love Ficus",
206+
slug: "",
207+
permalink: "",
208+
date: Date(),
209+
dateCreated: Date(),
210+
dateModified: nil,
211+
dateOnSaleStart: nil,
212+
dateOnSaleEnd: nil,
213+
productTypeKey: ProductType.simple.rawValue,
214+
statusKey: ProductStatus.draft.rawValue,
215+
featured: false,
216+
catalogVisibilityKey: ProductCatalogVisibility.hidden.rawValue,
217+
fullDescription: nil,
218+
shortDescription: nil,
219+
sku: "123456",
220+
price: "20",
221+
regularPrice: nil,
222+
salePrice: nil,
223+
onSale: false,
224+
purchasable: true,
225+
totalSales: 0,
226+
virtual: false,
227+
downloadable: false,
228+
downloads: [],
229+
downloadLimit: -1,
230+
downloadExpiry: -1,
231+
buttonText: "",
232+
externalURL: nil,
233+
taxStatusKey: ProductTaxStatus.taxable.rawValue,
234+
taxClass: nil,
235+
manageStock: false,
236+
stockQuantity: 7,
237+
stockStatusKey: ProductStockStatus.inStock.rawValue,
238+
backordersKey: ProductBackordersSetting.notAllowed.rawValue,
239+
backordersAllowed: false,
240+
backordered: false,
241+
soldIndividually: true,
242+
weight: nil,
243+
dimensions: ProductDimensions(length: "1", width: "1", height: "1"),
244+
shippingRequired: false,
245+
shippingTaxable: false,
246+
shippingClass: nil,
247+
shippingClassID: 0,
248+
productShippingClass: nil,
249+
reviewsAllowed: false,
250+
averageRating: "5",
251+
ratingCount: 0,
252+
relatedIDs: [],
253+
upsellIDs: [],
254+
crossSellIDs: [],
255+
parentID: 0,
256+
purchaseNote: nil,
257+
categories: [],
258+
tags: [],
259+
images: [],
260+
attributes: [],
261+
defaultAttributes: [],
262+
variations: [],
263+
groupedProducts: [],
264+
menuOrder: 0,
265+
addOns: [])
266+
}
267+
}

WooCommerce/Classes/ViewRelated/Orders/Order Creation/ProductsSection/AddProductToOrderViewModelProtocol.swift

Lines changed: 0 additions & 117 deletions
This file was deleted.

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,6 @@
11391139
CC0324A3263AD9F40056C6B7 /* MockShippingLabelAccountSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC0324A2263AD9F40056C6B7 /* MockShippingLabelAccountSettings.swift */; };
11401140
CC078531266E706300BA9AC1 /* ErrorTopBannerFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC078530266E706300BA9AC1 /* ErrorTopBannerFactory.swift */; };
11411141
CC07860526736B6500BA9AC1 /* ErrorTopBannerFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC07860426736B6500BA9AC1 /* ErrorTopBannerFactoryTests.swift */; };
1142-
CC13C0C9278DE76A00C0B5B5 /* AddProductToOrderViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC13C0C8278DE76A00C0B5B5 /* AddProductToOrderViewModelProtocol.swift */; };
11431142
CC13C0CB278E021300C0B5B5 /* AddProductVariationToOrderViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC13C0CA278E021300C0B5B5 /* AddProductVariationToOrderViewModel.swift */; };
11441143
CC13C0CD278E086D00C0B5B5 /* AddProductVariationToOrderViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC13C0CC278E086D00C0B5B5 /* AddProductVariationToOrderViewModelTests.swift */; };
11451144
CC200BB127847DE300EC5884 /* OrderPaymentSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC200BB027847DE300EC5884 /* OrderPaymentSection.swift */; };
@@ -2730,7 +2729,6 @@
27302729
CC0324A2263AD9F40056C6B7 /* MockShippingLabelAccountSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockShippingLabelAccountSettings.swift; sourceTree = "<group>"; };
27312730
CC078530266E706300BA9AC1 /* ErrorTopBannerFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorTopBannerFactory.swift; sourceTree = "<group>"; };
27322731
CC07860426736B6500BA9AC1 /* ErrorTopBannerFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorTopBannerFactoryTests.swift; sourceTree = "<group>"; };
2733-
CC13C0C8278DE76A00C0B5B5 /* AddProductToOrderViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddProductToOrderViewModelProtocol.swift; sourceTree = "<group>"; };
27342732
CC13C0CA278E021300C0B5B5 /* AddProductVariationToOrderViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddProductVariationToOrderViewModel.swift; sourceTree = "<group>"; };
27352733
CC13C0CC278E086D00C0B5B5 /* AddProductVariationToOrderViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddProductVariationToOrderViewModelTests.swift; sourceTree = "<group>"; };
27362734
CC200BB027847DE300EC5884 /* OrderPaymentSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderPaymentSection.swift; sourceTree = "<group>"; };
@@ -6139,7 +6137,6 @@
61396137
CC53FB372755213900C4CA4F /* AddProductToOrder.swift */,
61406138
CC53FB3B2757EC7200C4CA4F /* AddProductToOrderViewModel.swift */,
61416139
CC13C0CA278E021300C0B5B5 /* AddProductVariationToOrderViewModel.swift */,
6142-
CC13C0C8278DE76A00C0B5B5 /* AddProductToOrderViewModelProtocol.swift */,
61436140
CC53FB3427551A6E00C4CA4F /* ProductRow.swift */,
61446141
CC53FB39275697B000C4CA4F /* ProductRowViewModel.swift */,
61456142
CCC284102768C18500F6CC8B /* ProductInOrder.swift */,
@@ -8180,7 +8177,6 @@
81808177
029BFD4F24597D4B00FDDEEC /* UIButton+TitleAndImage.swift in Sources */,
81818178
B5A8F8AD20B88D9900D211DE /* LoginPrologueViewController.swift in Sources */,
81828179
B5D1AFC620BC7B7300DB0E8C /* StorePickerViewController.swift in Sources */,
8183-
CC13C0C9278DE76A00C0B5B5 /* AddProductToOrderViewModelProtocol.swift in Sources */,
81848180
02DD81FB242CAA400060E50B /* WordPressMediaLibraryPickerDataSource.swift in Sources */,
81858181
0240B3AC230A910C000A866C /* StoreStatsV4ChartAxisHelper.swift in Sources */,
81868182
31579028273EE2B1008CA3AF /* VersionHelpers.swift in Sources */,

0 commit comments

Comments
 (0)