From 9c54c28165cb0ccbd18cad7a6c9e74a415c3fedd Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Mon, 22 Apr 2024 17:02:02 -0400 Subject: [PATCH 1/8] Add Subscriber chart Shows subscriber growth over time --- Podfile | 2 +- Podfile.lock | 8 +- .../Stats/Helpers/StatSection.swift | 4 + .../Stats/SiteStatsTableViewCells.swift | 27 +++++++ .../Subscribers/StatsSubscribersCache.swift | 4 + .../StatsSubscribersChartCell.swift | 58 +++++++++++++++ .../Subscribers/StatsSubscribersChartCell.xib | 39 ++++++++++ .../StatsSubscribersLineChart.swift | 36 +++++++++ .../Subscribers/StatsSubscribersStore.swift | 31 ++++++++ .../StatsSubscribersViewController.swift | 1 + .../StatsSubscribersViewModel.swift | 73 +++++++++++++------ WordPress/WordPress.xcodeproj/project.pbxproj | 18 +++++ .../StatsSubscribersViewModelTests.swift | 34 ++++++++- 13 files changed, 306 insertions(+), 29 deletions(-) create mode 100644 WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.swift create mode 100644 WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.xib create mode 100644 WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersLineChart.swift diff --git a/Podfile b/Podfile index e22a398d7f77..53eaf4d457b1 100644 --- a/Podfile +++ b/Podfile @@ -56,7 +56,7 @@ end def wordpress_kit # pod 'WordPressKit', '~> 17.0.0' - pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '1a0955f6cbc20b258f82be7887d6e8e56a6fbce3' + pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: 'a7ccb2e6810eb9d546f9a85cd30057be88a9760b' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: '' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: '' # pod 'WordPressKit', path: '../WordPressKit-iOS' diff --git a/Podfile.lock b/Podfile.lock index d43866c313b0..85f58742392c 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -121,7 +121,7 @@ DEPENDENCIES: - SwiftLint (= 0.54.0) - WordPress-Editor-iOS (~> 1.19.11) - WordPressAuthenticator (>= 9.0.8, ~> 9.0) - - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `1a0955f6cbc20b258f82be7887d6e8e56a6fbce3`) + - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `a7ccb2e6810eb9d546f9a85cd30057be88a9760b`) - WordPressShared (from `https://github.com/wordpress-mobile/WordPress-iOS-Shared.git`, commit `688ee5e4efddc1fc23626626ef17b7e929bdafb0`) - WordPressUI (~> 1.16) - ZendeskSupportSDK (= 5.3.0) @@ -177,7 +177,7 @@ EXTERNAL SOURCES: Gutenberg: :podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.117.0.podspec WordPressKit: - :commit: 1a0955f6cbc20b258f82be7887d6e8e56a6fbce3 + :commit: a7ccb2e6810eb9d546f9a85cd30057be88a9760b :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -188,7 +188,7 @@ CHECKOUT OPTIONS: :git: https://github.com/wordpress-mobile/FSInteractiveMap.git :tag: 0.2.0 WordPressKit: - :commit: 1a0955f6cbc20b258f82be7887d6e8e56a6fbce3 + :commit: a7ccb2e6810eb9d546f9a85cd30057be88a9760b :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -239,6 +239,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced -PODFILE CHECKSUM: 2ee1661530a005e266006f993a65e84299509019 +PODFILE CHECKSUM: 0733776e0690892a2d9f7dab87c32abd8f2c8567 COCOAPODS: 1.15.2 diff --git a/WordPress/Classes/ViewRelated/Stats/Helpers/StatSection.swift b/WordPress/Classes/ViewRelated/Stats/Helpers/StatSection.swift index 092bbf09e044..b23c212fa67e 100644 --- a/WordPress/Classes/ViewRelated/Stats/Helpers/StatSection.swift +++ b/WordPress/Classes/ViewRelated/Stats/Helpers/StatSection.swift @@ -34,6 +34,7 @@ case postStatsMonthsYears case postStatsAverageViews case postStatsRecentWeeks + case subscribersChart case subscribersEmailsSummary static let allInsights: [StatSection] = [ @@ -143,6 +144,8 @@ return PostStatsHeaders.averageViewsPerDay case .postStatsRecentWeeks: return PostStatsHeaders.recentWeeks + case .subscribersChart: + return SubscribersHeaders.chart case .subscribersEmailsSummary: return SubscribersHeaders.emailsSummaryStats default: @@ -430,6 +433,7 @@ } struct SubscribersHeaders { + static let chart = NSLocalizedString("stats.subscribers.chart.title", value: "Subscribers", comment: "Stats 'Subscribers' card header, contains chart") static let emailsSummaryStats = NSLocalizedString("stats.subscribers.emailsSummaryCard.title", value: "Emails", comment: "Stats 'Emails' card header") } diff --git a/WordPress/Classes/ViewRelated/Stats/SiteStatsTableViewCells.swift b/WordPress/Classes/ViewRelated/Stats/SiteStatsTableViewCells.swift index 0025c010efab..d88c15216578 100644 --- a/WordPress/Classes/ViewRelated/Stats/SiteStatsTableViewCells.swift +++ b/WordPress/Classes/ViewRelated/Stats/SiteStatsTableViewCells.swift @@ -77,6 +77,33 @@ struct ViewsVisitorsRow: StatsHashableImmuTableRow { } } +struct SubscriberChartRow: StatsHashableImmuTableRow { + typealias CellType = StatsSubscribersChartCell + + static let cell: ImmuTableCell = { + return ImmuTableCell.nib(CellType.defaultNib, CellType.self) + }() + + let action: ImmuTableAction? = nil + let chartData: LineChartDataConvertible + let chartStyling: LineChartStyling + let xAxisDates: [Date] + let statSection: StatSection? + + static func == (lhs: SubscriberChartRow, rhs: SubscriberChartRow) -> Bool { + return lhs.xAxisDates == rhs.xAxisDates + } + + func configureCell(_ cell: UITableViewCell) { + + guard let cell = cell as? CellType else { + return + } + + cell.configure(row: self) + } +} + struct CellHeaderRow: StatsHashableImmuTableRow { typealias CellType = StatsCellHeader diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersCache.swift b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersCache.swift index db11cb0a3c51..bc3b009534ac 100644 --- a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersCache.swift +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersCache.swift @@ -26,5 +26,9 @@ final class StatsSubscribersCache { static func emailsSummary(quantity: Int, sortField: String, sortOrder: String, siteId: NSNumber) -> CacheKey { return .init(record: .subscribersEmailsSummary, key: "\(quantity) \(sortField) \(sortOrder)", siteID: siteId) } + + static func chartSummary(unit: String, siteId: NSNumber) -> CacheKey { + return .init(record: .subscribersChart, key: unit, siteID: siteId) + } } } diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.swift b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.swift new file mode 100644 index 000000000000..9c34e07f54c1 --- /dev/null +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.swift @@ -0,0 +1,58 @@ + +import UIKit + +class StatsSubscribersChartCell: StatsBaseCell, NibLoadable { + private typealias Style = WPStyleGuide.Stats + + @IBOutlet weak var chartView: UIView! + + private var chartData: LineChartDataConvertible! + private var chartStyling: LineChartStyling! + private var xAxisDates: [Date]! + + override func awakeFromNib() { + super.awakeFromNib() + + Style.configureCell(self) + } + + func configure(row: SubscriberChartRow) { + + statSection = .subscribersChart + + self.chartData = row.chartData + self.chartStyling = row.chartStyling + self.xAxisDates = row.xAxisDates + + configureChartView() + } +} + +private extension StatsSubscribersChartCell { + + func configureChartView() { + let configuration = StatsLineChartConfiguration(data: chartData, + styling: chartStyling, + analyticsGranularity: .days, + indexToHighlight: 0, + xAxisDates: xAxisDates) + let lineChartView = StatsLineChartView(configuration: configuration) + + resetChartContainerView() + chartView.addSubview(lineChartView) + chartView.accessibilityElements = [lineChartView] + + NSLayoutConstraint.activate([ + lineChartView.leadingAnchor.constraint(equalTo: chartView.leadingAnchor), + lineChartView.trailingAnchor.constraint(equalTo: chartView.trailingAnchor), + lineChartView.topAnchor.constraint(equalTo: chartView.topAnchor), + lineChartView.bottomAnchor.constraint(equalTo: chartView.bottomAnchor) + ]) + } + + func resetChartContainerView() { + for subview in chartView.subviews { + subview.removeFromSuperview() + } + } +} diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.xib b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.xib new file mode 100644 index 000000000000..dd0cad1996d5 --- /dev/null +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.xib @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersLineChart.swift b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersLineChart.swift new file mode 100644 index 000000000000..5a0eb66dcdda --- /dev/null +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersLineChart.swift @@ -0,0 +1,36 @@ +import Foundation +import DGCharts + +private struct SubscriberLineChartData: LineChartDataConvertible { + let accessibilityDescription: String + let lineChartData: LineChartData +} + +class StatsSubscribersLineChart { + + let lineChartData: LineChartDataConvertible + let lineChartStyling: LineChartStyling + + init(counts: [Int]) { + let chartEntries = counts.enumerated().map { index, count in + ChartDataEntry(x: Double(index), y: Double(count)) + } + let dataSet = LineChartDataSet(entries: chartEntries) + let chartData = LineChartData(dataSets: [dataSet]) + lineChartData = SubscriberLineChartData(accessibilityDescription: "Subscriber Charts", lineChartData: chartData) + lineChartStyling = SubscribersLineChartStyling() + } +} + +// MARK: - StatsSubscribersLineChartStyling + +private struct SubscribersLineChartStyling: LineChartStyling { + let primaryLineColor: UIColor = UIColor(light: .muriel(name: .blue, .shade50), dark: .muriel(name: .blue, .shade50)) + let secondaryLineColor: UIColor? = nil + let primaryHighlightColor: UIColor? = UIColor(red: 209.0/255.0, green: 209.0/255.0, blue: 214.0/255.0, alpha: 1.0) + let labelColor: UIColor = UIColor(light: .secondaryLabel, dark: .tertiaryLabel) + let legendColor: UIColor? = nil + let legendTitle: String? = nil + let lineColor: UIColor = .neutral(.shade5) + let yAxisValueFormatter: AxisValueFormatter = VerticalAxisFormatter() +} diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersStore.swift b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersStore.swift index 0f570b66c8e8..7aea01edc758 100644 --- a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersStore.swift +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersStore.swift @@ -4,7 +4,9 @@ import WordPressKit protocol StatsSubscribersStoreProtocol { var emailsSummary: CurrentValueSubject, Never> { get } + var chartSummary: CurrentValueSubject, Never> { get } func updateEmailsSummary(quantity: Int, sortField: StatsEmailsSummaryData.SortField) + func updateChartSummary() } struct StatsSubscribersStore: StatsSubscribersStoreProtocol { @@ -13,6 +15,7 @@ struct StatsSubscribersStore: StatsSubscribersStoreProtocol { private let statsService: StatsServiceRemoteV2 var emailsSummary: CurrentValueSubject, Never> = .init(.idle) + var chartSummary: CurrentValueSubject, Never> = .init(.idle) init() { self.siteID = SiteStatsInformation.sharedInstance.siteID ?? 0 @@ -48,6 +51,34 @@ struct StatsSubscribersStore: StatsSubscribersStoreProtocol { } } } + + func updateChartSummary() { + guard chartSummary.value != .loading else { return } + + let unit = StatsSubscribersSummaryData.Unit.day + let cacheKey = StatsSubscribersCache.CacheKey.chartSummary(unit: unit.rawValue, siteId: siteID) + let cachedData: StatsSubscribersSummaryData? = cache.getValue(key: cacheKey) + + if let cachedData = cachedData { + self.chartSummary.send(.success(cachedData)) + } else { + chartSummary.send(.loading) + } + + statsService.getSubscribers(unit: unit) { result in + DispatchQueue.main.async { + switch result { + case .success(let data): + cache.setValue(data, key: cacheKey) + self.chartSummary.send(.success(data)) + case .failure: + if cachedData == nil { + self.chartSummary.send(.error) + } + } + } + } + } } extension StatsSubscribersStore { diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewController.swift b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewController.swift index f4b50d0e1c0a..4510cba642a3 100644 --- a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewController.swift +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewController.swift @@ -69,6 +69,7 @@ final class StatsSubscribersViewController: SiteStatsBaseTableViewController { func tableRowTypes() -> [ImmuTableRow.Type] { return [ + SubscriberChartRow.self, TopTotalsPeriodStatsRow.self, StatsGhostTopImmutableRow.self, StatsErrorRow.self diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift index 5d55a741f2bb..9555e5c3dc8f 100644 --- a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift @@ -14,12 +14,19 @@ final class StatsSubscribersViewModel { } func refreshData() { + store.updateChartSummary() store.updateEmailsSummary(quantity: 10, sortField: .postId) } // MARK: - Lifecycle func addObservers() { + Publishers.MergeMany(store.chartSummary) + .removeDuplicates() + .sink { [weak self] _ in + self?.updateTableViewSnapshot() + } + .store(in: &cancellables) Publishers.MergeMany(store.emailsSummary) .removeDuplicates() .sink { [weak self] _ in @@ -37,45 +44,69 @@ final class StatsSubscribersViewModel { private extension StatsSubscribersViewModel { func updateTableViewSnapshot() { - let snapshot = ImmuTableDiffableDataSourceSnapshot.multiSectionSnapshot( - emailsSummaryRows() - ) + let rows: [any StatsHashableImmuTableRow] = [ + chartRow(), + emailsSummaryRow(), + ] + let snapshot = ImmuTableDiffableDataSourceSnapshot.multiSectionSnapshot(rows) + tableViewSnapshot.send(snapshot) } - func loadingRows(_ section: StatSection) -> [any StatsHashableImmuTableRow] { - return [StatsGhostTopImmutableRow(statSection: section)] + func loadingRow(_ section: StatSection) -> any StatsHashableImmuTableRow { + return StatsGhostTopImmutableRow(statSection: section) + } + + func errorRow(_ section: StatSection) -> any StatsHashableImmuTableRow { + return StatsErrorRow(rowStatus: .error, statType: .subscribers, statSection: section) } +} + +// MARK: - Chart - func errorRows(_ section: StatSection) -> [any StatsHashableImmuTableRow] { - return [StatsErrorRow(rowStatus: .error, statType: .subscribers, statSection: section)] +private extension StatsSubscribersViewModel { + func chartRow() -> any StatsHashableImmuTableRow { + switch store.chartSummary.value { + case .loading, .idle: + return loadingRow(.subscribersChart) + case .success(let chartSummary): + let xAxisDates = chartSummary.history.map { $0.date } + let viewsChart = StatsSubscribersLineChart(counts: chartSummary.history.map { $0.count }) + let row = SubscriberChartRow( + chartData: viewsChart.lineChartData, + chartStyling: viewsChart.lineChartStyling, + xAxisDates: xAxisDates, + statSection: .subscribersChart + ) + return row + case .error: + return errorRow(.subscribersChart) + } } } // MARK: - Emails Summary private extension StatsSubscribersViewModel { - func emailsSummaryRows() -> [any StatsHashableImmuTableRow] { + func emailsSummaryRow() -> any StatsHashableImmuTableRow { switch store.emailsSummary.value { case .loading, .idle: - return loadingRows(.subscribersEmailsSummary) + return loadingRow(.subscribersEmailsSummary) case .success(let emailsSummary): - return [ - TopTotalsPeriodStatsRow( - itemSubtitle: Strings.titleColumn, - dataSubtitle: Strings.opensColumn, - secondDataSubtitle: Strings.clicksColumn, - dataRows: emailsSummaryDataRows(emailsSummary), - statSection: .subscribersEmailsSummary, - siteStatsPeriodDelegate: viewMoreDelegate - ) - ] + return TopTotalsPeriodStatsRow( + itemSubtitle: Strings.titleColumn, + dataSubtitle: Strings.opensColumn, + secondDataSubtitle: Strings.clicksColumn, + dataRows: emailsSummaryDataRow(emailsSummary), + statSection: .subscribersEmailsSummary, + siteStatsPeriodDelegate: viewMoreDelegate + ) case .error: - return errorRows(.subscribersEmailsSummary) + return errorRow(.subscribersEmailsSummary) } } - func emailsSummaryDataRows(_ emailsSummary: StatsEmailsSummaryData) -> [StatsTotalRowData] { + func emailsSummaryDataRow(_ emailsSummary: StatsEmailsSummaryData) -> [StatsTotalRowData] { return emailsSummary.posts.map { StatsTotalRowData( name: $0.title, diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 8c2f0f99bd25..0a34d45bd89e 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -2797,6 +2797,12 @@ B026DAB02A96D9E900995410 /* support_chat_error_handler.js in Resources */ = {isa = PBXBuildFile; fileRef = B026DAAF2A96D9E900995410 /* support_chat_error_handler.js */; }; B026DAB12A96D9E900995410 /* support_chat_error_handler.js in Resources */ = {isa = PBXBuildFile; fileRef = B026DAAF2A96D9E900995410 /* support_chat_error_handler.js */; }; B030FE0A27EBF0BC000F6F5E /* SiteCreationIntentTracksEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B030FE0927EBF0BC000F6F5E /* SiteCreationIntentTracksEventTests.swift */; }; + B038A81C2BD70FCA00763731 /* StatsSubscribersChartCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B038A81B2BD70FCA00763731 /* StatsSubscribersChartCell.xib */; }; + B038A81D2BD70FCA00763731 /* StatsSubscribersChartCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B038A81A2BD70FCA00763731 /* StatsSubscribersChartCell.swift */; }; + B038A81E2BD70FCA00763731 /* StatsSubscribersChartCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B038A81A2BD70FCA00763731 /* StatsSubscribersChartCell.swift */; }; + B038A81F2BD70FCA00763731 /* StatsSubscribersChartCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B038A81B2BD70FCA00763731 /* StatsSubscribersChartCell.xib */; }; + B038A8212BD7164F00763731 /* StatsSubscribersLineChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = B038A8202BD7164F00763731 /* StatsSubscribersLineChart.swift */; }; + B038A8222BD7164F00763731 /* StatsSubscribersLineChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = B038A8202BD7164F00763731 /* StatsSubscribersLineChart.swift */; }; B03B9234250BC593000A40AF /* SuggestionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B03B9233250BC593000A40AF /* SuggestionService.swift */; }; B03B9236250BC5FD000A40AF /* Suggestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = B03B9235250BC5FD000A40AF /* Suggestion.swift */; }; B0637527253E7CEC00FD45D2 /* SuggestionsTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0637526253E7CEB00FD45D2 /* SuggestionsTableView.swift */; }; @@ -8171,6 +8177,9 @@ AEE082892681C23C00DCF54B /* GutenbergRefactoredGalleryUploadProcessorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GutenbergRefactoredGalleryUploadProcessorTests.swift; sourceTree = ""; }; B026DAAF2A96D9E900995410 /* support_chat_error_handler.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = support_chat_error_handler.js; sourceTree = ""; }; B030FE0927EBF0BC000F6F5E /* SiteCreationIntentTracksEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteCreationIntentTracksEventTests.swift; sourceTree = ""; }; + B038A81A2BD70FCA00763731 /* StatsSubscribersChartCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsSubscribersChartCell.swift; sourceTree = ""; }; + B038A81B2BD70FCA00763731 /* StatsSubscribersChartCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StatsSubscribersChartCell.xib; sourceTree = ""; }; + B038A8202BD7164F00763731 /* StatsSubscribersLineChart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsSubscribersLineChart.swift; sourceTree = ""; }; B03B9233250BC593000A40AF /* SuggestionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SuggestionService.swift; sourceTree = ""; }; B03B9235250BC5FD000A40AF /* Suggestion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Suggestion.swift; sourceTree = ""; }; B0637526253E7CEB00FD45D2 /* SuggestionsTableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SuggestionsTableView.swift; path = Suggestions/SuggestionsTableView.swift; sourceTree = ""; }; @@ -9921,6 +9930,9 @@ 01011E842BD27E47003B5C2B /* StatsSubscribersViewModel.swift */, 019C5B8C2BD6570D00A69DB0 /* StatsSubscribersStore.swift */, 019C5B932BD6917600A69DB0 /* StatsSubscribersCache.swift */, + B038A81A2BD70FCA00763731 /* StatsSubscribersChartCell.swift */, + B038A81B2BD70FCA00763731 /* StatsSubscribersChartCell.xib */, + B038A8202BD7164F00763731 /* StatsSubscribersLineChart.swift */, ); path = Subscribers; sourceTree = ""; @@ -19819,6 +19831,7 @@ 1761F18226209AEE000815EF /* jetpack-green-icon-app-60x60@3x.png in Resources */, 83317ED92BC71CEB001AD2F4 /* ReaderTagCardCell.xib in Resources */, FE3E83E626A58646008CE851 /* ListSimpleOverlayView.xib in Resources */, + B038A81C2BD70FCA00763731 /* StatsSubscribersChartCell.xib in Resources */, 401A3D022027DBD80099A127 /* PluginListCell.xib in Resources */, 17222D83261DDDF90047B163 /* celadon-classic-icon-app-60x60@2x.png in Resources */, 981C34912183871200FC2683 /* SiteStatsDashboard.storyboard in Resources */, @@ -20301,6 +20314,7 @@ F46597B128E6605E00D5F49A /* neu-green-icon-app-76@2x.png in Resources */, F41E4E9728F20802001880C6 /* white-on-pink-icon-app-76@2x.png in Resources */, F41E4EB828F225DB001880C6 /* stroke-dark-icon-app-60@3x.png in Resources */, + B038A81F2BD70FCA00763731 /* StatsSubscribersChartCell.xib in Resources */, F46597EA28E6698D00D5F49A /* spectrum-on-black-icon-app-76.png in Resources */, 98A047762821D069001B4E2D /* BloggingPromptsViewController.storyboard in Resources */, F41E4ECF28F23E00001880C6 /* green-on-white-icon-app-83.5@2x.png in Resources */, @@ -21931,6 +21945,7 @@ C7AFF87C283D5CF4000E01DF /* QRLoginVerifyCoordinator.swift in Sources */, FA25FA212609AA9C0005E08F /* AppConfiguration.swift in Sources */, 83EF3D7B2937D703000AF9BF /* SharedDataIssueSolver.swift in Sources */, + B038A81D2BD70FCA00763731 /* StatsSubscribersChartCell.swift in Sources */, 436D55DB210F862A00CEAA33 /* NibReusable.swift in Sources */, F49B9A09293A3243000CEFCE /* MigrationEvent.swift in Sources */, 98563DDD21BF30C40006F5E9 /* TabbedTotalsCell.swift in Sources */, @@ -23262,6 +23277,7 @@ 98E14A3C27C9712D007B0896 /* NotificationCommentDetailViewController.swift in Sources */, 9A8ECE122254A3260043C8DA /* JetpackRemoteInstallState.swift in Sources */, 40D7823A206AEA880015A3A1 /* Scheduler.swift in Sources */, + B038A8212BD7164F00763731 /* StatsSubscribersLineChart.swift in Sources */, 436D562E2117347C00CEAA33 /* RegisterDomainDetailsViewModel+RowDefinitions.swift in Sources */, E6FACB1E1EC675E300284AC7 /* GravatarProfile.swift in Sources */, D8212CB720AA7703008E8AE8 /* ReaderShareAction.swift in Sources */, @@ -24991,6 +25007,7 @@ FABB22CF2602FC2C00C8785C /* AssembledSiteView.swift in Sources */, FABB22D02602FC2C00C8785C /* ReaderTopicService+FollowedInterests.swift in Sources */, FABB22D12602FC2C00C8785C /* ReaderRecommendedSiteCardCell.swift in Sources */, + B038A8222BD7164F00763731 /* StatsSubscribersLineChart.swift in Sources */, FABB22D22602FC2C00C8785C /* PostEditorState.swift in Sources */, FABB22D32602FC2C00C8785C /* UICollectionViewCell+Tint.swift in Sources */, FABB22D42602FC2C00C8785C /* ManagedPerson+CoreDataProperties.swift in Sources */, @@ -25610,6 +25627,7 @@ 0CED200D2B68425A00E6DD52 /* WebKitView.swift in Sources */, FABB247F2602FC2C00C8785C /* StockPhotosPageable.swift in Sources */, FABB24802602FC2C00C8785C /* JetpackRestoreStatusViewController.swift in Sources */, + B038A81E2BD70FCA00763731 /* StatsSubscribersChartCell.swift in Sources */, FABB24812602FC2C00C8785C /* BindableTapGestureRecognizer.swift in Sources */, FABB24822602FC2C00C8785C /* ReaderSearchSuggestion.swift in Sources */, DCF892CA282FA37100BB71E1 /* SiteStatsBaseTableViewController.swift in Sources */, diff --git a/WordPress/WordPressTest/StatsSubscribersViewModelTests.swift b/WordPress/WordPressTest/StatsSubscribersViewModelTests.swift index 1b3edcc3c382..e839500d489f 100644 --- a/WordPress/WordPressTest/StatsSubscribersViewModelTests.swift +++ b/WordPress/WordPressTest/StatsSubscribersViewModelTests.swift @@ -24,17 +24,39 @@ final class StatsSubscribersViewModelTests: XCTestCase { }) .store(in: &cancellables) - store.emailsSummary.send(.loading) + store.chartSummary.send(.loading) wait(for: [expectation], timeout: 1) } + func testTableViewSnapshot_chartSummaryLoaded() throws { + let expectation = expectation(description: "Chart section should be loading") + var subscriberChartRow: SubscriberChartRow? + sut.tableViewSnapshot + .sink(receiveValue: { snapshot in + if let row = snapshot.itemIdentifiers.first?.immuTableRow as? SubscriberChartRow { + subscriberChartRow = row + expectation.fulfill() + } + }) + .store(in: &cancellables) + + let chartSummary = StatsSubscribersSummaryData(history: [ + .init(date: Date(), count: 1), + .init(date: Date(), count: 2), + ]) + store.chartSummary.send(.success(chartSummary)) + + wait(for: [expectation], timeout: 1) + XCTAssertNotNil(subscriberChartRow?.chartData) + } + func testTableViewSnapshot_emailsSummaryLoaded() throws { - let expectation = expectation(description: "First section should be loading") + let expectation = expectation(description: "Email section should be loading") var emailsSummaryRow: TopTotalsPeriodStatsRow? sut.tableViewSnapshot .sink(receiveValue: { snapshot in - if let row = snapshot.itemIdentifiers.first?.immuTableRow as? TopTotalsPeriodStatsRow { + if let row = snapshot.itemIdentifiers.last?.immuTableRow as? TopTotalsPeriodStatsRow { emailsSummaryRow = row expectation.fulfill() } @@ -56,9 +78,15 @@ final class StatsSubscribersViewModelTests: XCTestCase { } private class StatsSubscribersStoreMock: StatsSubscribersStoreProtocol { + var chartSummary: CurrentValueSubject, Never> = .init(.idle) var emailsSummary: CurrentValueSubject, Never> = .init(.idle) + var updateChartSummaryCalled = false var updateEmailsSummaryCalled = false + func updateChartSummary() { + updateChartSummaryCalled = false + } + func updateEmailsSummary(quantity: Int, sortField: StatsEmailsSummaryData.SortField) { updateEmailsSummaryCalled = true } From f3bf11701380c259d49ee68ca4af4c682bf41c6f Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Tue, 23 Apr 2024 22:28:20 -0400 Subject: [PATCH 2/8] Fixed chart cell title --- Podfile | 2 +- Podfile.lock | 8 ++++---- .../Stats/Subscribers/StatsSubscribersChartCell.xib | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Podfile b/Podfile index 53eaf4d457b1..56cb4d795e6a 100644 --- a/Podfile +++ b/Podfile @@ -56,7 +56,7 @@ end def wordpress_kit # pod 'WordPressKit', '~> 17.0.0' - pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: 'a7ccb2e6810eb9d546f9a85cd30057be88a9760b' + pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '3197069de70b1e2b57ca8f399896edfdd908fe4a' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: '' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: '' # pod 'WordPressKit', path: '../WordPressKit-iOS' diff --git a/Podfile.lock b/Podfile.lock index 85f58742392c..18b720e6293a 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -121,7 +121,7 @@ DEPENDENCIES: - SwiftLint (= 0.54.0) - WordPress-Editor-iOS (~> 1.19.11) - WordPressAuthenticator (>= 9.0.8, ~> 9.0) - - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `a7ccb2e6810eb9d546f9a85cd30057be88a9760b`) + - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `3197069de70b1e2b57ca8f399896edfdd908fe4a`) - WordPressShared (from `https://github.com/wordpress-mobile/WordPress-iOS-Shared.git`, commit `688ee5e4efddc1fc23626626ef17b7e929bdafb0`) - WordPressUI (~> 1.16) - ZendeskSupportSDK (= 5.3.0) @@ -177,7 +177,7 @@ EXTERNAL SOURCES: Gutenberg: :podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.117.0.podspec WordPressKit: - :commit: a7ccb2e6810eb9d546f9a85cd30057be88a9760b + :commit: 3197069de70b1e2b57ca8f399896edfdd908fe4a :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -188,7 +188,7 @@ CHECKOUT OPTIONS: :git: https://github.com/wordpress-mobile/FSInteractiveMap.git :tag: 0.2.0 WordPressKit: - :commit: a7ccb2e6810eb9d546f9a85cd30057be88a9760b + :commit: 3197069de70b1e2b57ca8f399896edfdd908fe4a :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -239,6 +239,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced -PODFILE CHECKSUM: 0733776e0690892a2d9f7dab87c32abd8f2c8567 +PODFILE CHECKSUM: 137d276a703acdcfe3339bcea95bdd41f68761f4 COCOAPODS: 1.15.2 diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.xib b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.xib index dd0cad1996d5..255292322f4a 100644 --- a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.xib +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.xib @@ -18,20 +18,21 @@ - + - + + From 92e4782d034e61f28a30958c6825db015dde42d2 Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Thu, 25 Apr 2024 14:42:23 -0400 Subject: [PATCH 3/8] Improved data fetching --- Podfile | 2 +- Podfile.lock | 8 ++++---- .../Subscribers/StatsSubscribersStore.swift | 12 +++++------ .../StatsSubscribersViewModel.swift | 20 ++++++++----------- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Podfile b/Podfile index 56cb4d795e6a..c3fef31d32d9 100644 --- a/Podfile +++ b/Podfile @@ -56,7 +56,7 @@ end def wordpress_kit # pod 'WordPressKit', '~> 17.0.0' - pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '3197069de70b1e2b57ca8f399896edfdd908fe4a' + pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '1b312425f37a0acee9027494f30adf8af69a6ce7' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: '' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: '' # pod 'WordPressKit', path: '../WordPressKit-iOS' diff --git a/Podfile.lock b/Podfile.lock index 18b720e6293a..6644923f9a53 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -121,7 +121,7 @@ DEPENDENCIES: - SwiftLint (= 0.54.0) - WordPress-Editor-iOS (~> 1.19.11) - WordPressAuthenticator (>= 9.0.8, ~> 9.0) - - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `3197069de70b1e2b57ca8f399896edfdd908fe4a`) + - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `1b312425f37a0acee9027494f30adf8af69a6ce7`) - WordPressShared (from `https://github.com/wordpress-mobile/WordPress-iOS-Shared.git`, commit `688ee5e4efddc1fc23626626ef17b7e929bdafb0`) - WordPressUI (~> 1.16) - ZendeskSupportSDK (= 5.3.0) @@ -177,7 +177,7 @@ EXTERNAL SOURCES: Gutenberg: :podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.117.0.podspec WordPressKit: - :commit: 3197069de70b1e2b57ca8f399896edfdd908fe4a + :commit: 1b312425f37a0acee9027494f30adf8af69a6ce7 :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -188,7 +188,7 @@ CHECKOUT OPTIONS: :git: https://github.com/wordpress-mobile/FSInteractiveMap.git :tag: 0.2.0 WordPressKit: - :commit: 3197069de70b1e2b57ca8f399896edfdd908fe4a + :commit: 1b312425f37a0acee9027494f30adf8af69a6ce7 :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -239,6 +239,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced -PODFILE CHECKSUM: 137d276a703acdcfe3339bcea95bdd41f68761f4 +PODFILE CHECKSUM: 25817355a3abf615b1ed495e9e58acf75647c5b3 COCOAPODS: 1.15.2 diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersStore.swift b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersStore.swift index 7aea01edc758..fcd6cdf349f3 100644 --- a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersStore.swift +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersStore.swift @@ -55,8 +55,8 @@ struct StatsSubscribersStore: StatsSubscribersStoreProtocol { func updateChartSummary() { guard chartSummary.value != .loading else { return } - let unit = StatsSubscribersSummaryData.Unit.day - let cacheKey = StatsSubscribersCache.CacheKey.chartSummary(unit: unit.rawValue, siteId: siteID) + let unit = StatsPeriodUnit.day + let cacheKey = StatsSubscribersCache.CacheKey.chartSummary(unit: unit.stringValue, siteId: siteID) let cachedData: StatsSubscribersSummaryData? = cache.getValue(key: cacheKey) if let cachedData = cachedData { @@ -65,13 +65,13 @@ struct StatsSubscribersStore: StatsSubscribersStoreProtocol { chartSummary.send(.loading) } - statsService.getSubscribers(unit: unit) { result in + statsService.getData(for: unit, endingOn: StatsDataHelper.currentDateForSite(), limit: 30) { (data: StatsSubscribersSummaryData?, error: Error?) in DispatchQueue.main.async { - switch result { - case .success(let data): + if let data = data { cache.setValue(data, key: cacheKey) self.chartSummary.send(.success(data)) - case .failure: + } + else { if cachedData == nil { self.chartSummary.send(.error) } diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift index 9555e5c3dc8f..c6483803e61b 100644 --- a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift @@ -21,18 +21,14 @@ final class StatsSubscribersViewModel { // MARK: - Lifecycle func addObservers() { - Publishers.MergeMany(store.chartSummary) - .removeDuplicates() - .sink { [weak self] _ in - self?.updateTableViewSnapshot() - } - .store(in: &cancellables) - Publishers.MergeMany(store.emailsSummary) - .removeDuplicates() - .sink { [weak self] _ in - self?.updateTableViewSnapshot() - } - .store(in: &cancellables) + Publishers.CombineLatest( + store.chartSummary.removeDuplicates(), + store.emailsSummary.removeDuplicates() + ) + .sink { [weak self] value in + self?.updateTableViewSnapshot() + } + .store(in: &cancellables) } func removeObservers() { From 25184c54efb19e34cfac345eb359881058514975 Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Thu, 25 Apr 2024 15:38:12 -0400 Subject: [PATCH 4/8] Merge in trunk and fixed issues --- Podfile | 2 +- Podfile.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Podfile b/Podfile index a5dda3b97bfc..6563351ef510 100644 --- a/Podfile +++ b/Podfile @@ -56,7 +56,7 @@ end def wordpress_kit # pod 'WordPressKit', '~> 17.0.0' - pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '14aa53a2e1cfa764e3e9e3e91d1f39f4ef09e098' + pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '8e020f825d8b21bb40c6cab324e97ca69f3090c9' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: '' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: '' # pod 'WordPressKit', path: '../WordPressKit-iOS' diff --git a/Podfile.lock b/Podfile.lock index 84ba5bea8268..db2387e8ddbf 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -121,7 +121,7 @@ DEPENDENCIES: - SwiftLint (= 0.54.0) - WordPress-Editor-iOS (~> 1.19.11) - WordPressAuthenticator (>= 9.0.8, ~> 9.0) - - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `14aa53a2e1cfa764e3e9e3e91d1f39f4ef09e098`) + - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `8e020f825d8b21bb40c6cab324e97ca69f3090c9`) - WordPressShared (from `https://github.com/wordpress-mobile/WordPress-iOS-Shared.git`, commit `688ee5e4efddc1fc23626626ef17b7e929bdafb0`) - WordPressUI (~> 1.16) - ZendeskSupportSDK (= 5.3.0) @@ -177,7 +177,7 @@ EXTERNAL SOURCES: Gutenberg: :podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.117.0.podspec WordPressKit: - :commit: 14aa53a2e1cfa764e3e9e3e91d1f39f4ef09e098 + :commit: 8e020f825d8b21bb40c6cab324e97ca69f3090c9 :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -188,7 +188,7 @@ CHECKOUT OPTIONS: :git: https://github.com/wordpress-mobile/FSInteractiveMap.git :tag: 0.2.0 WordPressKit: - :commit: 14aa53a2e1cfa764e3e9e3e91d1f39f4ef09e098 + :commit: 8e020f825d8b21bb40c6cab324e97ca69f3090c9 :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -239,6 +239,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced -PODFILE CHECKSUM: 4ac1d35f8415bdc8d4c8e39d6aa7a9f6dab5933d +PODFILE CHECKSUM: 55b1b06689c2f550323787c0568cb237bc11499a COCOAPODS: 1.15.2 From 9cc7ba2532e92788340987f6e70530631e9f3148 Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Thu, 25 Apr 2024 19:21:56 -0400 Subject: [PATCH 5/8] Fix subscriber chart for new sites --- Podfile | 2 +- Podfile.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Podfile b/Podfile index 6563351ef510..347b48ac481a 100644 --- a/Podfile +++ b/Podfile @@ -56,7 +56,7 @@ end def wordpress_kit # pod 'WordPressKit', '~> 17.0.0' - pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '8e020f825d8b21bb40c6cab324e97ca69f3090c9' + pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '7f47dbc791d59d0b5ad8c958441c3060b784ec43' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: '' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: '' # pod 'WordPressKit', path: '../WordPressKit-iOS' diff --git a/Podfile.lock b/Podfile.lock index db2387e8ddbf..7aa52ef0ab73 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -121,7 +121,7 @@ DEPENDENCIES: - SwiftLint (= 0.54.0) - WordPress-Editor-iOS (~> 1.19.11) - WordPressAuthenticator (>= 9.0.8, ~> 9.0) - - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `8e020f825d8b21bb40c6cab324e97ca69f3090c9`) + - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `7f47dbc791d59d0b5ad8c958441c3060b784ec43`) - WordPressShared (from `https://github.com/wordpress-mobile/WordPress-iOS-Shared.git`, commit `688ee5e4efddc1fc23626626ef17b7e929bdafb0`) - WordPressUI (~> 1.16) - ZendeskSupportSDK (= 5.3.0) @@ -177,7 +177,7 @@ EXTERNAL SOURCES: Gutenberg: :podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.117.0.podspec WordPressKit: - :commit: 8e020f825d8b21bb40c6cab324e97ca69f3090c9 + :commit: 7f47dbc791d59d0b5ad8c958441c3060b784ec43 :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -188,7 +188,7 @@ CHECKOUT OPTIONS: :git: https://github.com/wordpress-mobile/FSInteractiveMap.git :tag: 0.2.0 WordPressKit: - :commit: 8e020f825d8b21bb40c6cab324e97ca69f3090c9 + :commit: 7f47dbc791d59d0b5ad8c958441c3060b784ec43 :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -239,6 +239,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced -PODFILE CHECKSUM: 55b1b06689c2f550323787c0568cb237bc11499a +PODFILE CHECKSUM: 7b5d6ae9b49c6c663e1bcd975a044d4a451ea86e COCOAPODS: 1.15.2 From f6454c727cc6ed5cc103c7fa6bb30402131451fc Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Thu, 25 Apr 2024 20:05:05 -0400 Subject: [PATCH 6/8] Fixed unit test --- WordPress/WordPressTest/StatsSubscribersViewModelTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/WordPressTest/StatsSubscribersViewModelTests.swift b/WordPress/WordPressTest/StatsSubscribersViewModelTests.swift index 6dfe29b4ddc4..1d5e02906c62 100644 --- a/WordPress/WordPressTest/StatsSubscribersViewModelTests.swift +++ b/WordPress/WordPressTest/StatsSubscribersViewModelTests.swift @@ -43,7 +43,7 @@ final class StatsSubscribersViewModelTests: XCTestCase { let chartSummary = StatsSubscribersSummaryData(history: [ .init(date: Date(), count: 1), .init(date: Date(), count: 2), - ]) + ], period: .day, periodEndDate: Date()) store.chartSummary.send(.success(chartSummary)) wait(for: [expectation], timeout: 1) From fdea4d4de7191328b79d87887749d401be03a0c5 Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Fri, 26 Apr 2024 10:24:18 -0400 Subject: [PATCH 7/8] Fix chart row section --- Podfile | 2 +- Podfile.lock | 8 ++++---- .../Stats/Subscribers/StatsSubscribersChartCell.swift | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Podfile b/Podfile index 347b48ac481a..93dd406677a9 100644 --- a/Podfile +++ b/Podfile @@ -56,7 +56,7 @@ end def wordpress_kit # pod 'WordPressKit', '~> 17.0.0' - pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '7f47dbc791d59d0b5ad8c958441c3060b784ec43' + pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '77aee91d607cb8b86d4356c0aebfb3977ff1fcc7' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: '' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: '' # pod 'WordPressKit', path: '../WordPressKit-iOS' diff --git a/Podfile.lock b/Podfile.lock index 7aa52ef0ab73..fa52f0297ff6 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -121,7 +121,7 @@ DEPENDENCIES: - SwiftLint (= 0.54.0) - WordPress-Editor-iOS (~> 1.19.11) - WordPressAuthenticator (>= 9.0.8, ~> 9.0) - - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `7f47dbc791d59d0b5ad8c958441c3060b784ec43`) + - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `77aee91d607cb8b86d4356c0aebfb3977ff1fcc7`) - WordPressShared (from `https://github.com/wordpress-mobile/WordPress-iOS-Shared.git`, commit `688ee5e4efddc1fc23626626ef17b7e929bdafb0`) - WordPressUI (~> 1.16) - ZendeskSupportSDK (= 5.3.0) @@ -177,7 +177,7 @@ EXTERNAL SOURCES: Gutenberg: :podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.117.0.podspec WordPressKit: - :commit: 7f47dbc791d59d0b5ad8c958441c3060b784ec43 + :commit: 77aee91d607cb8b86d4356c0aebfb3977ff1fcc7 :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -188,7 +188,7 @@ CHECKOUT OPTIONS: :git: https://github.com/wordpress-mobile/FSInteractiveMap.git :tag: 0.2.0 WordPressKit: - :commit: 7f47dbc791d59d0b5ad8c958441c3060b784ec43 + :commit: 77aee91d607cb8b86d4356c0aebfb3977ff1fcc7 :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git WordPressShared: :commit: 688ee5e4efddc1fc23626626ef17b7e929bdafb0 @@ -239,6 +239,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced -PODFILE CHECKSUM: 7b5d6ae9b49c6c663e1bcd975a044d4a451ea86e +PODFILE CHECKSUM: 4bbf2ae7c80a5f39db237e7c3514872e9f7eb3ca COCOAPODS: 1.15.2 diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.swift b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.swift index 9c34e07f54c1..728d1cf49cd2 100644 --- a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.swift +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersChartCell.swift @@ -17,8 +17,7 @@ class StatsSubscribersChartCell: StatsBaseCell, NibLoadable { } func configure(row: SubscriberChartRow) { - - statSection = .subscribersChart + statSection = row.statSection self.chartData = row.chartData self.chartStyling = row.chartStyling From 55cb3a76bf33fbfc7393ab990d630f21c97b41b9 Mon Sep 17 00:00:00 2001 From: Paul Von Schrottky Date: Fri, 26 Apr 2024 10:42:13 -0400 Subject: [PATCH 8/8] Handle updated subscriber counts --- .../Classes/ViewRelated/Stats/SiteStatsTableViewCells.swift | 4 +++- .../Stats/Subscribers/StatsSubscribersViewModel.swift | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Stats/SiteStatsTableViewCells.swift b/WordPress/Classes/ViewRelated/Stats/SiteStatsTableViewCells.swift index ea4da9e03a77..0a1fa9fd74c1 100644 --- a/WordPress/Classes/ViewRelated/Stats/SiteStatsTableViewCells.swift +++ b/WordPress/Classes/ViewRelated/Stats/SiteStatsTableViewCells.swift @@ -85,13 +85,15 @@ struct SubscriberChartRow: StatsHashableImmuTableRow { }() let action: ImmuTableAction? = nil + let history: [StatsSubscribersSummaryData.SubscriberData] let chartData: LineChartDataConvertible let chartStyling: LineChartStyling let xAxisDates: [Date] let statSection: StatSection? static func == (lhs: SubscriberChartRow, rhs: SubscriberChartRow) -> Bool { - return lhs.xAxisDates == rhs.xAxisDates + return lhs.xAxisDates == rhs.xAxisDates && + lhs.history == rhs.history } func configureCell(_ cell: UITableViewCell) { diff --git a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift index 9ef86b40b6de..59b3a9330319 100644 --- a/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift +++ b/WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewModel.swift @@ -70,6 +70,7 @@ private extension StatsSubscribersViewModel { let viewsChart = StatsSubscribersLineChart(counts: chartSummary.history.map { $0.count }) return [ SubscriberChartRow( + history: chartSummary.history, chartData: viewsChart.lineChartData, chartStyling: viewsChart.lineChartStyling, xAxisDates: xAxisDates,