Skip to content

Commit 87a2046

Browse files
authored
Merge pull request #8341 from woocommerce/issue/8189-handle-range-selection-granularity
[Analytics Hub] Handle range selection granularity and interval
2 parents dfa7a73 + 1ca89c2 commit 87a2046

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,11 @@ private extension AnalyticsHubViewModel {
130130
latestDateToInclude: Date,
131131
forceRefresh: Bool) async throws -> OrderStatsV4 {
132132
try await withCheckedThrowingContinuation { continuation in
133-
// TODO: get unit and quantity from the selected period
134-
let unit: StatsGranularityV4 = .daily
135-
let quantity = 31
136-
137133
let action = StatsActionV4.retrieveCustomStats(siteID: siteID,
138-
unit: unit,
134+
unit: timeRangeSelectionType.granularity,
139135
earliestDateToInclude: earliestDateToInclude,
140136
latestDateToInclude: latestDateToInclude,
141-
quantity: quantity,
137+
quantity: timeRangeSelectionType.intervalSize,
142138
forceRefresh: forceRefresh) { result in
143139
continuation.resume(with: result)
144140
}

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,41 @@ extension AnalyticsHubTimeRangeSelection {
104104
}
105105
}
106106

107+
/// The granularity that should be used to request stats from the given SelectedType
108+
///
109+
var granularity: StatsGranularityV4 {
110+
switch self {
111+
case .today, .yesterday:
112+
return .hourly
113+
case .weekToDate, .lastWeek:
114+
return .daily
115+
case .monthToDate, .lastMonth:
116+
return .daily
117+
case .quarterToDate, .lastQuarter:
118+
return .weekly
119+
case .yearToDate, .lastYear:
120+
return .monthly
121+
}
122+
}
123+
124+
/// The response interval size that should be used to request stats from the given SelectedType
125+
/// in order to proper determine the stats charts and changes
126+
///
127+
var intervalSize: Int {
128+
switch self {
129+
case .today, .yesterday:
130+
return 24
131+
case .weekToDate, .lastWeek:
132+
return 7
133+
case .monthToDate, .lastMonth:
134+
return 31
135+
case .quarterToDate, .lastQuarter:
136+
return 13
137+
case .yearToDate, .lastYear:
138+
return 12
139+
}
140+
}
141+
107142
init(_ statsTimeRange: StatsTimeRangeV4) {
108143
switch statsTimeRange {
109144
case .today:

0 commit comments

Comments
 (0)