Skip to content

Commit 5797c52

Browse files
committed
Merge branch 'develop' into issue/2042-m2-feature-switch
# Conflicts: # WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormViewController.swift # WooCommerce/WooCommerceTests/ViewRelated/Products/Edit Product/DefaultProductFormTableViewModel+EditProductsM3Tests.swift
2 parents aa8a703 + 6bfa15a commit 5797c52

File tree

41 files changed

+1547
-103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1547
-103
lines changed

Networking/Networking/Model/Product/ProductStatus.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extension ProductStatus: RawRepresentable {
5656
case .pending:
5757
return NSLocalizedString("Pending review", comment: "Display label for the product's pending status")
5858
case .privateStatus:
59-
return NSLocalizedString("Private", comment: "Display label for the product's private status")
59+
return NSLocalizedString("Privately published", comment: "Display label for the product's private status")
6060
case .custom(let payload):
6161
return payload // unable to localize at runtime.
6262
}

Networking/Networking/Remote/SitePostsRemote.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class SitePostsRemote: Remote {
1616
/// - completion: Closure to be executed upon completion.
1717
///
1818
public func loadSitePost(for siteID: Int64, postID: Int64, completion: @escaping (Post?, Error?) -> Void) {
19-
let path = String(format: "/sites/%d/posts/%d", siteID, postID)
19+
let path = String(format: "sites/%d/posts/%d", siteID, postID)
2020
let parameters = ["fields": "site_ID,password"]
2121
let request = DotcomRequest(wordpressApiVersion: .mark1_1, method: .get, path: path, parameters: parameters)
2222
let mapper = PostMapper()
@@ -38,7 +38,7 @@ public class SitePostsRemote: Remote {
3838
var parameters = try post.toDictionary()
3939
let parametersFields = ["fields": "site_ID,password"]
4040
parameters.merge(parametersFields) { (current, _) in current }
41-
let path = String(format: "/sites/%d/posts/%d", siteID, postID)
41+
let path = String(format: "sites/%d/posts/%d", siteID, postID)
4242
let request = DotcomRequest(wordpressApiVersion: .mark1_2, method: .post, path: path, parameters: parameters)
4343
let mapper = PostMapper()
4444

Networking/NetworkingTests/Remote/SitePostsRemoteTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SitePostsRemoteTests: XCTestCase {
3535

3636
let postID: Int64 = 7
3737

38-
network.simulateResponse(requestUrlSuffix: "/sites/\(sampleSiteID)/posts/\(postID)", filename: "site-post")
38+
network.simulateResponse(requestUrlSuffix: "sites/\(sampleSiteID)/posts/\(postID)", filename: "site-post")
3939
remote.loadSitePost(for: sampleSiteID, postID: postID) {[weak self] (sitePost, error) in
4040
XCTAssertNil(error)
4141
XCTAssertNotNil(sitePost)
@@ -70,7 +70,7 @@ class SitePostsRemoteTests: XCTestCase {
7070
let remote = SitePostsRemote(network: network)
7171
let expectation = self.expectation(description: "Wait for site post update")
7272

73-
network.simulateResponse(requestUrlSuffix: "/sites/\(sampleSiteID)/posts/\(postID)", filename: "site-post-update")
73+
network.simulateResponse(requestUrlSuffix: "sites/\(sampleSiteID)/posts/\(postID)", filename: "site-post-update")
7474

7575
let newPassword = "new-password"
7676
let post = Post(siteID: sampleSiteID, password: newPassword)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Foundation
2+
3+
extension Optional where Wrapped == String {
4+
var isNilOrEmpty: Bool {
5+
guard let self = self else {
6+
return true
7+
}
8+
return self.isEmpty
9+
}
10+
}

WooCommerce/Classes/Extensions/UIImage+Woo.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,12 @@ extension UIImage {
397397
return im2.imageWithTintColor(tintColor)
398398
}
399399

400+
/// Password Field Image
401+
///
402+
static var passwordFieldImage: UIImage {
403+
return UIImage.gridicon(.visible)
404+
}
405+
400406
/// Waiting for Customers Image
401407
///
402408
static var waitingForCustomersImage: UIImage {

WooCommerce/Classes/Styles/UIColor+SemanticColors.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ extension UIColor {
149149
return UIColor(light: .accent,
150150
dark: .systemColor(.label))
151151
}
152+
153+
/// Text. WooCommercePurple-60 (< iOS 13 and Light Mode) and WooCommercePurple-30 (Dark Mode)
154+
///
155+
static var textBrand: UIColor {
156+
return UIColor(light: .withColorStudio(.wooCommercePurple, shade: .shade60),
157+
dark: .withColorStudio(.wooCommercePurple, shade: .shade30))
158+
}
152159
}
153160

154161

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import Foundation
2+
import Yosemite
3+
4+
/// Actions in the product form bottom sheet to add more product details.
5+
enum ProductFormBottomSheetAction {
6+
case editInventorySettings
7+
case editShippingSettings
8+
case editCategories
9+
case editBriefDescription
10+
}
11+
12+
extension ProductFormBottomSheetAction {
13+
func isVisible(product: Product) -> Bool {
14+
switch self {
15+
case .editInventorySettings:
16+
let hasStockData = product.manageStock ? product.stockQuantity != nil: true
17+
return product.sku == nil && hasStockData == false
18+
case .editShippingSettings:
19+
return product.weight.isNilOrEmpty &&
20+
product.dimensions.height.isEmpty && product.dimensions.width.isEmpty && product.dimensions.length.isEmpty
21+
case .editCategories:
22+
return product.categories.isEmpty
23+
case .editBriefDescription:
24+
return product.briefDescription.isNilOrEmpty
25+
}
26+
}
27+
}
28+
29+
extension ProductFormBottomSheetAction {
30+
var title: String {
31+
switch self {
32+
case .editInventorySettings:
33+
return NSLocalizedString("Inventory",
34+
comment: "Title of the product form bottom sheet action for editing inventory settings.")
35+
case .editShippingSettings:
36+
return NSLocalizedString("Shipping",
37+
comment: "Title of the product form bottom sheet action for editing shipping settings.")
38+
case .editCategories:
39+
return NSLocalizedString("Categories",
40+
comment: "Title of the product form bottom sheet action for editing categories.")
41+
case .editBriefDescription:
42+
return NSLocalizedString("Short description",
43+
comment: "Title of the product form bottom sheet action for editing short description.")
44+
}
45+
}
46+
47+
var subtitle: String {
48+
switch self {
49+
case .editInventorySettings:
50+
return NSLocalizedString("Update product inventory and SKU",
51+
comment: "Subtitle of the product form bottom sheet action for editing inventory settings.")
52+
case .editShippingSettings:
53+
return NSLocalizedString("Add weight and dimensions",
54+
comment: "Subtitle of the product form bottom sheet action for editing shipping settings.")
55+
case .editCategories:
56+
return NSLocalizedString("Organise your products into related groups",
57+
comment: "Subtitle of the product form bottom sheet action for editing categories.")
58+
case .editBriefDescription:
59+
return NSLocalizedString("A brief excerpt about your product",
60+
comment: "Subtitle of the product form bottom sheet action for editing short description.")
61+
}
62+
}
63+
}
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+
isEditProductsRelease3Enabled: Bool,
17+
onSelection: @escaping (ProductFormBottomSheetAction) -> Void) {
18+
self.onSelection = onSelection
19+
20+
let shouldShowShippingSettingsRow = product.isShippingEnabled
21+
let shouldShowCategoriesRow = isEditProductsRelease3Enabled
22+
let actions: [ProductFormBottomSheetAction?] = [
23+
.editInventorySettings,
24+
shouldShowShippingSettingsRow ? .editShippingSettings: nil,
25+
shouldShowCategoriesRow ? .editCategories: nil,
26+
.editBriefDescription
27+
]
28+
self.data = actions.compactMap({ $0 }).filter({ $0.isVisible(product: product) })
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private extension DefaultProductFormTableViewModel {
5050
}
5151

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

@@ -62,7 +62,7 @@ private extension DefaultProductFormTableViewModel {
6262
shouldShowBriefDescriptionRow ? .briefDescription(viewModel: briefDescriptionRow(product: product)): nil
6363
]
6464

65-
return rows.compactMap { $0 }
65+
return rows.compactMap { $0 }.filter { $0.isVisible(product: product) }
6666
}
6767
}
6868

WooCommerce/Classes/ViewRelated/Products/Edit Product/Product Settings/List Selector Data Source/ProductStatusSettingListSelectorCommand.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ final class ProductStatusSettingListSelectorCommand: ListSelectorCommand {
1212
let data: [ProductStatus] = [
1313
.publish,
1414
.draft,
15-
.pending,
16-
.privateStatus
15+
.pending
1716
]
1817

1918
private(set) var selected: ProductStatus?

0 commit comments

Comments
 (0)