Skip to content

Commit

Permalink
feat(archive): shows trash for non-archive accounts
Browse files Browse the repository at this point in the history
Summary:
Fixes T3570
Fixes T3737

Rename ArchiveThreadHelper to RemoveThreadHelper

Rename of `getRemovalTask`

Remove unarchive from `RemoveThreadHelper`. Pass in mailviewfilter

Rename actions

Rename archive action

renmaing

support trash and archive folders in RemoveThreadHelper

Move everything over to trash

add tests

Hide trash and archive

Test Plan: new tests

Reviewers: dillon, bengotow

Reviewed By: dillon, bengotow

Maniphest Tasks: T3570, T3737

Differential Revision: https://phab.nylas.com/D2089
  • Loading branch information
emorikawa committed Oct 1, 2015
1 parent fe077d4 commit ae69790
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 204 deletions.
2 changes: 1 addition & 1 deletion exports/nylas-exports.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class NylasExports
@require "ChangeStarredTask", 'flux/tasks/change-starred-task'
@require "CreateMetadataTask", 'flux/tasks/create-metadata-task'
@require "MarkMessageReadTask", 'flux/tasks/mark-message-read'
@require "ArchiveThreadHelper", 'flux/tasks/archive-thread-helper'
@require "DestroyMetadataTask", 'flux/tasks/destroy-metadata-task'

# Stores
Expand Down Expand Up @@ -134,6 +133,7 @@ class NylasExports
@load "UndoManager", 'flux/undo-manager'
@load "QuotedHTMLParser", 'services/quoted-html-parser'
@load "QuotedPlainTextParser", 'services/quoted-plain-text-parser'
@require "RemoveThreadHelper", 'services/remove-thread-helper'

# Errors
@get "APIError", -> require('../src/flux/errors').APIError
Expand Down
6 changes: 3 additions & 3 deletions internal_packages/message-list/lib/main.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MessageToolbarItems = require "./message-toolbar-items"
SidebarContactList} = require "./sidebar-components"

ThreadStarButton = require './thread-star-button'
ThreadArchiveButton = require './thread-archive-button'
ThreadRemoveButton = require './thread-remove-button'
ThreadToggleUnreadButton = require './thread-toggle-unread-button'

AutolinkerExtension = require './plugins/autolinker-extension'
Expand All @@ -36,7 +36,7 @@ module.exports =
ComponentRegistry.register ThreadStarButton,
role: 'message:Toolbar'

ComponentRegistry.register ThreadArchiveButton,
ComponentRegistry.register ThreadRemoveButton,
role: 'message:Toolbar'

ComponentRegistry.register ThreadToggleUnreadButton,
Expand All @@ -48,7 +48,7 @@ module.exports =
deactivate: ->
ComponentRegistry.unregister MessageList
ComponentRegistry.unregister ThreadStarButton
ComponentRegistry.unregister ThreadArchiveButton
ComponentRegistry.unregister ThreadRemoveButton
ComponentRegistry.unregister ThreadToggleUnreadButton
ComponentRegistry.unregister MessageToolbarItems
ComponentRegistry.unregister SidebarContactCard
Expand Down
24 changes: 0 additions & 24 deletions internal_packages/message-list/lib/thread-archive-button.cjsx

This file was deleted.

37 changes: 37 additions & 0 deletions internal_packages/message-list/lib/thread-remove-button.cjsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
_ = require 'underscore'
React = require 'react'
{Actions,
DOMUtils,
RemoveThreadHelper,
FocusedMailViewStore} = require 'nylas-exports'
{RetinaImg} = require 'nylas-component-kit'

class ThreadRemoveButton extends React.Component
@displayName: "ThreadRemoveButton"
@containerRequired: false

render: =>
focusedMailViewFilter = FocusedMailViewStore.mailView()
return false unless focusedMailViewFilter?.canRemoveThreads()

if RemoveThreadHelper.removeType() is RemoveThreadHelper.Type.Archive
tooltip = "Archive"
imgName = "toolbar-archive.png"
else if RemoveThreadHelper.removeType() is RemoveThreadHelper.Type.Trash
tooltip = "Trash"
imgName = "toolbar-trash.png"

<button className="btn btn-toolbar"
style={order: -106}
data-tooltip={tooltip}
onClick={@_onRemove}>
<RetinaImg name={imgName} mode={RetinaImg.Mode.ContentIsMask}/>
</button>

_onRemove: (e) =>
return unless DOMUtils.nodeIsVisible(e.currentTarget)
Actions.removeCurrentlyFocusedThread()
e.stopPropagation()


module.exports = ThreadRemoveButton
6 changes: 3 additions & 3 deletions internal_packages/thread-list/lib/main.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
React = require "react"
{ComponentRegistry, WorkspaceStore} = require "nylas-exports"

{DownButton, UpButton, ThreadBulkArchiveButton, ThreadBulkStarButton, ThreadBulkToggleUnreadButton} = require "./thread-buttons"
{DownButton, UpButton, ThreadBulkRemoveButton, ThreadBulkStarButton, ThreadBulkToggleUnreadButton} = require "./thread-buttons"
{DraftDeleteButton} = require "./draft-buttons"
ThreadSelectionBar = require './thread-selection-bar'
ThreadList = require './thread-list'
Expand Down Expand Up @@ -44,7 +44,7 @@ module.exports =
location: WorkspaceStore.Sheet.Thread.Toolbar.Right
modes: ['list']

ComponentRegistry.register ThreadBulkArchiveButton,
ComponentRegistry.register ThreadBulkRemoveButton,
role: 'thread:BulkAction'

ComponentRegistry.register ThreadBulkStarButton,
Expand All @@ -61,7 +61,7 @@ module.exports =
ComponentRegistry.unregister DraftSelectionBar
ComponentRegistry.unregister ThreadList
ComponentRegistry.unregister ThreadSelectionBar
ComponentRegistry.unregister ThreadBulkArchiveButton
ComponentRegistry.unregister ThreadBulkRemoveButton
ComponentRegistry.unregister ThreadBulkToggleUnreadButton
ComponentRegistry.unregister DownButton
ComponentRegistry.unregister UpButton
Expand Down
31 changes: 22 additions & 9 deletions internal_packages/thread-list/lib/thread-buttons.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,38 @@ React = require "react/addons"
classNames = require 'classnames'
ThreadListStore = require './thread-list-store'
{RetinaImg} = require 'nylas-component-kit'
{Actions, FocusedContentStore} = require "nylas-exports"
{Actions,
RemoveThreadHelper,
FocusedContentStore,
FocusedMailViewStore} = require "nylas-exports"

class ThreadBulkArchiveButton extends React.Component
@displayName: 'ThreadBulkArchiveButton'
class ThreadBulkRemoveButton extends React.Component
@displayName: 'ThreadBulkRemoveButton'
@containerRequired: false

@propTypes:
selection: React.PropTypes.object.isRequired

render: ->
focusedMailViewFilter = FocusedMailViewStore.mailView()
return false unless focusedMailViewFilter?.canRemoveThreads()

if RemoveThreadHelper.removeType() is RemoveThreadHelper.Type.Archive
tooltip = "Archive"
imgName = "toolbar-archive.png"
else if RemoveThreadHelper.removeType() is RemoveThreadHelper.Type.Trash
tooltip = "Trash"
imgName = "toolbar-trash.png"

<button style={order:-106}
className="btn btn-toolbar"
data-tooltip="Archive"
onClick={@_onArchive}>
<RetinaImg name="toolbar-archive.png" mode={RetinaImg.Mode.ContentIsMask} />
data-tooltip={tooltip}
onClick={@_onRemove}>
<RetinaImg name={imgName} mode={RetinaImg.Mode.ContentIsMask} />
</button>

_onArchive: =>
Actions.archiveSelection()
_onRemove: =>
Actions.removeSelection()


class ThreadBulkStarButton extends React.Component
Expand Down Expand Up @@ -158,4 +171,4 @@ UpButton = React.createClass
UpButton.containerRequired = false
DownButton.containerRequired = false

module.exports = {DownButton, UpButton, ThreadBulkArchiveButton, ThreadBulkStarButton, ThreadBulkToggleUnreadButton}
module.exports = {DownButton, UpButton, ThreadBulkRemoveButton, ThreadBulkStarButton, ThreadBulkToggleUnreadButton}
61 changes: 10 additions & 51 deletions internal_packages/thread-list/lib/thread-list-quick-actions.cjsx
Original file line number Diff line number Diff line change
@@ -1,71 +1,30 @@
_ = require 'underscore'
React = require 'react'
{Actions,
Utils,
Thread,
ArchiveThreadHelper,
CategoryStore,
ChangeFolderTask,
ChangeLabelsTask,
AccountStore} = require 'nylas-exports'
RemoveThreadHelper,
FocusedMailViewStore} = require 'nylas-exports'

class ThreadListQuickActions extends React.Component
@displayName: 'ThreadListQuickActions'
@propTypes:
thread: React.PropTypes.object
categoryId: React.PropTypes.string

render: =>
actions = []
if @_shouldDisplayArchiveButton()
actions.push <div key="archive" className="btn action action-archive" onClick={@_onArchive}></div>
else if AccountStore.current().usesLabels() and @props.categoryId == CategoryStore.getStandardCategory('all').id
actions.push <div key="trash" className="btn action action-trash" onClick={@_onTrash}></div>
focusedMailViewFilter = FocusedMailViewStore.mailView()
return false unless focusedMailViewFilter?.canRemoveThreads()

return false if actions.length is 0
classNames = "btn action action-#{RemoveThreadHelper.removeType()}"

<div className="inner">
{actions}
<div key="remove" className={classNames} onClick={@_onRemove}></div>
</div>

shouldComponentUpdate: (newProps, newState) ->
newProps.thread.id isnt @props?.thread.id

_shouldDisplayArchiveButton: =>
if @props.categoryId not in [CategoryStore.getStandardCategory('archive')?.id, CategoryStore.getStandardCategory('trash')?.id, CategoryStore.getStandardCategory('sent')?.id]
if AccountStore.current().usesLabels()
if @props.thread.labels.length == 1 and (@props.thread.labels[0].name == "archive" or @props.thread.labels[0].name == "all")
return false
return true
else if @props.thread.folders.length == 1 and @props.thread.folders[0].name == "archive"
return false
return true

return false

_onTrash: (event) =>
params =
thread: @props.thread,
labelsToRemove: [CategoryStore.byId(@props.categoryId)],
labelsToAdd: [CategoryStore.getStandardCategory("trash")]
Actions.queueTask(new ChangeLabelsTask(params))
# Don't trigger the thread row click
event.stopPropagation()


_onForward: (event) =>
Actions.composeForward({thread: @props.thread, popout: true})
# Don't trigger the thread row click
event.stopPropagation()

_onReply: (event) =>
Actions.composeReply({thread: @props.thread, popout: true})
# Don't trigger the thread row click
event.stopPropagation()

_onArchive: (event) =>
archiveTask = ArchiveThreadHelper.getArchiveTask([@props.thread])
Actions.queueTask(archiveTask)
_onRemove: (event) =>
focusedMailViewFilter = FocusedMailViewStore.mailView()
t = RemoveThreadHelper.getRemovalTask([@props.thread], focusedMailViewFilter)
Actions.queueTask(t)

# Don't trigger the thread row click
event.stopPropagation()
Expand Down
43 changes: 24 additions & 19 deletions internal_packages/thread-list/lib/thread-list-store.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NylasStore = require 'nylas-store'
ChangeUnreadTask,
ChangeStarredTask,
FocusedContentStore,
ArchiveThreadHelper,
RemoveThreadHelper,
TaskQueueStatusStore,
FocusedMailViewStore} = require 'nylas-exports'

Expand All @@ -22,14 +22,14 @@ class ThreadListStore extends NylasStore
constructor: ->
@_resetInstanceVars()

@listenTo Actions.archiveAndPrevious, @_onArchiveAndPrev
@listenTo Actions.archiveAndNext, @_onArchiveAndNext
@listenTo Actions.removeSelection, @_onRemoveSelection

@listenTo Actions.archiveSelection, @_onArchiveSelection
@listenTo Actions.moveThreads, @_onMoveThreads
@listenTo Actions.removeCurrentlyFocusedThread, @_onRemoveAndAuto
@listenTo Actions.removeAndNext, @_onRemoveAndNext
@listenTo Actions.removeAndPrevious, @_onRemoveAndPrev

@listenTo Actions.archive, @_onArchive
@listenTo Actions.moveThread, @_onMoveThread
@listenTo Actions.moveThreads, @_onMoveThreads

@listenTo Actions.toggleStarSelection, @_onToggleStarSelection
@listenTo Actions.toggleStarFocused, @_onToggleStarFocused
Expand Down Expand Up @@ -158,24 +158,29 @@ class ThreadListStore extends NylasStore
task = new ChangeUnreadTask {threads, unread}
Actions.queueTask task

_onArchive: ->
@_archiveAndShiftBy('auto')
_onRemoveAndAuto: ->
@_removeAndShiftBy('auto')

_onArchiveAndPrev: ->
@_archiveAndShiftBy(-1)
_onRemoveAndPrev: ->
@_removeAndShiftBy(-1)

_onArchiveAndNext: ->
@_archiveAndShiftBy(1)
_onRemoveAndNext: ->
@_removeAndShiftBy(1)

_archiveAndShiftBy: (offset) ->
_removeAndShiftBy: (offset) ->
mailViewFilter = FocusedMailViewStore.mailView()
return unless mailViewFilter.canApplyToThreads()
focused = FocusedContentStore.focused('thread')
return unless focused
task = ArchiveThreadHelper.getArchiveTask([focused])
task = RemoveThreadHelper.getRemovalTask([focused], mailViewFilter)
@_moveAndShiftBy(offset, task)

_onArchiveSelection: ->
_onRemoveSelection: ->
mailViewFilter = FocusedMailViewStore.mailView()
return unless mailViewFilter.canApplyToThreads()
selectedThreads = @_view.selection.items()
task = ArchiveThreadHelper.getArchiveTask(selectedThreads)
return unless selectedThreads.length > 0
task = RemoveThreadHelper.getRemovalTask(selectedThreads, mailViewFilter)
@_onMoveThreads(selectedThreads, task)

_onMoveThread: (thread, task) ->
Expand Down Expand Up @@ -233,13 +238,13 @@ class ThreadListStore extends NylasStore
# Remove the current thread from selection
@_view.selection.remove(focused)

# If the user is in list mode and archived without specifically saying
# "archive and next" or "archive and prev", return to the thread list
# If the user is in list mode and removed without specifically saying
# "remove and next" or "remove and prev", return to the thread list
# instead of focusing on the next message.
if layoutMode is 'list' and not explicitOffset
nextFocus = null

# Archive the current thread
# Remove the current thread
TaskQueueStatusStore.waitForPerformLocal(task).then =>
Actions.setFocus(collection: 'thread', item: nextFocus)
Actions.setCursorPosition(collection: 'thread', item: nextKeyboard)
Expand Down
17 changes: 8 additions & 9 deletions internal_packages/thread-list/lib/thread-list.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ class ThreadList extends React.Component
c5 = new ListTabular.Column
name: "HoverActions"
resolver: (thread) =>
currentCategoryId = FocusedMailViewStore.mailView()?.categoryId()
<ThreadListQuickActions thread={thread} categoryId={currentCategoryId}/>
<ThreadListQuickActions thread={thread} />

@wideColumns = [c1, c2, c3, c4, c5]

Expand Down Expand Up @@ -167,10 +166,10 @@ class ThreadList extends React.Component
@narrowColumns = [cNarrow]

@commands =
'core:remove-item': @_onArchive
'core:remove-item': @_onRemoveItem
'core:star-item': @_onStarItem
'core:remove-and-previous': -> Actions.archiveAndPrevious()
'core:remove-and-next': -> Actions.archiveAndNext()
'core:remove-and-previous': -> Actions.removeAndPrevious()
'core:remove-and-next': -> Actions.removeAndNext()

@itemPropsProvider = (item) ->
className: classNames
Expand Down Expand Up @@ -257,15 +256,15 @@ class ThreadList extends React.Component
else
Actions.toggleStarFocused()

_onArchive: =>
_onRemoveItem: =>
return unless ThreadListStore.view()

if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread
Actions.archive()
Actions.removeCurrentlyFocusedThread()
else if ThreadListStore.view().selection.count() > 0
Actions.archiveSelection()
Actions.removeSelection()
else
Actions.archive()
Actions.removeCurrentlyFocusedThread()


module.exports = ThreadList
Loading

0 comments on commit ae69790

Please sign in to comment.