Skip to content

Commit 4076374

Browse files
authored
Merge pull request #8159 from woocommerce/issue/8144-create-date-range-section
Analytics Hub: Create date range section
2 parents 4bfdf59 + a29e771 commit 4076374

File tree

7 files changed

+121
-6
lines changed

7 files changed

+121
-6
lines changed

WooCommerce/Classes/Extensions/UIImage+Woo.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,12 @@ extension UIImage {
11131113
static var jetpackSetupInterruptedImage: UIImage {
11141114
UIImage(named: "woo-jetpack-setup-interrupted")!
11151115
}
1116+
1117+
/// Calendar Icon
1118+
///
1119+
static var calendar: UIImage {
1120+
return UIImage.gridicon(.calendar)
1121+
}
11161122
}
11171123

11181124
private extension UIImage {

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,17 @@ struct AnalyticsHubView: View {
2727

2828
var body: some View {
2929
ScrollView {
30-
VStack(alignment: .leading, spacing: Layout.vertialSpacing) {
30+
VStack(alignment: .leading, spacing: Layout.verticalSpacing) {
3131
VStack(spacing: Layout.dividerSpacing) {
3232
Divider()
33-
Text("Placeholder for Time Range Selection")
34-
.padding(.leading)
33+
34+
AnalyticsTimeRangeCard(viewModel: viewModel.timeRangeCard)
3535
.padding(.horizontal, insets: safeAreaInsets)
36-
.frame(maxWidth: .infinity, minHeight: 84, alignment: .leading)
3736
.background(Color(uiColor: .listForeground))
3837

3938
Divider()
4039
}
4140

42-
4341
VStack(spacing: Layout.dividerSpacing) {
4442
Divider()
4543

@@ -78,7 +76,7 @@ private extension AnalyticsHubView {
7876
}
7977

8078
struct Layout {
81-
static let vertialSpacing: CGFloat = 24.0
79+
static let verticalSpacing: CGFloat = 24.0
8280
static let dividerSpacing: CGFloat = .zero
8381
}
8482
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ final class AnalyticsHubViewModel: ObservableObject {
4747
trailingDelta: Constants.placeholderDelta.string,
4848
trailingDeltaColor: Constants.deltaColor(for: Constants.placeholderDelta.direction))
4949

50+
/// Time Range ViewModel
51+
///
52+
@Published var timeRangeCard = AnalyticsTimeRangeCardViewModel(selectedRangeTitle: "Year to Date",
53+
currentRangeSubtitle: "Jan 1 - Nov 23, 2022",
54+
previousRangeSubtitle: "Jan 1 - Nov 23, 2021")
55+
5056
// MARK: Private data
5157

5258
/// Order stats for the current selected time period
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import SwiftUI
2+
3+
/// Resuable Time Range card made for the Analytics Hub.
4+
///
5+
struct AnalyticsTimeRangeCard: View {
6+
7+
let timeRangeTitle: String
8+
let currentRangeDescription: String
9+
let previousRangeDescription: String
10+
11+
var body: some View {
12+
VStack(alignment: .leading, spacing: Layout.verticalSpacing) {
13+
HStack {
14+
Image(uiImage: .calendar)
15+
.padding()
16+
.background(Circle().foregroundColor(Color(.systemGray6)))
17+
VStack(alignment: .leading, spacing: .zero) {
18+
Text(timeRangeTitle)
19+
.foregroundColor(Color(.text))
20+
.subheadlineStyle()
21+
Text(currentRangeDescription)
22+
.bold()
23+
}
24+
.padding(.leading)
25+
.frame(maxWidth: .infinity, alignment: .leading)
26+
}
27+
.padding(.leading)
28+
29+
Divider()
30+
31+
BoldableTextView(Localization.comparisonHeaderTextWith(previousRangeDescription))
32+
.padding(.leading)
33+
.frame(maxWidth: .infinity, alignment: .leading)
34+
.calloutStyle()
35+
}
36+
.padding([.top, .bottom])
37+
}
38+
}
39+
40+
// MARK: Constants
41+
private extension AnalyticsTimeRangeCard {
42+
enum Layout {
43+
static let verticalSpacing: CGFloat = 16
44+
}
45+
46+
enum Localization {
47+
static let previousRangeComparisonContent = NSLocalizedString(
48+
"Compared to **%1$@**",
49+
comment: "Subtitle describing the previous analytics period under comparison. E.g. Compared to Oct 1 - 22, 2022"
50+
)
51+
52+
static func comparisonHeaderTextWith(_ rangeDescription: String) -> String {
53+
return String.localizedStringWithFormat(Localization.previousRangeComparisonContent, rangeDescription)
54+
}
55+
}
56+
}
57+
58+
// MARK: Previews
59+
struct TimeRangeCard_Previews: PreviewProvider {
60+
static var previews: some View {
61+
AnalyticsTimeRangeCard(timeRangeTitle: "Month to Date",
62+
currentRangeDescription: "Nov 1 - 23, 2022",
63+
previousRangeDescription: "Oct 1 - 23, 2022")
64+
}
65+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Foundation
2+
3+
/// Analytics Hub Time Range Card ViewModel.
4+
/// Used to transmit analytics time range data.
5+
///
6+
struct AnalyticsTimeRangeCardViewModel {
7+
/// Time Range Title.
8+
///
9+
let selectedRangeTitle: String
10+
11+
/// Current Range Subtitle.
12+
///
13+
let currentRangeSubtitle: String
14+
15+
/// Previous Range Subtitle.
16+
///
17+
let previousRangeSubtitle: String
18+
}
19+
20+
/// Convenience extension to create an `AnalyticsTimeRangeCard` from a view model.
21+
///
22+
extension AnalyticsTimeRangeCard {
23+
init(viewModel: AnalyticsTimeRangeCardViewModel) {
24+
self.timeRangeTitle = viewModel.selectedRangeTitle
25+
self.currentRangeDescription = viewModel.currentRangeSubtitle
26+
self.previousRangeDescription = viewModel.previousRangeSubtitle
27+
}
28+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,11 +1336,13 @@
13361336
B5FD110E21D3CB8500560344 /* OrderTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5FD110D21D3CB8500560344 /* OrderTableViewCell.xib */; };
13371337
B5FD111221D3CE7700560344 /* NewNoteViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5FD111121D3CE7700560344 /* NewNoteViewController.xib */; };
13381338
B5FD111621D3F13700560344 /* BordersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FD111521D3F13700560344 /* BordersView.swift */; };
1339+
B60B5026292D308A00178C26 /* AnalyticsTimeRangeCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = B60B5025292D308A00178C26 /* AnalyticsTimeRangeCard.swift */; };
13391340
B622BC74289CF19400B10CEC /* WaitingTimeTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B622BC73289CF19400B10CEC /* WaitingTimeTrackerTests.swift */; };
13401341
B626C71B287659D60083820C /* OrderCustomFieldsDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = B626C71A287659D60083820C /* OrderCustomFieldsDetails.swift */; };
13411342
B63AAF4B254AD2C6000B28A2 /* URL+SurveyViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B63AAF4A254AD2C6000B28A2 /* URL+SurveyViewControllerTests.swift */; };
13421343
B651474527D644FF00C9C4E6 /* CustomerNoteSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = B651474427D644FF00C9C4E6 /* CustomerNoteSection.swift */; };
13431344
B687940C27699D420092BCA0 /* RefundFeesCalculationUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = B687940B27699D410092BCA0 /* RefundFeesCalculationUseCase.swift */; };
1345+
B6A10E9C292E5DEE00790797 /* AnalyticsTimeRangeCardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6A10E9B292E5DEE00790797 /* AnalyticsTimeRangeCardViewModel.swift */; };
13441346
B6C838DE28793B3A003AB786 /* OrderCustomFieldsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6C838DD28793B3A003AB786 /* OrderCustomFieldsViewModel.swift */; };
13451347
B6E851F3276320C70041D1BA /* RefundFeesDetailsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6E851F2276320C70041D1BA /* RefundFeesDetailsViewModel.swift */; };
13461348
B6E851F5276330200041D1BA /* RefundFeesDetailsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6E851F4276330200041D1BA /* RefundFeesDetailsTableViewCell.swift */; };
@@ -3322,11 +3324,13 @@
33223324
B5FD110D21D3CB8500560344 /* OrderTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = OrderTableViewCell.xib; sourceTree = "<group>"; };
33233325
B5FD111121D3CE7700560344 /* NewNoteViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewNoteViewController.xib; sourceTree = "<group>"; };
33243326
B5FD111521D3F13700560344 /* BordersView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BordersView.swift; sourceTree = "<group>"; };
3327+
B60B5025292D308A00178C26 /* AnalyticsTimeRangeCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsTimeRangeCard.swift; sourceTree = "<group>"; };
33253328
B622BC73289CF19400B10CEC /* WaitingTimeTrackerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaitingTimeTrackerTests.swift; sourceTree = "<group>"; };
33263329
B626C71A287659D60083820C /* OrderCustomFieldsDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderCustomFieldsDetails.swift; sourceTree = "<group>"; };
33273330
B63AAF4A254AD2C6000B28A2 /* URL+SurveyViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+SurveyViewControllerTests.swift"; sourceTree = "<group>"; };
33283331
B651474427D644FF00C9C4E6 /* CustomerNoteSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerNoteSection.swift; sourceTree = "<group>"; };
33293332
B687940B27699D410092BCA0 /* RefundFeesCalculationUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundFeesCalculationUseCase.swift; sourceTree = "<group>"; };
3333+
B6A10E9B292E5DEE00790797 /* AnalyticsTimeRangeCardViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsTimeRangeCardViewModel.swift; sourceTree = "<group>"; };
33303334
B6C838DD28793B3A003AB786 /* OrderCustomFieldsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderCustomFieldsViewModel.swift; sourceTree = "<group>"; };
33313335
B6E851F2276320C70041D1BA /* RefundFeesDetailsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundFeesDetailsViewModel.swift; sourceTree = "<group>"; };
33323336
B6E851F4276330200041D1BA /* RefundFeesDetailsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundFeesDetailsTableViewCell.swift; sourceTree = "<group>"; };
@@ -5271,6 +5275,8 @@
52715275
26E7EE69292D688900793045 /* AnalyticsHubViewModel.swift */,
52725276
2647F7B9292BE2F900D59FDF /* AnalyticsReportCard.swift */,
52735277
26E7EE6B292D894100793045 /* AnalyticsReportCardViewModel.swift */,
5278+
B60B5025292D308A00178C26 /* AnalyticsTimeRangeCard.swift */,
5279+
B6A10E9B292E5DEE00790797 /* AnalyticsTimeRangeCardViewModel.swift */,
52745280
);
52755281
path = "Analytics Hub";
52765282
sourceTree = "<group>";
@@ -9879,6 +9885,7 @@
98799885
31F92DE125E85F6A00DE04DF /* ConnectedReaderTableViewCell.swift in Sources */,
98809886
26C6E8E026E2B7BD00C7BB0F /* CountrySelectorViewModel.swift in Sources */,
98819887
0285BF7022FBD91C003A2525 /* TopPerformersSectionHeaderView.swift in Sources */,
9888+
B60B5026292D308A00178C26 /* AnalyticsTimeRangeCard.swift in Sources */,
98829889
E138D4FC269EEAFE006EA5C6 /* InPersonPaymentsViewModel.swift in Sources */,
98839890
039D948F276113490044EF38 /* UIView+SuperviewConstraints.swift in Sources */,
98849891
D8736B5322EF4F5900A14A29 /* NotificationsBadgeController.swift in Sources */,
@@ -10726,6 +10733,7 @@
1072610733
31E6F21F26B3577800227E6F /* CardReaderConnectionController.swift in Sources */,
1072710734
02ADC7CC239762E0008D4BED /* PaginatedListSelectorViewProperties.swift in Sources */,
1072810735
03FBDAF2263EE47C00ACE257 /* CouponListViewModel.swift in Sources */,
10736+
B6A10E9C292E5DEE00790797 /* AnalyticsTimeRangeCardViewModel.swift in Sources */,
1072910737
26CCBE0B2523B3650073F94D /* RefundProductsTotalTableViewCell.swift in Sources */,
1073010738
0229ED00258767BC00C336F8 /* ShippingLabelPrintingStepContentView.swift in Sources */,
1073110739
D8EE9698264D3CCB0033B2F9 /* ReceiptViewModel.swift in Sources */,

WooCommerce/WooCommerceTests/Extensions/IconsTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,4 +712,8 @@ final class IconsTests: XCTestCase {
712712
func test_jetpackSetupInterruptedImage_is_not_nil() {
713713
XCTAssertNotNil(UIImage.jetpackSetupInterruptedImage)
714714
}
715+
716+
func test_calendar_icon_is_not_nil() {
717+
XCTAssertNotNil(UIImage.calendar)
718+
}
715719
}

0 commit comments

Comments
 (0)