Skip to content

Commit 37a715b

Browse files
authored
Merge pull request #17867 from wordpress-mobile/issue/17845-move-add-new-insight-card
Add New Insights Card to navigation bar
2 parents 9fc374b + 75f970c commit 37a715b

5 files changed

Lines changed: 49 additions & 27 deletions

File tree

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [**] People: you can now manage Email Followers on the People section! [#17854]
99
* [*] Stats: fix navigation between Stats tab. [#17856]
1010
* [*] Quick Start: Fixed a bug where a user logging in via a self-hosted site not connected to Jetpack would see Quick Start when selecting "No thanks" on the Quick Start prompt. [#17855]
11+
* [*] Stats: can now add insights card from navigation bar [#17867]
1112

1213
19.1
1314
-----

WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,29 @@ class SiteStatsInsightsTableViewController: UITableViewController, StoryboardLoa
8383
viewModel?.refreshInsights()
8484
}
8585

86+
func showAddInsightView(source: String = "table_row") {
87+
WPAnalytics.track(.statsItemTappedInsightsAddStat, withProperties: ["source": source])
88+
89+
if displayingEmptyView {
90+
hideNoResults()
91+
addViewModelListeners()
92+
refreshInsights()
93+
}
94+
95+
if insightsToShow.contains(.customize) {
96+
// The view needs to be updated to remove the Customize card.
97+
// However, if it's done here, there is a weird animation before AddInsight is presented.
98+
// Instead, set 'viewNeedsUpdating' so the view is updated when 'addInsightDismissed' is called.
99+
viewNeedsUpdating = true
100+
dismissCustomizeCard()
101+
}
102+
103+
let controller = AddInsightTableViewController(insightsDelegate: self,
104+
insightsShown: insightsToShow.compactMap { $0.statSection })
105+
let navigationController = UINavigationController(rootViewController: controller)
106+
present(navigationController, animated: true, completion: nil)
107+
}
108+
86109
}
87110

88111
// MARK: - Private Extension
@@ -281,22 +304,6 @@ private extension SiteStatsInsightsTableViewController {
281304

282305
// MARK: - Insights Management
283306

284-
func showAddInsightView() {
285-
286-
if insightsToShow.contains(.customize) {
287-
// The view needs to be updated to remove the Customize card.
288-
// However, if it's done here, there is a weird animation before AddInsight is presented.
289-
// Instead, set 'viewNeedsUpdating' so the view is updated when 'addInsightDismissed' is called.
290-
viewNeedsUpdating = true
291-
dismissCustomizeCard()
292-
}
293-
294-
let controller = AddInsightTableViewController(insightsDelegate: self,
295-
insightsShown: insightsToShow.compactMap { $0.statSection })
296-
let navigationController = UINavigationController(rootViewController: controller)
297-
present(navigationController, animated: true, completion: nil)
298-
}
299-
300307
func moveInsightUp(_ insight: InsightType) {
301308
guard canMoveInsightUp(insight) else {
302309
return
@@ -633,15 +640,7 @@ extension SiteStatsInsightsTableViewController: ReaderDiscoverFlowDelegate {
633640

634641
extension SiteStatsInsightsTableViewController: NoResultsViewControllerDelegate {
635642
func actionButtonPressed() {
636-
guard !displayingEmptyView else {
637-
WPAnalytics.track(.statsItemTappedInsightsAddStat)
638-
showAddInsightView()
639-
return
640-
}
641-
642-
hideNoResults()
643-
addViewModelListeners()
644-
refreshInsights()
643+
showAddInsightView()
645644
}
646645
}
647646

WordPress/Classes/ViewRelated/Stats/Shared Views/StatsTotalRow.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ private extension StatsTotalRow {
376376
}
377377

378378
@IBAction func didTapDisclosureButton(_ sender: UIButton) {
379-
if let statSection = rowData?.statSection {
379+
if let statSection = rowData?.statSection,
380+
statSection != .insightsAddInsight {
380381
captureAnalyticsEventsFor(statSection)
381382
}
382383

WordPress/Classes/ViewRelated/Stats/SiteStatsDashboardViewController.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,36 @@ class SiteStatsDashboardViewController: UIViewController {
6969
private var periodTableViewController = SiteStatsPeriodTableViewController.loadFromStoryboard()
7070
private var pageViewController: UIPageViewController?
7171

72+
@objc lazy var manageInsightsButton: UIBarButtonItem = {
73+
let button = UIBarButtonItem(
74+
image: .gridicon(.cog),
75+
style: .plain,
76+
target: self,
77+
action: #selector(manageInsightsButtonTapped))
78+
button.accessibilityHint = NSLocalizedString("Tap to customize insights", comment: "Accessibility hint to customize insights")
79+
return button
80+
}()
81+
7282
// MARK: - View
7383

7484
override func viewDidLoad() {
7585
super.viewDidLoad()
86+
configureNavBar()
7687
setupFilterBar()
7788
restoreSelectedDateFromUserDefaults()
7889
restoreSelectedPeriodFromUserDefaults()
7990
addWillEnterForegroundObserver()
8091
view.accessibilityIdentifier = "stats-dashboard"
8192
}
8293

94+
func configureNavBar() {
95+
parent?.navigationItem.rightBarButtonItem = currentSelectedPeriod == .insights ? manageInsightsButton : nil
96+
}
97+
98+
@objc func manageInsightsButtonTapped() {
99+
insightsTableViewController.showAddInsightView(source: "nav_bar")
100+
}
101+
83102
override func viewWillDisappear(_ animated: Bool) {
84103
super.viewWillDisappear(animated)
85104
removeWillEnterForegroundObserver()
@@ -145,6 +164,8 @@ private extension SiteStatsDashboardViewController {
145164

146165
@objc func selectedFilterDidChange(_ filterBar: FilterTabBar) {
147166
currentSelectedPeriod = StatsPeriodType(rawValue: filterBar.selectedIndex) ?? StatsPeriodType.insights
167+
168+
configureNavBar()
148169
}
149170

150171
}

WordPress/Classes/ViewRelated/Stats/StatsViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ - (void)viewDidLoad
5959
// Being shown in a modal window
6060
if (self.presentingViewController != nil) {
6161
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonTapped:)];
62-
self.navigationItem.rightBarButtonItem = doneButton;
62+
self.navigationItem.leftBarButtonItem = doneButton;
6363
self.title = self.blog.settings.name;
6464
}
6565

0 commit comments

Comments
 (0)