Skip to content

Commit

Permalink
Fix an issue with Referrers in Stats showing invalid icons (#23943)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Jan 3, 2025
2 parents 309ddbc + 2f22b2f commit fe31a0d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 64 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [*] Fix incorrect chevron icons direction in RTL languages [#23940]
* [*] Fix an issue with clear navigation bar background in revision browser [#23941]
* [*] Fix an issue with comments being lost on request failure [#23942]
* [*] Fix an issue with Referrers in Stats showing invalid icons [#23943]

25.6
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,27 +502,19 @@ private extension SiteStatsPeriodViewModel {
let referrers = store.getTopReferrers()?.referrers.prefix(10) ?? []

func rowDataFromReferrer(referrer: StatsReferrer) -> StatsTotalRowData {
var icon: UIImage? = nil
var iconURL: URL? = nil

switch referrer.iconURL?.lastPathComponent {
case "search-engine.png":
icon = Style.imageForGridiconType(.search)
case nil:
icon = Style.imageForGridiconType(.globe)
default:
iconURL = referrer.iconURL
}

return StatsTotalRowData(name: referrer.title,
data: referrer.viewsCount.abbreviatedString(),
icon: icon,
socialIconURL: iconURL,
showDisclosure: true,
disclosureURL: referrer.url,
childRows: referrer.children.map { rowDataFromReferrer(referrer: $0) },
statSection: .periodReferrers,
isReferrerSpam: referrer.isSpam)
return StatsTotalRowData(
name: referrer.title,
data: referrer.viewsCount.abbreviatedString(),
icon: nil,
socialIconURL: nil,
showDisclosure: true,
disclosureURL: referrer.url,
childRows: referrer.children.map {
rowDataFromReferrer(referrer: $0)
},
statSection: .periodReferrers,
isReferrerSpam: referrer.isSpam
)
}

return referrers.map { rowDataFromReferrer(referrer: $0) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,26 +274,33 @@ class SiteStatsInsightsDetailsViewModel: Observable {

// Views Visitors
let weekEnd = futureEndOfWeekDate(for: periodSummary)
rows.append(contentsOf: SiteStatsImmuTableRows.viewVisitorsImmuTableRows(periodSummary,
selectedSegment: selectedViewsVisitorsSegment,
periodDate: selectedDate!,
periodEndDate: weekEnd,
siteStatsInsightsDelegate: nil,
viewsAndVisitorsDelegate: viewsAndVisitorsDelegate))
rows.append(
contentsOf: SiteStatsImmuTableRows.viewVisitorsImmuTableRows(
periodSummary,
selectedSegment: selectedViewsVisitorsSegment,
periodDate: selectedDate!,
periodEndDate: weekEnd,
siteStatsInsightsDelegate: nil,
viewsAndVisitorsDelegate: viewsAndVisitorsDelegate
)
)

// Referrers
if let referrers = viewsAndVisitorsData.topReferrers {
let referrersData = referrersRowData(topReferrers: referrers)
let chartViewModel = StatsReferrersChartViewModel(referrers: referrers)
let chartView: UIView? = referrers.totalReferrerViewsCount > 0 ? chartViewModel.makeReferrersChartView() : nil

var referrersRow = TopTotalsPeriodStatsRow(itemSubtitle: StatSection.periodReferrers.itemSubtitle,
dataSubtitle: StatSection.periodReferrers.dataSubtitle,
dataRows: referrersData,
statSection: StatSection.periodReferrers,
siteStatsPeriodDelegate: nil, //TODO - look at if I need to be not null
siteStatsReferrerDelegate: nil,
siteStatsInsightsDetailsDelegate: insightsDetailsDelegate)
var referrersRow = TopTotalsPeriodStatsRow(
itemSubtitle: StatSection.periodReferrers.itemSubtitle,
dataSubtitle: StatSection.periodReferrers.dataSubtitle,
dataRows: referrersData,
statSection: StatSection.periodReferrers,
siteStatsPeriodDelegate: nil,
//TODO - look at if I need to be not null
siteStatsReferrerDelegate: nil,
siteStatsInsightsDetailsDelegate: insightsDetailsDelegate
)
referrersRow.topAccessoryView = chartView
rows.append(referrersRow)
}
Expand All @@ -304,12 +311,18 @@ class SiteStatsInsightsDetailsViewModel: Observable {
if isMapShown {
rows.append(CountriesMapRow(countriesMap: map, statSection: .periodCountries))
}
rows.append(CountriesStatsRow(itemSubtitle: StatSection.periodCountries.itemSubtitle,
dataSubtitle: StatSection.periodCountries.dataSubtitle,
statSection: isMapShown ? nil : .periodCountries,
dataRows: countriesRowData(topCountries: viewsAndVisitorsData.topCountries),
siteStatsPeriodDelegate: nil,
siteStatsInsightsDetailsDelegate: insightsDetailsDelegate))
rows.append(
CountriesStatsRow(
itemSubtitle: StatSection.periodCountries.itemSubtitle,
dataSubtitle: StatSection.periodCountries.dataSubtitle,
statSection: isMapShown ? nil : .periodCountries,
dataRows: countriesRowData(
topCountries: viewsAndVisitorsData.topCountries
),
siteStatsPeriodDelegate: nil,
siteStatsInsightsDetailsDelegate: insightsDetailsDelegate
)
)
return rows
}

Expand All @@ -326,29 +339,42 @@ class SiteStatsInsightsDetailsViewModel: Observable {
let emailFollowersCount = insightsStore.getEmailFollowers()?.emailFollowersCount ?? 0

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

let chartView: UIView = chartViewModel.makeFollowersChartView()

var chartRow = TopTotalsPeriodStatsRow(itemSubtitle: "",
dataSubtitle: "",
dataRows: followersRowData(dotComFollowersCount: dotComFollowersCount,
emailFollowersCount: emailFollowersCount,
totalCount: dotComFollowersCount + emailFollowersCount),
statSection: StatSection.insightsFollowersWordPress,
siteStatsPeriodDelegate: nil, //TODO - look at if I need to be not null
siteStatsReferrerDelegate: nil)
var chartRow = TopTotalsPeriodStatsRow(
itemSubtitle: "",
dataSubtitle: "",
dataRows: followersRowData(
dotComFollowersCount: dotComFollowersCount,
emailFollowersCount: emailFollowersCount,
totalCount: dotComFollowersCount + emailFollowersCount
),
statSection: StatSection.insightsFollowersWordPress,
siteStatsPeriodDelegate: nil,
//TODO - look at if I need to be not null
siteStatsReferrerDelegate: nil
)
chartRow.topAccessoryView = chartView
rows.append(chartRow)
}

rows.append(TabbedTotalsStatsRow(tabsData: [tabDataForFollowerType(.insightsFollowersWordPress),
tabDataForFollowerType(.insightsFollowersEmail)],
rows.append(
TabbedTotalsStatsRow(
tabsData: [
tabDataForFollowerType(.insightsFollowersWordPress),
tabDataForFollowerType(.insightsFollowersEmail)
],
statSection: .insightsFollowersWordPress,
siteStatsInsightsDelegate: insightsDetailsDelegate,
siteStatsDetailsDelegate: detailsDelegate,
showTotalCount: false))
showTotalCount: false
)
)
return rows
}
case .insightsLikesTotals:
Expand All @@ -358,21 +384,32 @@ class SiteStatsInsightsDetailsViewModel: Observable {
let likesTotalsData = revampStore.getLikesTotalsData()

if let summary = likesTotalsData.summary {
rows.append(TotalInsightStatsRow(dataRow: createLikesTotalInsightsRow(periodSummary: summary),
statSection: statSection,
siteStatsInsightsDelegate: nil)
rows.append(
TotalInsightStatsRow(
dataRow: createLikesTotalInsightsRow(
periodSummary: summary
),
statSection: statSection,
siteStatsInsightsDelegate: nil
)
)
}

if let topPostsAndPages = likesTotalsData.topPostsAndPages {
rows.append(TopTotalsPeriodStatsRow(itemSubtitle: StatSection.periodPostsAndPages.itemSubtitle,
dataSubtitle: StatSection.periodPostsAndPages.dataSubtitle,
dataRows: postsAndPagesRowData(topPostsAndPages: topPostsAndPages),
statSection: StatSection.periodPostsAndPages,
siteStatsPeriodDelegate: nil,
siteStatsReferrerDelegate: nil,
siteStatsInsightsDetailsDelegate: insightsDetailsDelegate,
siteStatsDetailsDelegate: detailsDelegate))
rows.append(
TopTotalsPeriodStatsRow(
itemSubtitle: StatSection.periodPostsAndPages.itemSubtitle,
dataSubtitle: StatSection.periodPostsAndPages.dataSubtitle,
dataRows: postsAndPagesRowData(
topPostsAndPages: topPostsAndPages
),
statSection: StatSection.periodPostsAndPages,
siteStatsPeriodDelegate: nil,
siteStatsReferrerDelegate: nil,
siteStatsInsightsDetailsDelegate: insightsDetailsDelegate,
siteStatsDetailsDelegate: detailsDelegate
)
)
}

return rows
Expand Down

0 comments on commit fe31a0d

Please sign in to comment.