Skip to content

Commit 44e5f13

Browse files
committed
Create ProductFormBottomSheetAction and ProductFormBottomSheetListSelectorCommand for showing the product more details bottom sheet.
1 parent 46ddafb commit 44e5f13

File tree

7 files changed

+153
-3
lines changed

7 files changed

+153
-3
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import Foundation
2+
3+
/// Actions in the product form bottom sheet to add more product details.
4+
enum ProductFormBottomSheetAction {
5+
case editInventorySettings
6+
case editShippingSettings
7+
case editCategories
8+
case editBriefDescription
9+
}
10+
11+
extension ProductFormBottomSheetAction {
12+
var title: String {
13+
switch self {
14+
case .editInventorySettings:
15+
return NSLocalizedString("Inventory",
16+
comment: "Title of the product form bottom sheet action for editing inventory settings.")
17+
case .editShippingSettings:
18+
return NSLocalizedString("Shipping",
19+
comment: "Title of the product form bottom sheet action for editing shipping settings.")
20+
case .editCategories:
21+
return NSLocalizedString("Categories",
22+
comment: "Title of the product form bottom sheet action for editing categories.")
23+
case .editBriefDescription:
24+
return NSLocalizedString("Short description",
25+
comment: "Title of the product form bottom sheet action for editing short description.")
26+
}
27+
}
28+
29+
var subtitle: String {
30+
switch self {
31+
case .editInventorySettings:
32+
return NSLocalizedString("Update product inventory and SKU",
33+
comment: "Subtitle of the product form bottom sheet action for editing inventory settings.")
34+
case .editShippingSettings:
35+
return NSLocalizedString("Add weight and dimensions",
36+
comment: "Subtitle of the product form bottom sheet action for editing shipping settings.")
37+
case .editCategories:
38+
return NSLocalizedString("Organise your products into related groups",
39+
comment: "Subtitle of the product form bottom sheet action for editing categories.")
40+
case .editBriefDescription:
41+
return NSLocalizedString("A brief excerpt about your product",
42+
comment: "Subtitle of the product form bottom sheet action for editing short description.")
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import Yosemite
2+
3+
/// `BottomSheetListSelectorCommand` for selecting a Product form action.
4+
///
5+
final class ProductFormBottomSheetListSelectorCommand: BottomSheetListSelectorCommand {
6+
typealias Model = ProductFormBottomSheetAction
7+
typealias Cell = ImageAndTitleAndTextTableViewCell
8+
9+
let data: [ProductFormBottomSheetAction]
10+
11+
let selected: ProductFormBottomSheetAction? = nil
12+
13+
private let onSelection: (ProductFormBottomSheetAction) -> Void
14+
15+
init(product: Product,
16+
isEditProductsRelease2Enabled: Bool,
17+
isEditProductsRelease3Enabled: Bool, onSelection: @escaping (ProductFormBottomSheetAction) -> Void) {
18+
self.onSelection = onSelection
19+
20+
let shouldShowShippingSettingsRow = product.isShippingEnabled
21+
let shouldShowBriefDescriptionRow = isEditProductsRelease2Enabled
22+
let shouldShowCategoriesRow = isEditProductsRelease3Enabled
23+
let actions: [ProductFormBottomSheetAction?] = [
24+
.editInventorySettings,
25+
shouldShowShippingSettingsRow ? .editShippingSettings: nil,
26+
shouldShowCategoriesRow ? .editCategories: nil,
27+
shouldShowBriefDescriptionRow ? .editBriefDescription: nil]
28+
self.data = actions.compactMap({ $0 })
29+
}
30+
31+
func configureCell(cell: ImageAndTitleAndTextTableViewCell, model: ProductFormBottomSheetAction) {
32+
cell.selectionStyle = .none
33+
cell.accessoryType = .disclosureIndicator
34+
let viewModel = ImageAndTitleAndTextTableViewCell.ViewModel(title: model.title, text: model.subtitle)
35+
cell.updateUI(viewModel: viewModel)
36+
}
37+
38+
func handleSelectedChange(selected: ProductFormBottomSheetAction) {
39+
onSelection(selected)
40+
}
41+
42+
func isSelected(model: ProductFormBottomSheetAction) -> Bool {
43+
return model == selected
44+
}
45+
}

WooCommerce/Classes/ViewRelated/Products/Edit Product/DefaultProductFormTableViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private extension DefaultProductFormTableViewModel {
4949
}
5050

5151
func settingsRows(product: Product) -> [ProductFormSection.SettingsRow] {
52-
let shouldShowShippingSettingsRow = product.downloadable == false && product.virtual == false
52+
let shouldShowShippingSettingsRow = product.isShippingEnabled
5353
let shouldShowBriefDescriptionRow = isEditProductsRelease2Enabled
5454
let shouldShowCategoriesRow = isEditProductsRelease3Enabled
5555

WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormViewController.swift

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ private extension ProductFormViewController {
170170
button.applyLinkButtonStyle()
171171
button.contentEdgeInsets = .zero
172172
button.distributeTitleAndImage(spacing: 16)
173-
}, onButtonTapped: { _ in
174-
// TODO-2053: show more details bottom sheet
173+
}, onButtonTapped: { [weak self] button in
174+
self?.moreDetailsButtonTapped(button: button)
175175
})
176176
let buttonContainerView = BottomButtonContainerView(viewModel: viewModel)
177177

@@ -182,6 +182,39 @@ private extension ProductFormViewController {
182182
}
183183
}
184184

185+
// MARK: More details actions
186+
//
187+
private extension ProductFormViewController {
188+
func moreDetailsButtonTapped(button: UIButton) {
189+
let title = NSLocalizedString("Add more details", comment: "")
190+
let viewProperties = BottomSheetListSelectorViewProperties(title: title)
191+
let isEditProductsRelease2Enabled = featureFlagService.isFeatureFlagEnabled(.editProductsRelease2)
192+
let isEditProductsRelease3Enabled = featureFlagService.isFeatureFlagEnabled(.editProductsRelease3)
193+
let dataSource = ProductFormBottomSheetListSelectorCommand(product: product,
194+
isEditProductsRelease2Enabled: isEditProductsRelease2Enabled,
195+
isEditProductsRelease3Enabled: isEditProductsRelease3Enabled) { [weak self] action in
196+
self?.dismiss(animated: true) { [weak self] in
197+
switch action {
198+
case .editInventorySettings:
199+
self?.editInventorySettings()
200+
case .editShippingSettings:
201+
self?.editShippingSettings()
202+
case .editCategories:
203+
self?.editCategories()
204+
case .editBriefDescription:
205+
self?.editBriefDescription()
206+
}
207+
}
208+
}
209+
let listSelectorViewController = BottomSheetListSelectorViewController(viewProperties: viewProperties,
210+
command: dataSource) { [weak self] selectedSortOrder in
211+
self?.dismiss(animated: true, completion: nil)
212+
}
213+
let bottomSheet = BottomSheetViewController(childViewController: listSelectorViewController)
214+
bottomSheet.show(from: self, sourceView: button, arrowDirections: .up)
215+
}
216+
}
217+
185218
// MARK: Navigation actions
186219
//
187220
private extension ProductFormViewController {

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
020F41E823176F8E00776C4D /* TopBannerPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 020F41E723176F8E00776C4D /* TopBannerPresenter.swift */; };
5151
0212275C244972660042161F /* BottomSheetListSelectorSectionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0212275B244972660042161F /* BottomSheetListSelectorSectionHeaderView.swift */; };
5252
0212275E2449728A0042161F /* BottomSheetListSelectorSectionHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0212275D2449728A0042161F /* BottomSheetListSelectorSectionHeaderView.xib */; };
53+
0212276124498A270042161F /* ProductFormBottomSheetListSelectorCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0212276024498A270042161F /* ProductFormBottomSheetListSelectorCommand.swift */; };
54+
0212276324498CDC0042161F /* ProductFormBottomSheetAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0212276224498CDC0042161F /* ProductFormBottomSheetAction.swift */; };
5355
0215320B24231D5A003F2BBD /* UIStackView+Subviews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0215320A24231D5A003F2BBD /* UIStackView+Subviews.swift */; };
5456
0215320D2423309B003F2BBD /* UIStackView+SubviewsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0215320C2423309B003F2BBD /* UIStackView+SubviewsTests.swift */; };
5557
02153211242376B5003F2BBD /* ProductPriceSettingsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02153210242376B5003F2BBD /* ProductPriceSettingsViewModelTests.swift */; };
@@ -875,6 +877,8 @@
875877
020F41E723176F8E00776C4D /* TopBannerPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopBannerPresenter.swift; sourceTree = "<group>"; };
876878
0212275B244972660042161F /* BottomSheetListSelectorSectionHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomSheetListSelectorSectionHeaderView.swift; sourceTree = "<group>"; };
877879
0212275D2449728A0042161F /* BottomSheetListSelectorSectionHeaderView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BottomSheetListSelectorSectionHeaderView.xib; sourceTree = "<group>"; };
880+
0212276024498A270042161F /* ProductFormBottomSheetListSelectorCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductFormBottomSheetListSelectorCommand.swift; sourceTree = "<group>"; };
881+
0212276224498CDC0042161F /* ProductFormBottomSheetAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductFormBottomSheetAction.swift; sourceTree = "<group>"; };
878882
0215320A24231D5A003F2BBD /* UIStackView+Subviews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIStackView+Subviews.swift"; sourceTree = "<group>"; };
879883
0215320C2423309B003F2BBD /* UIStackView+SubviewsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIStackView+SubviewsTests.swift"; sourceTree = "<group>"; };
880884
02153210242376B5003F2BBD /* ProductPriceSettingsViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductPriceSettingsViewModelTests.swift; sourceTree = "<group>"; };
@@ -1727,9 +1731,19 @@
17271731
path = "View Models";
17281732
sourceTree = "<group>";
17291733
};
1734+
0212275F244989D20042161F /* BottomSheetListSelector */ = {
1735+
isa = PBXGroup;
1736+
children = (
1737+
0212276024498A270042161F /* ProductFormBottomSheetListSelectorCommand.swift */,
1738+
0212276224498CDC0042161F /* ProductFormBottomSheetAction.swift */,
1739+
);
1740+
path = BottomSheetListSelector;
1741+
sourceTree = "<group>";
1742+
};
17301743
021627232379637E000208D2 /* Edit Product */ = {
17311744
isa = PBXGroup;
17321745
children = (
1746+
0212275F244989D20042161F /* BottomSheetListSelector */,
17331747
020B2F9223BDDBC300BD79AD /* Error Handling */,
17341748
02F4F50C237AFBB700E13A9C /* Cells */,
17351749
021E2A1223A9FBF200B1DE07 /* Inventory Settings */,
@@ -4495,6 +4509,8 @@
44954509
028296EC237D28B600E84012 /* TextViewViewController.swift in Sources */,
44964510
454B28BE23BF63C600CD2091 /* DateIntervalFormatter+Helpers.swift in Sources */,
44974511
024DF3052372ADCD006658FE /* KeyboardScrollable.swift in Sources */,
4512+
0290E27A238E590500B5C466 /* ListSelectorViewProperties.swift in Sources */,
4513+
0212276324498CDC0042161F /* ProductFormBottomSheetAction.swift in Sources */,
44984514
B555530F21B57DE700449E71 /* ApplicationAdapter.swift in Sources */,
44994515
029D444E22F141CD00DEFA8A /* DashboardStatsV3ViewController.swift in Sources */,
45004516
747AA08B2107CF8D0047A89B /* TracksProvider.swift in Sources */,
@@ -4629,6 +4645,7 @@
46294645
B517EA18218B232700730EC4 /* StringFormatter+Notes.swift in Sources */,
46304646
CE583A072107849F00D73C1C /* SwitchTableViewCell.swift in Sources */,
46314647
D8149F562251EE300006A245 /* UITextField+Helpers.swift in Sources */,
4648+
0212276124498A270042161F /* ProductFormBottomSheetListSelectorCommand.swift in Sources */,
46324649
D831E2E0230E0BA7000037D0 /* Logs.swift in Sources */,
46334650
0235594924496449004BE2B8 /* BottomSheetViewController.swift in Sources */,
46344651
CECC759C23D61C1400486676 /* AggregateDataHelper.swift in Sources */,

Yosemite/Yosemite.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
02E262BD238CE46A00B79588 /* ShippingSettingsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E262BC238CE46A00B79588 /* ShippingSettingsService.swift */; };
4646
02E262C0238CE80100B79588 /* StorageShippingSettingsServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E262BF238CE80100B79588 /* StorageShippingSettingsServiceTests.swift */; };
4747
02E262C2238CF74D00B79588 /* StorageShippingSettingsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E262C1238CF74D00B79588 /* StorageShippingSettingsService.swift */; };
48+
02E493EB245C0DCC000AEA9E /* Product+Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E493EA245C0DCC000AEA9E /* Product+Settings.swift */; };
4849
02E4F5E423CD5628003B0010 /* NSOrderedSet+Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E4F5E323CD5628003B0010 /* NSOrderedSet+Array.swift */; };
4950
02F096C4240670A400C0C1D5 /* Media+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F096C3240670A400C0C1D5 /* Media+Equatable.swift */; };
5051
02FF054D23D983F30058E6E7 /* MediaFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02FF054523D983F30058E6E7 /* MediaFileManager.swift */; };
@@ -258,6 +259,7 @@
258259
02E262BC238CE46A00B79588 /* ShippingSettingsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingSettingsService.swift; sourceTree = "<group>"; };
259260
02E262BF238CE80100B79588 /* StorageShippingSettingsServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageShippingSettingsServiceTests.swift; sourceTree = "<group>"; };
260261
02E262C1238CF74D00B79588 /* StorageShippingSettingsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageShippingSettingsService.swift; sourceTree = "<group>"; };
262+
02E493EA245C0DCC000AEA9E /* Product+Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Product+Settings.swift"; sourceTree = "<group>"; };
261263
02E4F5E323CD5628003B0010 /* NSOrderedSet+Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSOrderedSet+Array.swift"; sourceTree = "<group>"; };
262264
02F096C3240670A400C0C1D5 /* Media+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Media+Equatable.swift"; sourceTree = "<group>"; };
263265
02FF054523D983F30058E6E7 /* MediaFileManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaFileManager.swift; sourceTree = "<group>"; };
@@ -507,6 +509,7 @@
507509
isa = PBXGroup;
508510
children = (
509511
0225512022FC2F3000D98613 /* OrderStatsV4Interval+Date.swift */,
512+
02E493EA245C0DCC000AEA9E /* Product+Settings.swift */,
510513
);
511514
path = Extensions;
512515
sourceTree = "<group>";
@@ -1145,6 +1148,7 @@
11451148
026CF62C237D92DC009563D4 /* ProductVariationAttribute+ReadOnlyConvertible.swift in Sources */,
11461149
74B7D6B020F910AF002667AC /* OrderNote+ReadOnlyConvertible.swift in Sources */,
11471150
74B2601F2188A92A0041793A /* Note+ReadOnlyConvertible.swift in Sources */,
1151+
02E493EB245C0DCC000AEA9E /* Product+Settings.swift in Sources */,
11481152
CE179D57235F4E7500C24EB3 /* RefundStore.swift in Sources */,
11491153
0218B4EE242E08B20083A847 /* MediaType.swift in Sources */,
11501154
CE3B7AD72225ECA90050FE4B /* OrderStatusStore.swift in Sources */,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extension Product {
2+
/// Whether shipping settings are available for the product.
3+
public var isShippingEnabled: Bool {
4+
return downloadable == false && virtual == false
5+
}
6+
}

0 commit comments

Comments
 (0)