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 Refresh] Insights tabbed cards: fix displaying details view #11675

Merged
merged 2 commits into from
May 13, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ extension UITableViewCell {
toStackView rowsStackView: UIStackView,
forType statType: StatType,
limitRowsDisplayed: Bool = true,
forDetailsList: Bool = false,
rowDelegate: StatsTotalRowDelegate? = nil,
viewMoreDelegate: ViewMoreRowDelegate? = nil) {

let numberOfDataRows = dataRows.count

guard numberOfDataRows > 0 else {
if !forDetailsList {
if limitRowsDisplayed {
let row = StatsNoDataRow.loadFromNib()
row.configure(forType: statType)
rowsStackView.addArrangedSubview(row)
Expand Down
27 changes: 15 additions & 12 deletions WordPress/Classes/ViewRelated/Stats/Insights/TabbedTotalsCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TabbedTotalsCell: UITableViewCell, NibLoadable {
private weak var siteStatsInsightsDelegate: SiteStatsInsightsDelegate?
private weak var siteStatsDetailsDelegate: SiteStatsDetailsDelegate?
private var showTotalCount = false
private var limitRowsDisplayed = true
private var forDetails = false

// MARK: - Configure

Expand All @@ -65,13 +65,13 @@ class TabbedTotalsCell: UITableViewCell, NibLoadable {
siteStatsDetailsDelegate: SiteStatsDetailsDelegate? = nil,
showTotalCount: Bool,
selectedIndex: Int = 0,
limitRowsDisplayed: Bool = true) {
forDetails: Bool = false) {
self.tabsData = tabsData
self.siteStatsInsightsDelegate = siteStatsInsightsDelegate
self.siteStatsDetailsDelegate = siteStatsDetailsDelegate
self.showTotalCount = showTotalCount
self.limitRowsDisplayed = limitRowsDisplayed
bottomSeparatorLine.isHidden = !limitRowsDisplayed
self.forDetails = forDetails
bottomSeparatorLine.isHidden = forDetails
setupFilterBar(selectedIndex: selectedIndex)
addRowsForSelectedFilter()
configureSubtitles()
Expand Down Expand Up @@ -114,14 +114,18 @@ private extension TabbedTotalsCell {
}

func toggleNoResults() {

guard forDetails else {
return
}

noResultsViewController.removeFromView()

let showNoResults = tabsData[filterTabBar.selectedIndex].dataRows.isEmpty && !limitRowsDisplayed
let showNoResults = tabsData[filterTabBar.selectedIndex].dataRows.isEmpty
noResultsView.isHidden = !showNoResults

guard showNoResults,
let superview = superview else {
return
guard showNoResults, let superview = superview else {
return
}

noResultsViewController.view.frame = noResultsView.bounds
Expand All @@ -130,17 +134,16 @@ private extension TabbedTotalsCell {
}

func addRowsForSelectedFilter() {
toggleNoResults()

guard noResultsView.isHidden else {
if forDetails {
toggleNoResults()
return
}

addRows(tabsData[filterTabBar.selectedIndex].dataRows,
toStackView: rowsStackView,
forType: .insights,
limitRowsDisplayed: limitRowsDisplayed,
forDetailsList: !limitRowsDisplayed,
limitRowsDisplayed: true,
rowDelegate: self,
viewMoreDelegate: self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private extension SiteStatsDetailTableViewController {
func tableRowTypes() -> [ImmuTableRow.Type] {
return [DetailDataRow.self,
DetailSubtitlesHeaderRow.self,
TabbedTotalsDetailStatsRow.self,
DetailSubtitlesTabbedHeaderRow.self,
TopTotalsDetailStatsRow.self,
DetailSubtitlesCountriesHeaderRow.self]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,28 @@ class SiteStatsDetailsViewModel: Observable {
switch statSection {
case .insightsFollowersWordPress, .insightsFollowersEmail:
let selectedIndex = statSection == .insightsFollowersWordPress ? 0 : 1
tableRows.append(TabbedTotalsDetailStatsRow(tabsData: [tabDataForFollowerType(.insightsFollowersWordPress),
tabDataForFollowerType(.insightsFollowersEmail)],
siteStatsDetailsDelegate: detailsDelegate,
showTotalCount: true,
selectedIndex: selectedIndex))
let wpTabData = tabDataForFollowerType(.insightsFollowersWordPress)
let emailTabData = tabDataForFollowerType(.insightsFollowersEmail)

tableRows.append(DetailSubtitlesTabbedHeaderRow(tabsData: [wpTabData, emailTabData],
siteStatsDetailsDelegate: detailsDelegate,
showTotalCount: true,
selectedIndex: selectedIndex))

let dataRows = statSection == .insightsFollowersWordPress ? wpTabData.dataRows : emailTabData.dataRows
tableRows.append(contentsOf: tabbedRowsFrom(dataRows))
case .insightsCommentsAuthors, .insightsCommentsPosts:
let selectedIndex = statSection == .insightsCommentsAuthors ? 0 : 1
tableRows.append(TabbedTotalsDetailStatsRow(tabsData: [tabDataForCommentType(.insightsCommentsAuthors),
tabDataForCommentType(.insightsCommentsPosts)],
siteStatsDetailsDelegate: detailsDelegate,
showTotalCount: false,
selectedIndex: selectedIndex))
let authorsTabData = tabDataForCommentType(.insightsCommentsAuthors)
let postsTabData = tabDataForCommentType(.insightsCommentsPosts)

tableRows.append(DetailSubtitlesTabbedHeaderRow(tabsData: [authorsTabData, postsTabData],
siteStatsDetailsDelegate: detailsDelegate,
showTotalCount: false,
selectedIndex: selectedIndex))

let dataRows = statSection == .insightsCommentsAuthors ? authorsTabData.dataRows : postsTabData.dataRows
tableRows.append(contentsOf: tabbedRowsFrom(dataRows))
case .insightsTagsAndCategories:
tableRows.append(TopTotalsDetailStatsRow(itemSubtitle: StatSection.insightsTagsAndCategories.itemSubtitle,
dataSubtitle: StatSection.insightsTagsAndCategories.dataSubtitle,
Expand Down Expand Up @@ -300,6 +310,10 @@ private extension SiteStatsDetailsViewModel {

// MARK: - Tabbed Cards

func tabbedRowsFrom(_ commentsRowData: [StatsTotalRowData]) -> [DetailDataRow] {
return dataRowsFor(commentsRowData)
}

func tabDataForFollowerType(_ followerType: StatSection) -> TabData {
let tabTitle = followerType.tabTitle
var followers: [StatsFollower] = []
Expand Down
56 changes: 28 additions & 28 deletions WordPress/Classes/ViewRelated/Stats/SiteStatsTableViewCells.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,34 +122,6 @@ struct TabbedTotalsStatsRow: ImmuTableRow {
}
}

struct TabbedTotalsDetailStatsRow: ImmuTableRow {

typealias CellType = TabbedTotalsCell

static let cell: ImmuTableCell = {
return ImmuTableCell.nib(CellType.defaultNib, CellType.self)
}()

let tabsData: [TabData]
weak var siteStatsDetailsDelegate: SiteStatsDetailsDelegate?
let showTotalCount: Bool
let selectedIndex: Int
let action: ImmuTableAction? = nil

func configureCell(_ cell: UITableViewCell) {

guard let cell = cell as? CellType else {
return
}

cell.configure(tabsData: tabsData,
siteStatsDetailsDelegate: siteStatsDetailsDelegate,
showTotalCount: showTotalCount,
selectedIndex: selectedIndex,
limitRowsDisplayed: false)
}
}

struct TopTotalsDetailStatsRow: ImmuTableRow {

typealias CellType = TopTotalsCell
Expand Down Expand Up @@ -506,3 +478,31 @@ struct DetailSubtitlesCountriesHeaderRow: ImmuTableRow {
cell.configure(itemSubtitle: itemSubtitle, dataSubtitle: dataSubtitle, dataRows: [], forDetails: true)
}
}

struct DetailSubtitlesTabbedHeaderRow: ImmuTableRow {

typealias CellType = TabbedTotalsCell

static let cell: ImmuTableCell = {
return ImmuTableCell.nib(CellType.defaultNib, CellType.self)
}()

let tabsData: [TabData]
weak var siteStatsDetailsDelegate: SiteStatsDetailsDelegate?
let showTotalCount: Bool
let selectedIndex: Int
let action: ImmuTableAction? = nil

func configureCell(_ cell: UITableViewCell) {

guard let cell = cell as? CellType else {
return
}

cell.configure(tabsData: tabsData,
siteStatsDetailsDelegate: siteStatsDetailsDelegate,
showTotalCount: showTotalCount,
selectedIndex: selectedIndex,
forDetails: true)
}
}