File tree Expand file tree Collapse file tree 2 files changed +37
-6
lines changed
WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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:
You can’t perform that action at this time.
0 commit comments