Skip to content

Commit 65f8fe6

Browse files
committed
Use NavigationLink to set disclosure indicator on variable product rows
1 parent 113f623 commit 65f8fe6

File tree

4 files changed

+21
-38
lines changed

4 files changed

+21
-38
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ struct AddProductToOrder: View {
1919
InfiniteScrollList(isLoading: viewModel.shouldShowScrollIndicator,
2020
loadAction: viewModel.syncNextPage) {
2121
ForEach(viewModel.productRows) { rowViewModel in
22-
ProductRow(viewModel: rowViewModel)
23-
.onTapGesture {
24-
viewModel.selectProduct(rowViewModel.productOrVariationID)
25-
isPresented.toggle()
26-
}
22+
createProductRow(rowViewModel: rowViewModel)
2723
}
2824
}
2925
case .empty:
@@ -57,6 +53,22 @@ struct AddProductToOrder: View {
5753
}
5854
.wooNavigationBarStyle()
5955
}
56+
57+
@ViewBuilder private func createProductRow(rowViewModel: ProductRowViewModel) -> some View {
58+
if rowViewModel.numberOfVariations > 0 {
59+
NavigationLink {
60+
// TODO: Navigate to variation list
61+
} label: {
62+
ProductRow(viewModel: rowViewModel)
63+
}
64+
} else {
65+
ProductRow(viewModel: rowViewModel)
66+
.onTapGesture {
67+
viewModel.selectProduct(rowViewModel.productOrVariationID)
68+
isPresented.toggle()
69+
}
70+
}
71+
}
6072
}
6173

6274
private extension AddProductToOrder {

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ struct ProductRow: View {
4242

4343
ProductStepper(viewModel: viewModel)
4444
.renderedIf(viewModel.canChangeQuantity)
45-
46-
Image(uiImage: .chevronImage)
47-
.renderedIf(viewModel.isSelectable)
48-
.flipsForRightToLeftLayoutDirection(true)
49-
.frame(width: Layout.chevronImageSize, height: Layout.chevronImageSize)
50-
.foregroundColor(Color(UIColor.gray(.shade30)))
5145
}
5246
}
5347
}
@@ -149,17 +143,6 @@ struct ProductRow_Previews: PreviewProvider {
149143
manageStock: true,
150144
canChangeQuantity: false,
151145
imageURL: nil)
152-
let viewModelSelectable = ProductRowViewModel(productOrVariationID: 1,
153-
name: "Love Ficus",
154-
sku: "123456",
155-
price: "",
156-
stockStatusKey: "instock",
157-
stockQuantity: 7,
158-
manageStock: true,
159-
canChangeQuantity: false,
160-
imageURL: nil,
161-
isSelectable: true,
162-
numberOfVariations: 3)
163146

164147
ProductRow(viewModel: viewModel)
165148
.previewDisplayName("ProductRow with stepper")
@@ -168,9 +151,5 @@ struct ProductRow_Previews: PreviewProvider {
168151
ProductRow(viewModel: viewModelWithoutStepper)
169152
.previewDisplayName("ProductRow without stepper")
170153
.previewLayout(.sizeThatFits)
171-
172-
ProductRow(viewModel: viewModelSelectable)
173-
.previewDisplayName("Selectable ProductRow")
174-
.previewLayout(.sizeThatFits)
175154
}
176155
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,9 @@ final class ProductRowViewModel: ObservableObject, Identifiable {
8484
quantity <= minimumQuantity
8585
}
8686

87-
/// Whether the product row is selectable
88-
/// Used to add a disclosure indicator for variable products
89-
///
90-
let isSelectable: Bool
91-
9287
/// Number of variations in a variable product
9388
///
94-
private let numberOfVariations: Int
89+
let numberOfVariations: Int
9590

9691
init(id: String? = nil,
9792
productOrVariationID: Int64,
@@ -104,7 +99,6 @@ final class ProductRowViewModel: ObservableObject, Identifiable {
10499
quantity: Decimal = 1,
105100
canChangeQuantity: Bool,
106101
imageURL: URL?,
107-
isSelectable: Bool = false,
108102
numberOfVariations: Int = 0,
109103
currencyFormatter: CurrencyFormatter = CurrencyFormatter(currencySettings: ServiceLocator.currencySettings)) {
110104
self.id = id ?? productOrVariationID.description
@@ -119,7 +113,6 @@ final class ProductRowViewModel: ObservableObject, Identifiable {
119113
self.canChangeQuantity = canChangeQuantity
120114
self.imageURL = imageURL
121115
self.currencyFormatter = currencyFormatter
122-
self.isSelectable = isSelectable
123116
self.numberOfVariations = numberOfVariations
124117
}
125118

@@ -149,7 +142,6 @@ final class ProductRowViewModel: ObservableObject, Identifiable {
149142
quantity: quantity,
150143
canChangeQuantity: canChangeQuantity,
151144
imageURL: product.imageURL,
152-
isSelectable: product.productType == .variable,
153145
numberOfVariations: product.variations.count,
154146
currencyFormatter: currencyFormatter)
155147
}

WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Creation/ProductRowViewModelTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ class ProductRowViewModelTests: XCTestCase {
2222
XCTAssertEqual(viewModel.imageURL, URL(string: imageURLString))
2323
XCTAssertFalse(viewModel.canChangeQuantity)
2424
XCTAssertEqual(viewModel.quantity, 1)
25-
XCTAssertFalse(viewModel.isSelectable)
25+
XCTAssertEqual(viewModel.numberOfVariations, 0)
2626
}
2727

2828
func test_viewModel_is_created_with_correct_initial_values_from_variable_product() {
2929
// Given
30-
let product = Product.fake().copy(productTypeKey: "variable")
30+
let product = Product.fake().copy(productTypeKey: "variable", variations: [0, 1, 2])
3131

3232
// When
3333
let viewModel = ProductRowViewModel(product: product, canChangeQuantity: false)
3434

3535
// Then
36-
XCTAssertTrue(viewModel.isSelectable)
36+
XCTAssertEqual(viewModel.numberOfVariations, 3)
3737
}
3838

3939
func test_viewModel_is_created_with_correct_initial_values_from_product_variation() {

0 commit comments

Comments
 (0)