Skip to content

Commit 4bfdf59

Browse files
authored
Merge pull request #8208 from woocommerce/issue/8149-placeholder-card-data
[Analytics Hub] Initialize Revenue and Orders Analytics cards with localized placeholder data
2 parents 64bb048 + 54fb760 commit 4bfdf59

File tree

1 file changed

+49
-18
lines changed

1 file changed

+49
-18
lines changed

WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModel.swift

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import Yosemite
3+
import class UIKit.UIColor
34

45
/// Main View Model for the Analytics Hub.
56
///
@@ -24,27 +25,27 @@ final class AnalyticsHubViewModel: ObservableObject {
2425

2526
/// Revenue Card ViewModel
2627
///
27-
@Published var revenueCard = AnalyticsReportCardViewModel(title: "REVENUE",
28-
leadingTitle: "Total Sales",
29-
leadingValue: "$3.234",
30-
leadingDelta: "+23%",
31-
leadingDeltaColor: .withColorStudio(.green, shade: .shade50),
32-
trailingTitle: "Net Sales",
33-
trailingValue: "$2.324",
34-
trailingDelta: "-4%",
35-
trailingDeltaColor: .withColorStudio(.red, shade: .shade40))
28+
@Published var revenueCard = AnalyticsReportCardViewModel(title: Localization.RevenueCard.title,
29+
leadingTitle: Localization.RevenueCard.leadingTitle,
30+
leadingValue: Constants.placeholderValue,
31+
leadingDelta: Constants.placeholderDelta.string,
32+
leadingDeltaColor: Constants.deltaColor(for: Constants.placeholderDelta.direction),
33+
trailingTitle: Localization.RevenueCard.trailingTitle,
34+
trailingValue: Constants.placeholderValue,
35+
trailingDelta: Constants.placeholderDelta.string,
36+
trailingDeltaColor: Constants.deltaColor(for: Constants.placeholderDelta.direction))
3637

3738
/// Orders Card ViewModel
3839
///
39-
@Published var ordersCard = AnalyticsReportCardViewModel(title: "ORDERS",
40-
leadingTitle: "Total Orders",
41-
leadingValue: "145",
42-
leadingDelta: "+36%",
43-
leadingDeltaColor: .withColorStudio(.green, shade: .shade50),
44-
trailingTitle: "Average Order Value",
45-
trailingValue: "$57,99",
46-
trailingDelta: "-16%",
47-
trailingDeltaColor: .withColorStudio(.red, shade: .shade40))
40+
@Published var ordersCard = AnalyticsReportCardViewModel(title: Localization.OrderCard.title,
41+
leadingTitle: Localization.OrderCard.leadingTitle,
42+
leadingValue: Constants.placeholderValue,
43+
leadingDelta: Constants.placeholderDelta.string,
44+
leadingDeltaColor: Constants.deltaColor(for: Constants.placeholderDelta.direction),
45+
trailingTitle: Localization.OrderCard.trailingTitle,
46+
trailingValue: Constants.placeholderValue,
47+
trailingDelta: Constants.placeholderDelta.string,
48+
trailingDeltaColor: Constants.deltaColor(for: Constants.placeholderDelta.direction))
4849

4950
// MARK: Private data
5051

@@ -97,3 +98,33 @@ private extension AnalyticsHubViewModel {
9798
}
9899
}
99100
}
101+
102+
// MARK: - Constants
103+
private extension AnalyticsHubViewModel {
104+
enum Constants {
105+
static let placeholderValue = "-"
106+
static let placeholderDelta = StatsDataTextFormatter.createDeltaPercentage(from: 0.0, to: 0.0)
107+
static func deltaColor(for direction: StatsDataTextFormatter.DeltaPercentage.Direction) -> UIColor {
108+
switch direction {
109+
case .positive:
110+
return .withColorStudio(.green, shade: .shade50)
111+
case .negative, .zero:
112+
return .withColorStudio(.red, shade: .shade40)
113+
}
114+
}
115+
}
116+
117+
enum Localization {
118+
enum RevenueCard {
119+
static let title = NSLocalizedString("REVENUE", comment: "Title for revenue analytics section in the Analytics Hub")
120+
static let leadingTitle = NSLocalizedString("Total Sales", comment: "Label for total sales (gross revenue) in the Analytics Hub")
121+
static let trailingTitle = NSLocalizedString("Net Sales", comment: "Label for net sales (net revenue) in the Analytics Hub")
122+
}
123+
124+
enum OrderCard {
125+
static let title = NSLocalizedString("ORDERS", comment: "Title for order analytics section in the Analytics Hub")
126+
static let leadingTitle = NSLocalizedString("Total Orders", comment: "Label for total number of orders in the Analytics Hub")
127+
static let trailingTitle = NSLocalizedString("Average Order Value", comment: "Label for average value of orders in the Analytics Hub")
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)