From 604b8a0659a0394e5334caf17c3b1a8a85a1c2f0 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Wed, 23 Nov 2022 13:30:37 +0000 Subject: [PATCH 1/2] Add fake order stats for configuring Analytics cards --- .../Analytics Hub/AnalyticsHubViewModel.swift | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModel.swift b/WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModel.swift index 45dc42586be..d7d22ba755e 100644 --- a/WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModel.swift @@ -1,4 +1,5 @@ import Foundation +import Yosemite /// Main View Model for the Analytics Hub. /// @@ -27,4 +28,56 @@ final class AnalyticsHubViewModel: ObservableObject { trailingValue: "$57,99", trailingDelta: "-16%", trailingDeltaColor: .withColorStudio(.red, shade: .shade40)) + + // MARK: Private data + + /// Order stats for the current selected time period + /// + @Published private var currentOrderStats: OrderStatsV4 = { + fakeOrderStats(with: fakeCurrentOrderTotals()) + }() + + /// Order stats for the previous time period (for comparison) + /// + @Published private var previousOrderStats: OrderStatsV4 = { + fakeOrderStats(with: fakePreviousOrderTotals()) + }() +} + +// MARK: - Fake data + +/// Extension with fake data. This can be removed once we fetch real data from the API. +/// +private extension AnalyticsHubViewModel { + static func fakeCurrentOrderTotals() -> OrderStatsV4Totals { + OrderStatsV4Totals(totalOrders: 3, + totalItemsSold: 5, + grossRevenue: 800, + couponDiscount: 0, + totalCoupons: 0, + refunds: 0, + taxes: 0, + shipping: 0, + netRevenue: 800, + totalProducts: 2, + averageOrderValue: 266) + } + + static func fakePreviousOrderTotals() -> OrderStatsV4Totals { + OrderStatsV4Totals(totalOrders: 2, + totalItemsSold: 8, + grossRevenue: 1000, + couponDiscount: 0, + totalCoupons: 0, + refunds: 0, + taxes: 0, + shipping: 0, + netRevenue: 900, + totalProducts: 2, + averageOrderValue: 500) + } + + static func fakeOrderStats(with totals: OrderStatsV4Totals) -> OrderStatsV4 { + OrderStatsV4(siteID: 12345, granularity: .daily, totals: totals, intervals: []) + } } From 5bfcbed366e2ca4518db5d16b78cba0d8d004214 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Wed, 23 Nov 2022 15:32:02 +0000 Subject: [PATCH 2/2] Initialize order stats properties with nil values --- .../Analytics Hub/AnalyticsHubViewModel.swift | 46 +------------------ 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModel.swift b/WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModel.swift index d7d22ba755e..98386dfbc63 100644 --- a/WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Dashboard/Analytics Hub/AnalyticsHubViewModel.swift @@ -33,51 +33,9 @@ final class AnalyticsHubViewModel: ObservableObject { /// Order stats for the current selected time period /// - @Published private var currentOrderStats: OrderStatsV4 = { - fakeOrderStats(with: fakeCurrentOrderTotals()) - }() + @Published private var currentOrderStats: OrderStatsV4? = nil /// Order stats for the previous time period (for comparison) /// - @Published private var previousOrderStats: OrderStatsV4 = { - fakeOrderStats(with: fakePreviousOrderTotals()) - }() -} - -// MARK: - Fake data - -/// Extension with fake data. This can be removed once we fetch real data from the API. -/// -private extension AnalyticsHubViewModel { - static func fakeCurrentOrderTotals() -> OrderStatsV4Totals { - OrderStatsV4Totals(totalOrders: 3, - totalItemsSold: 5, - grossRevenue: 800, - couponDiscount: 0, - totalCoupons: 0, - refunds: 0, - taxes: 0, - shipping: 0, - netRevenue: 800, - totalProducts: 2, - averageOrderValue: 266) - } - - static func fakePreviousOrderTotals() -> OrderStatsV4Totals { - OrderStatsV4Totals(totalOrders: 2, - totalItemsSold: 8, - grossRevenue: 1000, - couponDiscount: 0, - totalCoupons: 0, - refunds: 0, - taxes: 0, - shipping: 0, - netRevenue: 900, - totalProducts: 2, - averageOrderValue: 500) - } - - static func fakeOrderStats(with totals: OrderStatsV4Totals) -> OrderStatsV4 { - OrderStatsV4(siteID: 12345, granularity: .daily, totals: totals, intervals: []) - } + @Published private var previousOrderStats: OrderStatsV4? = nil }