Skip to content

Commit

Permalink
Add addBookmark function and call it and delete from menus
Browse files Browse the repository at this point in the history
  • Loading branch information
yoanarios committed Jan 21, 2025
1 parent cbf3c76 commit 50d8b58
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Storage
class ActionProviderBuilder {
private var actions = [UIAction]()
private var taskId = UIBackgroundTaskIdentifier(rawValue: 0)
private let bookmarksTelemetry = BookmarksTelemetry()

func build() -> [UIAction] {
return actions
Expand Down Expand Up @@ -44,12 +45,9 @@ class ActionProviderBuilder {
title: .ContextMenuBookmarkLink,
image: UIImage.templateImageNamed(StandardImageIdentifiers.Large.bookmark),
identifier: UIAction.Identifier("linkContextMenu.bookmarkLink")
) { _ in
) { [weak self] _ in
addBookmark(url.absoluteString, title, nil)
TelemetryWrapper.recordEvent(category: .action,
method: .add,
object: .bookmark,
value: .contextMenu)
self?.bookmarksTelemetry.addBookmark(eventLabel: .contextMenu)
}
)
}
Expand All @@ -60,12 +58,9 @@ class ActionProviderBuilder {
title: .RemoveBookmarkContextMenuTitle,
image: UIImage.templateImageNamed(StandardImageIdentifiers.Large.cross),
identifier: UIAction.Identifier("linkContextMenu.removeBookmarkLink")
) { _ in
) { [weak self] _ in
removeBookmark(url, title, nil)
TelemetryWrapper.recordEvent(category: .action,
method: .delete,
object: .bookmark,
value: .contextMenu)
self?.bookmarksTelemetry.deleteBookmark(eventLabel: .contextMenu)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class HomepageContextMenuHelper: HomepageContextMenuProtocol,
weak var browserNavigationHandler: BrowserNavigationHandler?
weak var delegate: ContextHelperDelegate?
var getPopoverSourceRect: ((UIView?) -> CGRect)?
private let bookmarksTelemetry = BookmarksTelemetry()

init(
viewModel: HomepageViewModel,
Expand Down Expand Up @@ -208,8 +209,7 @@ class HomepageContextMenuHelper: HomepageContextMenuProtocol,

let url = URL(string: site.url)
self.delegate?.homePanelDidRequestBookmarkToast(url: url, action: .remove)

TelemetryWrapper.recordEvent(category: .action, method: .delete, object: .bookmark, value: .activityStream)
self.bookmarksTelemetry.deleteBookmark(eventLabel: .activityStream)
})
}

Expand All @@ -234,8 +234,7 @@ class HomepageContextMenuHelper: HomepageContextMenuProtocol,
site.setBookmarked(true)

self.delegate?.homePanelDidRequestBookmarkToast(url: nil, action: .add)

TelemetryWrapper.recordEvent(category: .action, method: .add, object: .bookmark, value: .activityStream)
self.bookmarksTelemetry.addBookmark(eventLabel: .activityStream)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,35 @@ struct BookmarksTelemetry {
enum EventLabel: String {
case bookmarksPanel = "bookmarks-panel"
case topSites = "top-sites"
case activityStream = "activity-stream"
case contextMenu = "page-action-menu"
}

init(gleanWrapper: GleanWrapper = DefaultGleanWrapper()) {
self.gleanWrapper = gleanWrapper
}

func addBookmarkFolder() {
gleanWrapper.recordEvent(for: GleanMetrics.Bookmarks.folderAdd)
func addBookmark(eventLabel: EventLabel) {
gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.add,
label: eventLabel.rawValue)
}

func deleteBookmark() {
func deleteBookmark(eventLabel: EventLabel) {
gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.delete,
label: EventLabel.bookmarksPanel.rawValue)
label: eventLabel.rawValue)
}

func openBookmarksSite(eventLabel: EventLabel) {
gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.open, label: eventLabel.rawValue)
gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.open,
label: eventLabel.rawValue)
}

func editBookmark(eventLabel: EventLabel) {
gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.edit, label: eventLabel.rawValue)
gleanWrapper.recordLabel(for: GleanMetrics.Bookmarks.edit,
label: eventLabel.rawValue)
}

func addBookmarkFolder() {
gleanWrapper.recordEvent(for: GleanMetrics.Bookmarks.folderAdd)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ class BookmarksViewController: SiteTableViewController,
guard let strongSelf = self else { completion(false); return }

strongSelf.deleteBookmarkNodeAtIndexPath(indexPath)
strongSelf.bookmarksTelemetry.deleteBookmark()
strongSelf.bookmarksTelemetry.deleteBookmark(eventLabel: .bookmarksPanel)
completion(true)
}

Expand Down Expand Up @@ -734,7 +734,7 @@ extension BookmarksViewController: LibraryPanelContextMenu {
iconString: StandardImageIdentifiers.Large.bookmarkSlash,
tapHandler: { _ in
self.deleteBookmarkNodeAtIndexPath(indexPath)
self.bookmarksTelemetry.deleteBookmark()
self.bookmarksTelemetry.deleteBookmark(eventLabel: .bookmarksPanel)
}).items
actions.append(removeAction)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class LegacyBookmarksPanel: SiteTableViewController,
guard let strongSelf = self else { completion(false); return }

strongSelf.deleteBookmarkNodeAtIndexPath(indexPath)
strongSelf.bookmarksTelemetry.deleteBookmark()
strongSelf.bookmarksTelemetry.deleteBookmark(eventLabel: .bookmarksPanel)
completion(true)
}

Expand Down Expand Up @@ -551,7 +551,7 @@ extension LegacyBookmarksPanel: LibraryPanelContextMenu {
iconString: StandardImageIdentifiers.Large.bookmarkSlash,
tapHandler: { [weak self] _ in
self?.deleteBookmarkNodeAtIndexPath(indexPath)
self?.bookmarksTelemetry.deleteBookmark()
self?.bookmarksTelemetry.deleteBookmark(eventLabel: .bookmarksPanel)
}).items
actions.append(removeAction)

Expand Down

0 comments on commit 50d8b58

Please sign in to comment.