Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats Insights: Remove social (publicize) subscribers #23099

Merged
merged 3 commits into from Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 1 addition & 12 deletions WordPress/Classes/Stores/StatsInsightsStore.swift
Expand Up @@ -827,25 +827,14 @@ extension StatsInsightsStore {
func getTotalFollowerCount() -> Int {
let totalDotComFollowers = getDotComFollowers()?.dotComFollowersCount ?? 0
let totalEmailFollowers = getEmailFollowers()?.emailFollowersCount ?? 0
let totalPublicize = getPublicizeCount()

return totalDotComFollowers + totalEmailFollowers + totalPublicize
return totalDotComFollowers + totalEmailFollowers
}

func getPublicize() -> StatsPublicizeInsight? {
return state.publicizeFollowers
}

func getPublicizeCount() -> Int {
var totalPublicize = 0
if let publicize = getPublicize(),
!publicize.publicizeServices.isEmpty {
totalPublicize = publicize.publicizeServices.compactMap({$0.followers}).reduce(0, +)
}

return totalPublicize
}

func getTopCommentsInsight() -> StatsCommentsInsight? {
return state.topCommentsInsight
}
Expand Down
Expand Up @@ -531,7 +531,6 @@ private extension SiteStatsInsightsViewModel {
static let total = NSLocalizedString("Total", comment: "Label for total followers")
static let wordPress = NSLocalizedString("WordPress.com", comment: "Label for WordPress.com followers")
static let email = NSLocalizedString("Email", comment: "Label for email followers")
static let social = NSLocalizedString("Social", comment: "Follower Totals label for social media followers")
}

struct TodaysStats {
Expand Down Expand Up @@ -614,36 +613,6 @@ private extension SiteStatsInsightsViewModel {

}

func createTotalFollowersRows() -> [StatsTwoColumnRowData] {
let totalDotComFollowers = insightsStore.getDotComFollowers()?.dotComFollowersCount ?? 0
let totalEmailFollowers = insightsStore.getEmailFollowers()?.emailFollowersCount ?? 0

var totalPublicize = 0
if let publicize = insightsStore.getPublicize(),
!publicize.publicizeServices.isEmpty {
totalPublicize = publicize.publicizeServices.compactMap({$0.followers}).reduce(0, +)
}

let totalFollowers = insightsStore.getTotalFollowerCount()
guard totalFollowers > 0 else {
return []
}

var dataRows = [StatsTwoColumnRowData]()

dataRows.append(StatsTwoColumnRowData.init(leftColumnName: FollowerTotals.total,
leftColumnData: totalFollowers.abbreviatedString(),
rightColumnName: FollowerTotals.wordPress,
rightColumnData: totalDotComFollowers.abbreviatedString()))

dataRows.append(StatsTwoColumnRowData.init(leftColumnName: FollowerTotals.email,
leftColumnData: totalEmailFollowers.abbreviatedString(),
rightColumnName: FollowerTotals.social,
rightColumnData: totalPublicize.abbreviatedString()))

return dataRows
}

func createLikesTotalInsightsRow() -> StatsTotalInsightsData {
return StatsTotalInsightsData.createTotalInsightsData(periodSummary: periodStore.getSummary(), insightsStore: insightsStore, statsSummaryType: .likes)
}
Expand Down
Expand Up @@ -325,21 +325,18 @@ class SiteStatsInsightsDetailsViewModel: Observable {

let dotComFollowersCount = insightsStore.getDotComFollowers()?.dotComFollowersCount ?? 0
let emailFollowersCount = insightsStore.getEmailFollowers()?.emailFollowersCount ?? 0
let publicizeCount = insightsStore.getPublicizeCount()

if dotComFollowersCount > 0 || emailFollowersCount > 0 || publicizeCount > 0 {
if dotComFollowersCount > 0 || emailFollowersCount > 0 {
let chartViewModel = StatsFollowersChartViewModel(dotComFollowersCount: dotComFollowersCount,
emailFollowersCount: emailFollowersCount,
publicizeCount: publicizeCount)
emailFollowersCount: emailFollowersCount)

let chartView: UIView = chartViewModel.makeFollowersChartView()

var chartRow = TopTotalsPeriodStatsRow(itemSubtitle: "",
dataSubtitle: "",
dataRows: followersRowData(dotComFollowersCount: dotComFollowersCount,
emailFollowersCount: emailFollowersCount,
othersCount: publicizeCount,
totalCount: dotComFollowersCount + emailFollowersCount + publicizeCount),
totalCount: dotComFollowersCount + emailFollowersCount),
statSection: StatSection.insightsFollowersWordPress,
siteStatsPeriodDelegate: nil, //TODO - look at if I need to be not null
siteStatsReferrerDelegate: nil)
Expand Down Expand Up @@ -1003,7 +1000,7 @@ private extension SiteStatsInsightsDetailsViewModel {
}

// MARK: - Followers
func followersRowData(dotComFollowersCount: Int, emailFollowersCount: Int, othersCount: Int, totalCount: Int) -> [StatsTotalRowData] {
func followersRowData(dotComFollowersCount: Int, emailFollowersCount: Int, totalCount: Int) -> [StatsTotalRowData] {
var rowData = [StatsTotalRowData]()

rowData.append(
Expand All @@ -1018,12 +1015,6 @@ private extension SiteStatsInsightsDetailsViewModel {
statSection: .insightsFollowersEmail)
)

rowData.append(
StatsTotalRowData(name: StatSection.insightsPublicize.tabTitle,
data: "\(othersCount.abbreviatedString()) (\(roundedPercentage(numerator: othersCount, denominator: totalCount))%)",
statSection: .insightsFollowersWordPress)
)

return rowData
}

Expand Down
Expand Up @@ -2,15 +2,13 @@ import Foundation

struct StatsFollowersChartViewModel {

public let dotComFollowersCount: Int
public let emailFollowersCount: Int
public let publicizeCount: Int
let dotComFollowersCount: Int
let emailFollowersCount: Int

func makeFollowersChartView() -> UIView {
// The followers chart currently shows 3 segments. If available, it will show:
// The followers chart currently shows 2 segments. If available, it will show:
// - WordPress.com followers
// - Email followers
// - Social

let chartView = DonutChartView()
chartView.configure(title: "", totalCount: CGFloat(totalCount()), segments: segments())
Expand All @@ -20,14 +18,13 @@ struct StatsFollowersChartViewModel {
}

internal func totalCount() -> Int {
return dotComFollowersCount + emailFollowersCount + publicizeCount
return dotComFollowersCount + emailFollowersCount
}

internal func segments() -> [DonutChartView.Segment] {
var segments: [DonutChartView.Segment] = []
segments.append(segmentWith(title: Constants.wpComGroupTitle, count: dotComFollowersCount, color: Constants.wpComColor))
segments.append(segmentWith(title: Constants.emailGroupTitle, count: emailFollowersCount, color: Constants.emailColor))
segments.append(segmentWith(title: Constants.socialGroupTitle, count: publicizeCount, color: Constants.socialColor))
return segments
}

Expand All @@ -42,11 +39,9 @@ struct StatsFollowersChartViewModel {
private enum Constants {
static let wpComGroupTitle = NSLocalizedString("WordPress", comment: "Title of Stats section that shows WordPress.com followers.")
static let emailGroupTitle = NSLocalizedString("Email", comment: "Title of Stats section that shows email followers.")
static let socialGroupTitle = NSLocalizedString("Social", comment: "Title of Stats section that shows social followers.")

static let wpComColor: UIColor = .muriel(name: .blue, .shade50)
static let emailColor: UIColor = .muriel(name: .blue, .shade5)
static let socialColor: UIColor = .muriel(name: .orange, .shade30)

static let chartHeight: CGFloat = 231.0
}
Expand Down