Skip to content

Commit

Permalink
Update page context menu with Stats and Settings (#23065)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Apr 23, 2024
2 parents c7c1ff1 + 534ffff commit e79ee20
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 44 deletions.
3 changes: 2 additions & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
24.8
-----

* [*] Move "Settings" context menu action in "Pages" from the submenu to a separate section to make it easily discoverable and make it available for unpublished posts [#23065]
* [*] Add "Stats" context menu action to "Pages" [#23065]

24.7
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ extension PageListViewController: InteractivePostViewDelegate {
viewPost(apost)
}

func stats(for apost: AbstractPost) {
// Not available for pages
}

func duplicate(_ apost: AbstractPost) {
guard let page = apost as? Page else { return }
copyPage(page)
Expand Down
17 changes: 12 additions & 5 deletions WordPress/Classes/ViewRelated/Pages/PageMenuViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ final class PageMenuViewModelTests: CoreDataTestCase {
[.view],
[.moveToDraft, .duplicate, .share],
[.blaze],
[.setParent, .setHomepage, .setPostsPage, .settings],
[.setParent, .setHomepage, .setPostsPage],
[.stats, .settings],
[.trash]
]
expect(buttons).to(equal(expectedButtons))
Expand All @@ -53,7 +54,8 @@ final class PageMenuViewModelTests: CoreDataTestCase {
let expectedButtons: [[AbstractPostButton]] = [
[.view],
[.moveToDraft, .duplicate, .share],
[.setParent, .setHomepage, .setPostsPage, .settings],
[.setParent, .setHomepage, .setPostsPage],
[.stats, .settings],
[.trash]
]
expect(buttons).to(equal(expectedButtons))
Expand All @@ -80,7 +82,8 @@ final class PageMenuViewModelTests: CoreDataTestCase {
let expectedButtons: [[AbstractPostButton]] = [
[.view],
[.moveToDraft, .duplicate, .share],
[.setParent, .setHomepage, .setPostsPage, .settings],
[.setParent, .setHomepage, .setPostsPage],
[.settings],
[.trash]
]
expect(buttons).to(equal(expectedButtons))
Expand Down Expand Up @@ -108,7 +111,8 @@ final class PageMenuViewModelTests: CoreDataTestCase {
[.view],
[.duplicate, .share],
[.blaze],
[.setParent, .setPostsPage, .settings]
[.setParent, .setPostsPage],
[.stats, .settings]
]
expect(buttons).to(equal(expectedButtons))
}
Expand All @@ -135,7 +139,8 @@ final class PageMenuViewModelTests: CoreDataTestCase {
[.view],
[.moveToDraft, .duplicate, .share],
[.blaze],
[.setParent, .setHomepage, .setRegularPage, .settings],
[.setParent, .setHomepage, .setRegularPage],
[.stats, .settings],
[.trash]
]
expect(buttons).to(equal(expectedButtons))
Expand All @@ -156,6 +161,7 @@ final class PageMenuViewModelTests: CoreDataTestCase {
[.view],
[.publish, .duplicate],
[.setParent],
[.settings],
[.trash]
]
expect(buttons).to(equal(expectedButtons))
Expand All @@ -176,6 +182,7 @@ final class PageMenuViewModelTests: CoreDataTestCase {
[.view],
[.moveToDraft],
[.setParent],
[.settings],
[.trash]
]
expect(buttons).to(equal(expectedButtons))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,37 @@ class AbstractPostListViewController: UIViewController,
}
}

func stats(for post: AbstractPost) {
viewStatsForPost(post)
}

fileprivate func viewStatsForPost(_ post: AbstractPost) {
// Check the blog
let blog = post.blog

guard blog.supports(.stats) else {
// Needs Jetpack.
return
}

WPAnalytics.track(.postListStatsAction, withProperties: propertiesForAnalytics())

// Push the Post Stats ViewController
guard let postID = post.postID as? Int else {
return
}

SiteStatsInformation.sharedInstance.siteTimeZone = blog.timeZone
SiteStatsInformation.sharedInstance.oauth2Token = blog.authToken
SiteStatsInformation.sharedInstance.siteID = blog.dotComID

let postURL = URL(string: post.permaLink! as String)
let postStatsTableViewController = PostStatsTableViewController.withJPBannerForBlog(postID: postID,
postTitle: post.titleForDisplay(),
postURL: postURL)
navigationController?.pushViewController(postStatsTableViewController, animated: true)
}

@objc func copyPostLink(_ post: AbstractPost) {
let pasteboard = UIPasteboard.general
guard let link = post.permaLink else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ extension AbstractPostButton: AbstractPostMenuAction {
case .retry: return UIImage(systemName: "arrow.clockwise")
case .view: return UIImage(systemName: "safari")
case .publish: return UIImage(systemName: "tray.and.arrow.up")
case .stats: return UIImage(systemName: "chart.bar.xaxis")
case .stats: return UIImage(systemName: "chart.line.uptrend.xyaxis")
case .duplicate: return UIImage(systemName: "doc.on.doc")
case .moveToDraft: return UIImage(systemName: "pencil.line")
case .trash: return UIImage(systemName: "trash")
Expand Down
12 changes: 10 additions & 2 deletions WordPress/Classes/ViewRelated/Post/PageMenuViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class PageMenuViewModel: AbstractPostMenuViewModel {
createSecondarySection(),
createBlazeSection(),
createSetPageAttributesSection(),
createNavigationSection(),
createTrashSection()
]
}
Expand Down Expand Up @@ -124,11 +125,18 @@ final class PageMenuViewModel: AbstractPostMenuViewModel {
} else {
buttons.append(.setRegularPage)
}
return AbstractPostButtonSection(buttons: buttons, submenuButton: .pageAttributes)
}

private func createNavigationSection() -> AbstractPostButtonSection {
var buttons = [AbstractPostButton]()
if isJetpackFeaturesEnabled, page.status == .publish && page.hasRemote() {
buttons.append(.stats)
}
if page.status != .trash {
buttons.append(.settings)
}

return AbstractPostButtonSection(buttons: buttons, submenuButton: .pageAttributes)
return AbstractPostButtonSection(buttons: buttons)
}

private func createTrashSection() -> AbstractPostButtonSection {
Expand Down
31 changes: 0 additions & 31 deletions WordPress/Classes/ViewRelated/Post/PostListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,33 +212,6 @@ final class PostListViewController: AbstractPostListViewController, InteractiveP
PostListEditorPresenter.handleCopy(post: post, in: self)
}

fileprivate func viewStatsForPost(_ post: AbstractPost) {
// Check the blog
let blog = post.blog

guard blog.supports(.stats) else {
// Needs Jetpack.
return
}

WPAnalytics.track(.postListStatsAction, withProperties: propertiesForAnalytics())

// Push the Post Stats ViewController
guard let postID = post.postID as? Int else {
return
}

SiteStatsInformation.sharedInstance.siteTimeZone = blog.timeZone
SiteStatsInformation.sharedInstance.oauth2Token = blog.authToken
SiteStatsInformation.sharedInstance.siteID = blog.dotComID

let postURL = URL(string: post.permaLink! as String)
let postStatsTableViewController = PostStatsTableViewController.withJPBannerForBlog(postID: postID,
postTitle: post.titleForDisplay(),
postURL: postURL)
navigationController?.pushViewController(postStatsTableViewController, animated: true)
}

// MARK: - InteractivePostViewDelegate

func edit(_ post: AbstractPost) {
Expand All @@ -249,10 +222,6 @@ final class PostListViewController: AbstractPostListViewController, InteractiveP
viewPost(post)
}

func stats(for post: AbstractPost) {
viewStatsForPost(post)
}

func duplicate(_ post: AbstractPost) {
editDuplicatePost(post)
}
Expand Down

0 comments on commit e79ee20

Please sign in to comment.