[client-app] Measure and report times for removing from inbox

Summary:
This commit adds a new action, `removeThreadsFromView` to be proxied and
measured through the ThreadListActionsStore

This action can encompass many different actions, e.g.:
- unstarring in starred view
- changing unread in unread view
- Moving to inbox from trash
- archiving a search result (which won't actually remove it from the thread-list)

However, for now, we are only interested in timing actions that remove threads
from the inbox

Depends on D3983

Test Plan: manual

Reviewers: halla, spang, evan

Reviewed By: spang, evan

Differential Revision: https://phab.nylas.com/D3984
This commit is contained in:
Juan Tejada 2017-02-20 17:42:35 -08:00
parent a8fbcb0c93
commit 90e49d31aa
5 changed files with 39 additions and 11 deletions

View file

@ -139,6 +139,8 @@ class ThreadList extends React.Component
props =
className: classes
# TODO this swiping logic needs some serious cleanup
props.shouldEnableSwipe = =>
perspective = FocusedPerspectiveStore.current()
tasks = perspective.tasksForRemovingItems([item], CategoryRemovalTargetRulesets.Default, "Swipe")
@ -149,7 +151,6 @@ class ThreadList extends React.Component
tasks = perspective.tasksForRemovingItems([item], CategoryRemovalTargetRulesets.Default, "Swipe")
return null if tasks.length is 0
# TODO this logic is brittle
task = tasks[0]
name = if task instanceof ChangeStarredTask
'unstar'
@ -163,9 +164,11 @@ class ThreadList extends React.Component
props.onSwipeRight = (callback) ->
perspective = FocusedPerspectiveStore.current()
tasks = perspective.tasksForRemovingItems([item], CategoryRemovalTargetRulesets.Default, "Swipe")
callback(false) if tasks.length is 0
if tasks.length is 0
callback(false)
return
Actions.removeThreadsFromView({threads: [item], source: 'Swipe', ruleset: CategoryRemovalTargetRulesets.Default})
Actions.closePopover()
Actions.queueTasks(tasks)
callback(true)
disabledPackages = NylasEnv.config.get('core.disabledPackages') ? []
@ -315,10 +318,9 @@ class ThreadList extends React.Component
_onRemoveFromView: (ruleset = CategoryRemovalTargetRulesets.Default) =>
threads = @_threadsForKeyboardAction()
return unless threads
current = FocusedPerspectiveStore.current()
tasks = current.tasksForRemovingItems(threads, ruleset, "Keyboard Shortcut")
Actions.queueTasks(tasks)
if not threads
return
Actions.removeThreadsFromView({threads, ruleset, source: "Keyboard Shortcut"})
Actions.popSheet()
_onArchiveItem: =>

View file

@ -32,7 +32,7 @@ class SearchMailboxPerspective extends MailboxPerspective {
tasksForRemovingItems(threads) {
return TaskFactory.tasksForApplyingCategories({
source: "Dragged Out of List",
source: "Removing from Search Results",
threads: threads,
categoriesToAdd: (accountId) => {
const account = AccountStore.accountForId(accountId)

View file

@ -567,6 +567,7 @@ class Actions {
// Thread list actions
static archiveThreads = ActionScopeWindow;
static removeThreadsFromView = ActionScopeWindow;
static threadListDidUpdate = ActionScopeWindow;
}

View file

@ -4,6 +4,7 @@ import Actions from '../actions'
import Utils from '../models/utils'
import TaskFactory from '../tasks/task-factory'
import IdentityStore from '../stores/identity-store'
import FocusedPerspectiveStore from '../stores/focused-perspective-store'
class ThreadListActionsStore extends NylasStore {
@ -15,6 +16,7 @@ class ThreadListActionsStore extends NylasStore {
activate() {
this.listenTo(Actions.archiveThreads, this._onArchiveThreads)
this.listenTo(Actions.removeThreadsFromView, this._onRemoveThreadsFromView)
this.listenTo(Actions.threadListDidUpdate, this._onThreadListDidUpdate)
}
@ -71,6 +73,26 @@ class ThreadListActionsStore extends NylasStore {
const tasks = TaskFactory.tasksForArchiving({threads, source})
Actions.queueTasks(tasks)
}
_onRemoveThreadsFromView = ({threads, ruleset, source} = {}) => {
if (threads.length === 0) { return }
const perspective = FocusedPerspectiveStore.current()
const tasks = perspective.tasksForRemovingItems(threads, ruleset, source)
// This action can encompass many different actions, e.g.:
// - unstarring in starred view
// - changing unread in unread view
// - Moving to inbox from trash
// - archiving a search result (which won't actually remove it from the thread-list)
// For now, we are only interested in timing actions that remove threads
// from the inbox
if (perspective.isInbox()) {
// TODO figure out the `targetCategory`
this._setNewTimer({threads, source, action: 'remove-from-view'})
}
Actions.queueTasks(tasks)
}
}
export default new ThreadListActionsStore()

View file

@ -214,10 +214,10 @@ class StarredMailboxPerspective extends MailboxPerspective
task = new ChangeStarredTask({threads:threadsOrIds, starred: true, source: "Dragged Into List"})
Actions.queueTask(task)
tasksForRemovingItems: (threads) =>
tasksForRemovingItems: (threads, ruleset, source) =>
task = TaskFactory.taskForInvertingStarred({
threads: threads
source: "Removed From List"
source: source || "Removed From List"
})
return [task]
@ -358,6 +358,8 @@ class CategoryMailboxPerspective extends MailboxPerspective
# )
#
tasksForRemovingItems: (threads, ruleset, source) =>
if threads.length is 0
return []
if not ruleset
throw new Error("tasksForRemovingItems: you must pass a ruleset object to determine the destination of the threads")
@ -367,7 +369,8 @@ class CategoryMailboxPerspective extends MailboxPerspective
else
@categoriesSharedName()
return [] if ruleset[name] is null
if ruleset[name] is null
return []
return TaskFactory.tasksForApplyingCategories(
source: source || "Removed From List",