Skip to content

Commit 9a51370

Browse files
committed
Extract VM from cell details. add new sales channel label to summary
1 parent bf9a4c0 commit 9a51370

File tree

4 files changed

+117
-85
lines changed

4 files changed

+117
-85
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Details/Order Summary Section/SummaryTableViewCell.swift

Lines changed: 13 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,6 @@ import UIKit
22
import Yosemite
33
import Gridicons
44

5-
/// The ViewModel for `SummaryTableViewCell`.
6-
///
7-
/// TODO This and that cell class should be renamed to be less ambiguous.
8-
///
9-
struct SummaryTableViewCellViewModel {
10-
fileprivate struct OrderStatusPresentation {
11-
let style: OrderStatusEnum
12-
let title: String
13-
}
14-
15-
private let billingAddress: Address?
16-
private let dateCreated: Date
17-
18-
fileprivate let presentation: OrderStatusPresentation
19-
20-
private let calendar: Calendar
21-
22-
init(order: Order,
23-
status: OrderStatus?,
24-
calendar: Calendar = .current) {
25-
26-
billingAddress = order.billingAddress
27-
dateCreated = order.dateCreated
28-
29-
presentation = OrderStatusPresentation(
30-
style: status?.status ?? order.status,
31-
title: status?.name ?? order.status.rawValue
32-
)
33-
34-
self.calendar = calendar
35-
}
36-
37-
/// The full name from the billing address
38-
///
39-
var billedPersonName: String {
40-
if let fullName = billingAddress?.fullName, fullName.isNotEmpty {
41-
return fullName
42-
} else {
43-
return Localization.guestName
44-
}
45-
}
46-
47-
/// The date, time, and the order number concatenated together. Example, “Jan 22, 2018, 11:23 AM”.
48-
///
49-
var subtitle: String {
50-
let formatter = DateFormatter.dateAndTimeFormatter
51-
formatter.timeZone = .siteTimezone
52-
return formatter.string(from: dateCreated)
53-
}
54-
}
55-
56-
// MARK: - SummaryTableViewCell
57-
//
585
final class SummaryTableViewCell: UITableViewCell {
596

607
/// Label: Title
@@ -65,6 +12,10 @@ final class SummaryTableViewCell: UITableViewCell {
6512
///
6613
@IBOutlet private weak var subtitleLabel: UILabel!
6714

15+
///
16+
///
17+
@IBOutlet private weak var salesChannelLabel: UILabel!
18+
6819
/// Label: Payment Status
6920
///
7021
@IBOutlet private weak var paymentStatusLabel: PaddedLabel!
@@ -80,6 +31,7 @@ final class SummaryTableViewCell: UITableViewCell {
8031
func configure(_ viewModel: SummaryTableViewCellViewModel) {
8132
titleLabel.text = viewModel.billedPersonName
8233
subtitleLabel.text = viewModel.subtitle
34+
salesChannelLabel.text = viewModel.formattedSalesChannel
8335

8436
display(presentation: viewModel.presentation)
8537
}
@@ -91,8 +43,6 @@ final class SummaryTableViewCell: UITableViewCell {
9143
paymentStatusLabel.text = presentation.title
9244
}
9345

94-
// MARK: - Overridden Methods
95-
9646
override func awakeFromNib() {
9747
super.awakeFromNib()
9848

@@ -124,9 +74,6 @@ final class SummaryTableViewCell: UITableViewCell {
12474
}
12575
}
12676

127-
128-
// MARK: - Private
129-
//
13077
private extension SummaryTableViewCell {
13178

13279
/// Preserves the current Payment BG Color
@@ -154,6 +101,14 @@ private extension SummaryTableViewCell {
154101
subtitleLabel.accessibilityIdentifier = "summary-table-view-cell-created-label"
155102
paymentStatusLabel.applyPaddedLabelDefaultStyles()
156103
paymentStatusLabel.accessibilityIdentifier = "summary-table-view-cell-payment-status-label"
104+
105+
if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleOrdersi1) {
106+
salesChannelLabel.isHidden = false
107+
salesChannelLabel.applyFootnoteStyle()
108+
salesChannelLabel.accessibilityIdentifier = ""
109+
} else {
110+
salesChannelLabel.isHidden = true
111+
}
157112
}
158113

159114
func configureIcon() {
@@ -169,9 +124,6 @@ private extension SummaryTableViewCell {
169124
}
170125
}
171126

172-
173-
// MARK: - VoiceOver
174-
///
175127
private extension SummaryTableViewCell {
176128
func configureIconForVoiceOver() {
177129
updateStatusButton.accessibilityLabel = NSLocalizedString("Update Order Status",
@@ -181,12 +133,3 @@ private extension SummaryTableViewCell {
181133
comment: "Accessibility hint for the button to update the order status")
182134
}
183135
}
184-
185-
// MARK: - Localization
186-
187-
private extension SummaryTableViewCellViewModel {
188-
enum Localization {
189-
static let guestName: String = NSLocalizedString("Guest",
190-
comment: "In Order Details, the name of the billed person when there are no name and last name.")
191-
}
192-
}

WooCommerce/Classes/ViewRelated/Orders/Order Details/Order Summary Section/SummaryTableViewCell.xib

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23727" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23721"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
99
</dependencies>
@@ -17,26 +17,37 @@
1717
<rect key="frame" x="0.0" y="0.0" width="320" height="108"/>
1818
<autoresizingMask key="autoresizingMask"/>
1919
<subviews>
20-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Created eons ago at 9:51" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Kz9-1h-fRY">
21-
<rect key="frame" x="16" y="16" width="288" height="16"/>
22-
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
23-
<nil key="textColor"/>
24-
<nil key="highlightedColor"/>
25-
</label>
20+
<stackView opaque="NO" contentMode="scaleToFill" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="3xk-nT-znM">
21+
<rect key="frame" x="16" y="8" width="288" height="40"/>
22+
<subviews>
23+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Created eons ago at 9:51" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Kz9-1h-fRY">
24+
<rect key="frame" x="0.0" y="0.0" width="142" height="40"/>
25+
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
26+
<nil key="textColor"/>
27+
<nil key="highlightedColor"/>
28+
</label>
29+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sales Channel" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kU8-dT-4zl" userLabel="Sales Channel Label">
30+
<rect key="frame" x="146" y="0.0" width="142" height="40"/>
31+
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
32+
<nil key="textColor"/>
33+
<nil key="highlightedColor"/>
34+
</label>
35+
</subviews>
36+
</stackView>
2637
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="#00 Jane Doe" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VuR-wG-Bbc">
27-
<rect key="frame" x="16" y="40" width="288" height="28"/>
38+
<rect key="frame" x="16" y="56" width="288" height="24.5"/>
2839
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
2940
<nil key="textColor"/>
3041
<nil key="highlightedColor"/>
3142
</label>
3243
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="740" text="Processing" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uIV-Sn-Yeh" customClass="PaddedLabel" customModule="WooCommerce" customModuleProvider="target">
33-
<rect key="frame" x="16" y="76" width="67" height="16"/>
44+
<rect key="frame" x="16" y="88.5" width="67" height="3.5"/>
3445
<fontDescription key="fontDescription" style="UICTFontTextStyleFootnote"/>
3546
<nil key="textColor"/>
3647
<nil key="highlightedColor"/>
3748
</label>
3849
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0jq-dU-DSt">
39-
<rect key="frame" x="284" y="74" width="20" height="20"/>
50+
<rect key="frame" x="284" y="80.5" width="20" height="20"/>
4051
<constraints>
4152
<constraint firstAttribute="width" secondItem="0jq-dU-DSt" secondAttribute="height" multiplier="1:1" id="JlF-NG-SGG"/>
4253
<constraint firstAttribute="width" constant="20" id="weV-me-Oj4"/>
@@ -46,22 +57,23 @@
4657
</subviews>
4758
<constraints>
4859
<constraint firstItem="0jq-dU-DSt" firstAttribute="centerY" secondItem="uIV-Sn-Yeh" secondAttribute="centerY" id="0cI-jv-Lbj"/>
49-
<constraint firstItem="Kz9-1h-fRY" firstAttribute="leading" secondItem="VuR-wG-Bbc" secondAttribute="leading" id="0iO-Eg-LvT"/>
5060
<constraint firstAttribute="bottom" secondItem="uIV-Sn-Yeh" secondAttribute="bottom" constant="16" id="3OU-Nl-wcg"/>
5161
<constraint firstItem="uIV-Sn-Yeh" firstAttribute="top" secondItem="VuR-wG-Bbc" secondAttribute="bottom" constant="8" id="4yW-xe-vMw"/>
5262
<constraint firstAttribute="trailingMargin" secondItem="VuR-wG-Bbc" secondAttribute="trailing" id="ALe-dT-Iae"/>
53-
<constraint firstItem="VuR-wG-Bbc" firstAttribute="top" secondItem="Kz9-1h-fRY" secondAttribute="bottom" constant="8" id="B6Q-cI-ASJ"/>
5463
<constraint firstItem="0jq-dU-DSt" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="uIV-Sn-Yeh" secondAttribute="trailing" constant="16" id="GXV-DS-eh5"/>
55-
<constraint firstItem="Kz9-1h-fRY" firstAttribute="trailing" secondItem="VuR-wG-Bbc" secondAttribute="trailing" id="H8X-uc-vIl"/>
64+
<constraint firstItem="3xk-nT-znM" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="L58-GD-bWI"/>
65+
<constraint firstItem="3xk-nT-znM" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="8" id="TnO-xe-26W"/>
66+
<constraint firstItem="VuR-wG-Bbc" firstAttribute="top" secondItem="3xk-nT-znM" secondAttribute="bottom" constant="8" id="V2y-BO-1WX"/>
67+
<constraint firstAttribute="trailing" secondItem="3xk-nT-znM" secondAttribute="trailing" constant="16" id="VFI-lp-YIc"/>
5668
<constraint firstItem="0jq-dU-DSt" firstAttribute="trailing" secondItem="VuR-wG-Bbc" secondAttribute="trailing" id="Yrn-9W-9Dw"/>
5769
<constraint firstItem="uIV-Sn-Yeh" firstAttribute="leading" secondItem="VuR-wG-Bbc" secondAttribute="leading" id="h9K-qI-gKu"/>
5870
<constraint firstItem="VuR-wG-Bbc" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" id="mSL-pS-fig"/>
59-
<constraint firstItem="Kz9-1h-fRY" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="16" id="uxx-qn-5Vc"/>
6071
</constraints>
6172
</tableViewCellContentView>
6273
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
6374
<connections>
6475
<outlet property="paymentStatusLabel" destination="uIV-Sn-Yeh" id="7Go-fW-UgK"/>
76+
<outlet property="salesChannelLabel" destination="kU8-dT-4zl" id="xwb-3Z-ADx"/>
6577
<outlet property="subtitleLabel" destination="Kz9-1h-fRY" id="NEV-D0-Rfz"/>
6678
<outlet property="titleLabel" destination="VuR-wG-Bbc" id="d7c-2Y-FFD"/>
6779
<outlet property="updateStatusButton" destination="0jq-dU-DSt" id="f15-0P-cBB"/>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import Foundation
2+
import Yosemite
3+
4+
struct SummaryTableViewCellViewModel {
5+
struct OrderStatusPresentation {
6+
let style: OrderStatusEnum
7+
let title: String
8+
}
9+
10+
private let billingAddress: Address?
11+
private let dateCreated: Date
12+
private let salesChannel: String?
13+
14+
let presentation: OrderStatusPresentation
15+
16+
private let calendar: Calendar
17+
18+
init(order: Order,
19+
status: OrderStatus?,
20+
calendar: Calendar = .current) {
21+
22+
billingAddress = order.billingAddress
23+
dateCreated = order.dateCreated
24+
salesChannel = order.createdVia
25+
26+
presentation = OrderStatusPresentation(
27+
style: status?.status ?? order.status,
28+
title: status?.name ?? order.status.rawValue
29+
)
30+
31+
self.calendar = calendar
32+
}
33+
34+
/// The full name from the billing address
35+
///
36+
var billedPersonName: String {
37+
if let fullName = billingAddress?.fullName, fullName.isNotEmpty {
38+
return fullName
39+
} else {
40+
return Localization.guestName
41+
}
42+
}
43+
44+
/// The date, time, and the order number concatenated together. Example, “Jan 22, 2018, 11:23 AM”.
45+
///
46+
var subtitle: String {
47+
let formatter = DateFormatter.dateAndTimeFormatter
48+
formatter.timeZone = .siteTimezone
49+
return formatter.string(from: dateCreated)
50+
}
51+
52+
///
53+
///
54+
var formattedSalesChannel: String? {
55+
guard let salesChannel = salesChannel else {
56+
return nil
57+
}
58+
switch salesChannel {
59+
case "pos-rest-api":
60+
return "POS"
61+
default:
62+
return nil
63+
}
64+
}
65+
}
66+
67+
private extension SummaryTableViewCellViewModel {
68+
enum Localization {
69+
static let guestName: String = NSLocalizedString("SummaryTableViewCellViewModel.guestName",
70+
value: "Guest",
71+
comment: "In Order Details, the name of the billed person when there are no name and last name.")
72+
}
73+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,7 @@
15941594
68C7E5C42C69B3CD00856513 /* PointOfSaleItemListErrorLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C7E5C32C69B3CD00856513 /* PointOfSaleItemListErrorLayout.swift */; };
15951595
68D1BEDB28FFEDC20074A29E /* OrderCustomerListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68D1BEDA28FFEDC20074A29E /* OrderCustomerListView.swift */; };
15961596
68D1BEDD2900E4180074A29E /* CustomerSearchUICommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68D1BEDC2900E4180074A29E /* CustomerSearchUICommand.swift */; };
1597+
68D23B5B2E14FD1C00316BA6 /* SummaryTableViewCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68D23B5A2E14FD1A00316BA6 /* SummaryTableViewCellViewModel.swift */; };
15971598
68D3E98D2C7C371B005B6278 /* POSEdgeShadowViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68D3E98C2C7C371B005B6278 /* POSEdgeShadowViewModifier.swift */; };
15981599
68D5094E2AD39BC900B6FFD5 /* DiscountLineDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68D5094D2AD39BC900B6FFD5 /* DiscountLineDetailsView.swift */; };
15991600
68D8FBD12BFEF9C700477C42 /* TotalsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68D8FBD02BFEF9C700477C42 /* TotalsView.swift */; };
@@ -4728,6 +4729,7 @@
47284729
68C7E5C32C69B3CD00856513 /* PointOfSaleItemListErrorLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointOfSaleItemListErrorLayout.swift; sourceTree = "<group>"; };
47294730
68D1BEDA28FFEDC20074A29E /* OrderCustomerListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderCustomerListView.swift; sourceTree = "<group>"; };
47304731
68D1BEDC2900E4180074A29E /* CustomerSearchUICommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerSearchUICommand.swift; sourceTree = "<group>"; };
4732+
68D23B5A2E14FD1A00316BA6 /* SummaryTableViewCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SummaryTableViewCellViewModel.swift; sourceTree = "<group>"; };
47314733
68D3E98C2C7C371B005B6278 /* POSEdgeShadowViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSEdgeShadowViewModifier.swift; sourceTree = "<group>"; };
47324734
68D5094D2AD39BC900B6FFD5 /* DiscountLineDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscountLineDetailsView.swift; sourceTree = "<group>"; };
47334735
68D8FBD02BFEF9C700477C42 /* TotalsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TotalsView.swift; sourceTree = "<group>"; };
@@ -12138,6 +12140,7 @@
1213812140
isa = PBXGroup;
1213912141
children = (
1214012142
CEE006032077D1280079161F /* SummaryTableViewCell.swift */,
12143+
68D23B5A2E14FD1A00316BA6 /* SummaryTableViewCellViewModel.swift */,
1214112144
CEE006042077D1280079161F /* SummaryTableViewCell.xib */,
1214212145
CE35F10C2343E5B3007B2A6B /* Edit Order Status */,
1214312146
);
@@ -15834,6 +15837,7 @@
1583415837
B9DC770329F18A8D0013B191 /* TopProductsFromCachedOrdersProvider.swift in Sources */,
1583515838
86023FB12B199F6200A28F07 /* ThemesCarouselView.swift in Sources */,
1583615839
EE19058C2B5F744300617C53 /* BlazeAddPaymentMethodWebView.swift in Sources */,
15840+
68D23B5B2E14FD1C00316BA6 /* SummaryTableViewCellViewModel.swift in Sources */,
1583715841
D83F5933225B2EB900626E75 /* ManualTrackingViewController.swift in Sources */,
1583815842
3142663F2645E2AB00500598 /* PaymentSettingsFlowViewModelPresenter.swift in Sources */,
1583915843
68E141DB2D13107400A70D5B /* PointOfSaleCollectCashView.swift in Sources */,

0 commit comments

Comments
 (0)