Skip to content

Commit a1bfa14

Browse files
committed
Remove out of context changes
1 parent 74f96ae commit a1bfa14

File tree

11 files changed

+79
-157
lines changed

11 files changed

+79
-157
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class AnalyticsHubViewModel: ObservableObject {
1515
init(siteID: Int64,
1616
statsTimeRange: StatsTimeRangeV4,
1717
stores: StoresManager = ServiceLocator.stores) {
18-
let selectedType = AnalyticsHubTimeRangeSelectionType(statsTimeRange)
18+
let selectedType = AnalyticsHubTimeRangeSelection.SelectionType(statsTimeRange)
1919
let timeRangeSelection = AnalyticsHubTimeRangeSelection(selectionType: selectedType)
2020

2121
self.siteID = siteID
@@ -41,7 +41,7 @@ final class AnalyticsHubViewModel: ObservableObject {
4141

4242
/// Time Range Selection Type
4343
///
44-
@Published var timeRangeSelectionType: AnalyticsHubTimeRangeSelectionType
44+
@Published var timeRangeSelectionType: AnalyticsHubTimeRangeSelection.SelectionType
4545

4646
/// Time Range ViewModel
4747
///

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ struct AnalyticsTimeRangeCard: View {
77
let timeRangeTitle: String
88
let currentRangeDescription: String
99
let previousRangeDescription: String
10-
@Binding var selectionType: AnalyticsHubTimeRangeSelectionType
10+
@Binding var selectionType: AnalyticsHubTimeRangeSelection.SelectionType
1111

1212
@State private var showTimeRangeSelectionView: Bool = false
1313

14-
init(viewModel: AnalyticsTimeRangeCardViewModel, selectionType: Binding<AnalyticsHubTimeRangeSelectionType>) {
14+
init(viewModel: AnalyticsTimeRangeCardViewModel, selectionType: Binding<AnalyticsHubTimeRangeSelection.SelectionType>) {
1515
self.timeRangeTitle = viewModel.selectedRangeTitle
1616
self.currentRangeDescription = viewModel.currentRangeSubtitle
1717
self.previousRangeDescription = viewModel.previousRangeSubtitle
@@ -22,7 +22,7 @@ struct AnalyticsTimeRangeCard: View {
2222
createTimeRangeContent()
2323
.sheet(isPresented: $showTimeRangeSelectionView) {
2424
SelectionList(title: Localization.timeRangeSelectionTitle,
25-
items: AnalyticsHubTimeRangeSelectionType.allCases,
25+
items: AnalyticsHubTimeRangeSelection.SelectionType.allCases,
2626
contentKeyPath: \.description,
2727
selected: $selectionType)
2828
}

WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/Time Range/AnalyticsHubTimeRangeSelection.swift

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import Yosemite
23

34
/// Main source of time ranges of the Analytics Hub, responsible for providing the current and previous dates
45
/// for a given Date and range Type alongside their UI descriptions
@@ -9,7 +10,6 @@ public class AnalyticsHubTimeRangeSelection {
910
private let formattedCurrentRangeText: String?
1011
private let formattedPreviousRangeText: String?
1112
let rangeSelectionDescription: String
12-
1313
/// Provide a date description of the current time range set internally.
1414
/// - Returns the Time range in a UI friendly format. If the current time range is not available,
1515
/// then returns an presentable error message.
@@ -19,7 +19,6 @@ public class AnalyticsHubTimeRangeSelection {
1919
}
2020
return currentTimeRangeDescription
2121
}
22-
2322
/// Generates a date description of the previous time range set internally.
2423
/// - Returns the Time range in a UI friendly format. If the previous time range is not available,
2524
/// then returns an presentable error message.
@@ -31,24 +30,36 @@ public class AnalyticsHubTimeRangeSelection {
3130
}
3231

3332
//TODO: abandon usage of the ISO 8601 Calendar and build one based on the Site calendar configuration
34-
init(selectionType: AnalyticsHubTimeRangeSelectionType,
33+
init(selectionType: SelectionType,
3534
currentDate: Date = Date(),
3635
timezone: TimeZone = TimeZone.autoupdatingCurrent,
3736
calendar: Calendar = Calendar(identifier: .iso8601)) {
38-
let selectionData = selectionType.mapToRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
37+
var selectionData: AnalyticsHubTimeRangeData
38+
39+
switch selectionType {
40+
case .today:
41+
selectionData = AnalyticsHubDayRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
42+
case .weekToDate:
43+
selectionData = AnalyticsHubWeekRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
44+
case .monthToDate:
45+
selectionData = AnalyticsHubMonthRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
46+
case .yearToDate:
47+
selectionData = AnalyticsHubYearRangeData(referenceDate: currentDate, timezone: timezone, calendar: calendar)
48+
}
49+
3950
let currentTimeRange = selectionData.currentTimeRange
4051
let previousTimeRange = selectionData.previousTimeRange
41-
let simplifiedDescription = selectionType == .today || selectionType == .yesterday
42-
4352
self.currentTimeRange = currentTimeRange
4453
self.previousTimeRange = previousTimeRange
45-
self.rangeSelectionDescription = selectionType.description
54+
55+
let simplifiedDescription = selectionType == .today
4656
self.formattedCurrentRangeText = currentTimeRange?.formatToString(simplified: simplifiedDescription,
4757
timezone: timezone,
4858
calendar: calendar)
4959
self.formattedPreviousRangeText = previousTimeRange?.formatToString(simplified: simplifiedDescription,
5060
timezone: timezone,
5161
calendar: calendar)
62+
self.rangeSelectionDescription = selectionType.description
5263
}
5364

5465
/// Unwrap the generated selected `AnalyticsHubTimeRange` based on the `selectedTimeRange`
@@ -60,7 +71,6 @@ public class AnalyticsHubTimeRangeSelection {
6071
}
6172
return currentTimeRange
6273
}
63-
6474
/// Unwrap the generated previous `AnalyticsHubTimeRange`relative to the selected one
6575
/// based on the `selectedTimeRange` provided during initialization.
6676
/// - throws a `.previousRangeGenerationFailed` error if the unwrap fails.
@@ -72,33 +82,53 @@ public class AnalyticsHubTimeRangeSelection {
7282
}
7383
}
7484

75-
// MARK: - Data creation utility
76-
private extension AnalyticsHubTimeRangeSelectionType {
77-
func mapToRangeData(referenceDate: Date, timezone: TimeZone, calendar: Calendar) -> AnalyticsHubTimeRangeData {
78-
switch self {
79-
case .today:
80-
return AnalyticsHubTodayRangeData(referenceDate: referenceDate, timezone: timezone, calendar: calendar)
81-
case .yesterday:
82-
return AnalyticsHubYesterdayRangeData(referenceDate: referenceDate, timezone: timezone, calendar: calendar)
83-
case .weekToDate:
84-
return AnalyticsHubWeekToDateRangeData(referenceDate: referenceDate, timezone: timezone, calendar: calendar)
85-
case .monthToDate:
86-
return AnalyticsHubMonthToDateRangeData(referenceDate: referenceDate, timezone: timezone, calendar: calendar)
87-
case .yearToDate:
88-
return AnalyticsHubYearToDateRangeData(referenceDate: referenceDate, timezone: timezone, calendar: calendar)
85+
// MARK: - Time Range Selection Type
86+
extension AnalyticsHubTimeRangeSelection {
87+
enum SelectionType: CaseIterable {
88+
case today
89+
case weekToDate
90+
case monthToDate
91+
case yearToDate
92+
93+
var description: String {
94+
switch self {
95+
case .today:
96+
return Localization.today
97+
case .weekToDate:
98+
return Localization.weekToDate
99+
case .monthToDate:
100+
return Localization.monthToDate
101+
case .yearToDate:
102+
return Localization.yearToDate
103+
}
104+
}
105+
106+
init(_ statsTimeRange: StatsTimeRangeV4) {
107+
switch statsTimeRange {
108+
case .today:
109+
self = .today
110+
case .thisWeek:
111+
self = .weekToDate
112+
case .thisMonth:
113+
self = .monthToDate
114+
case .thisYear:
115+
self = .yearToDate
116+
}
89117
}
90118
}
91119
}
92-
93120
// MARK: - Constants
94121
extension AnalyticsHubTimeRangeSelection {
95-
96122
enum TimeRangeGeneratorError: Error {
97123
case selectedRangeGenerationFailed
98124
case previousRangeGenerationFailed
99125
}
100126

101127
enum Localization {
128+
static let today = NSLocalizedString("Today", comment: "Title of the Analytics Hub Today's selection range")
129+
static let weekToDate = NSLocalizedString("Week to Date", comment: "Title of the Analytics Hub Week to Date selection range")
130+
static let monthToDate = NSLocalizedString("Month to Date", comment: "Title of the Analytics Hub Month to Date selection range")
131+
static let yearToDate = NSLocalizedString("Year to Date", comment: "Title of the Analytics Hub Year to Date selection range")
102132
static let selectionTitle = NSLocalizedString("Date Range", comment: "Title of the range selection list")
103133
static let noCurrentPeriodAvailable = NSLocalizedString("No current period available",
104134
comment: "A error message when it's not possible to acquire"

WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/Time Range/AnalyticsHubTimeRangeSelectionType.swift

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
struct AnalyticsHubTodayRangeData: AnalyticsHubTimeRangeData {
3+
struct AnalyticsHubDayRangeData: AnalyticsHubTimeRangeData {
44
let currentDateStart: Date?
55
let currentDateEnd: Date?
66
let previousDateStart: Date?
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
struct AnalyticsHubMonthToDateRangeData: AnalyticsHubTimeRangeData {
3+
struct AnalyticsHubMonthRangeData: AnalyticsHubTimeRangeData {
44
let currentDateStart: Date?
55
let currentDateEnd: Date?
66
let previousDateStart: Date?
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
struct AnalyticsHubWeekToDateRangeData: AnalyticsHubTimeRangeData {
3+
struct AnalyticsHubWeekRangeData: AnalyticsHubTimeRangeData {
44
let currentDateStart: Date?
55
let currentDateEnd: Date?
66
let previousDateStart: Date?
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
struct AnalyticsHubYearToDateRangeData: AnalyticsHubTimeRangeData {
3+
struct AnalyticsHubYearRangeData: AnalyticsHubTimeRangeData {
44
let currentDateStart: Date?
55
let currentDateEnd: Date?
66
let previousDateStart: Date?

WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/Time Range/Range Data Generation/AnalyticsHubYesterdayRangeData.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)