Skip to content

Commit f6315d4

Browse files
committed
Add view for list of product variations to add to a new order
1 parent 752a70b commit f6315d4

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import SwiftUI
2+
3+
/// View showing a list of product variations to add to an order.
4+
///
5+
struct AddProductVariationToOrder: View {
6+
/// Defines whether the view is presented.
7+
///
8+
@Binding var isPresented: Bool
9+
10+
/// View model to drive the view.
11+
///
12+
@ObservedObject var viewModel: AddProductVariationToOrderViewModel
13+
14+
var body: some View {
15+
NavigationView {
16+
Group {
17+
switch viewModel.syncStatus {
18+
case .results:
19+
InfiniteScrollList(isLoading: viewModel.shouldShowScrollIndicator,
20+
loadAction: viewModel.syncNextPage) {
21+
ForEach(viewModel.productVariationRows) { rowViewModel in
22+
ProductRow(viewModel: rowViewModel)
23+
.onTapGesture {
24+
viewModel.selectVariation(rowViewModel.productOrVariationID)
25+
isPresented.toggle()
26+
}
27+
}
28+
}
29+
case .empty:
30+
EmptyState(title: Localization.emptyStateMessage, image: .emptyProductsTabImage)
31+
.frame(maxHeight: .infinity)
32+
case .firstPageSync:
33+
List(viewModel.ghostRows) { rowViewModel in
34+
ProductRow(viewModel: rowViewModel)
35+
.redacted(reason: .placeholder)
36+
.shimmering()
37+
}
38+
.listStyle(PlainListStyle())
39+
default:
40+
EmptyView()
41+
}
42+
}
43+
.background(Color(.listBackground).ignoresSafeArea())
44+
.ignoresSafeArea(.container, edges: .horizontal)
45+
.navigationTitle(viewModel.productName)
46+
.navigationBarTitleDisplayMode(.inline)
47+
.onAppear {
48+
viewModel.syncFirstPage()
49+
}
50+
}
51+
.wooNavigationBarStyle()
52+
}
53+
}
54+
55+
private extension AddProductVariationToOrder {
56+
enum Localization {
57+
static let emptyStateMessage = NSLocalizedString("No product variations found",
58+
comment: "Message displayed if there are no product variations for a product.")
59+
}
60+
}
61+
62+
struct AddProductVariationToOrder_Previews: PreviewProvider {
63+
static var previews: some View {
64+
let viewModel = AddProductVariationToOrderViewModel(siteID: 1, productID: 2, productName: "Monstera Plant", productAttributes: [])
65+
66+
AddProductVariationToOrder(isPresented: .constant(true), viewModel: viewModel)
67+
}
68+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@
11811181
CCE4CD172667EBB100E09FD4 /* ShippingLabelPaymentMethodsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCE4CD162667EBB100E09FD4 /* ShippingLabelPaymentMethodsViewModelTests.swift */; };
11821182
CCE4CD282669324300E09FD4 /* ShippingLabelPaymentMethodsTopBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCE4CD272669324300E09FD4 /* ShippingLabelPaymentMethodsTopBanner.swift */; };
11831183
CCF87BBE279047BC00461C43 /* InfiniteScrollList.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCF87BBD279047BC00461C43 /* InfiniteScrollList.swift */; };
1184+
CCF87BC02790582500461C43 /* AddProductVariationToOrder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCF87BBF2790582400461C43 /* AddProductVariationToOrder.swift */; };
11841185
CCFC00B523E9BD1500157A78 /* ScreenshotCredentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCFC00B423E9BD1500157A78 /* ScreenshotCredentials.swift */; };
11851186
CCFC00EE23E9BD5500157A78 /* oauth2_token.json in Resources */ = {isa = PBXBuildFile; fileRef = CCFC00BC23E9BD5500157A78 /* oauth2_token.json */; };
11861187
CCFC00EF23E9BD5500157A78 /* auth_options.json in Resources */ = {isa = PBXBuildFile; fileRef = CCFC00BD23E9BD5500157A78 /* auth_options.json */; };
@@ -2774,6 +2775,7 @@
27742775
CCE4CD162667EBB100E09FD4 /* ShippingLabelPaymentMethodsViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelPaymentMethodsViewModelTests.swift; sourceTree = "<group>"; };
27752776
CCE4CD272669324300E09FD4 /* ShippingLabelPaymentMethodsTopBanner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelPaymentMethodsTopBanner.swift; sourceTree = "<group>"; };
27762777
CCF87BBD279047BC00461C43 /* InfiniteScrollList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfiniteScrollList.swift; sourceTree = "<group>"; };
2778+
CCF87BBF2790582400461C43 /* AddProductVariationToOrder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddProductVariationToOrder.swift; sourceTree = "<group>"; };
27772779
CCFC00B423E9BD1500157A78 /* ScreenshotCredentials.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScreenshotCredentials.swift; sourceTree = "<group>"; };
27782780
CCFC00BC23E9BD5500157A78 /* oauth2_token.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = oauth2_token.json; sourceTree = "<group>"; };
27792781
CCFC00BD23E9BD5500157A78 /* auth_options.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = auth_options.json; sourceTree = "<group>"; };
@@ -6139,6 +6141,7 @@
61396141
children = (
61406142
CC53FB372755213900C4CA4F /* AddProductToOrder.swift */,
61416143
CC53FB3B2757EC7200C4CA4F /* AddProductToOrderViewModel.swift */,
6144+
CCF87BBF2790582400461C43 /* AddProductVariationToOrder.swift */,
61426145
CC13C0CA278E021300C0B5B5 /* AddProductVariationToOrderViewModel.swift */,
61436146
CC53FB3427551A6E00C4CA4F /* ProductRow.swift */,
61446147
CC53FB39275697B000C4CA4F /* ProductRowViewModel.swift */,
@@ -8600,6 +8603,7 @@
86008603
0211252825773F220075AD2A /* Models+Copiable.generated.swift in Sources */,
86018604
4596853F2540669900D17B90 /* DownloadableFileSource.swift in Sources */,
86028605
0279F0E4252DC9670098D7DE /* ProductVariationLoadUseCase.swift in Sources */,
8606+
CCF87BC02790582500461C43 /* AddProductVariationToOrder.swift in Sources */,
86038607
02CA63DC23D1ADD100BBF148 /* DeviceMediaLibraryPicker.swift in Sources */,
86048608
021A84E0257DFC2A00BC71D1 /* RefundShippingLabelViewController.swift in Sources */,
86058609
DE279BA826E9C8E3002BA963 /* ShippingLabelSinglePackage.swift in Sources */,

0 commit comments

Comments
 (0)