fix(message-list): Only display labels when usesLabels()

This commit is contained in:
Ben Gotow 2016-01-28 10:46:33 -08:00
parent 7ef187e882
commit da68b393a2
6 changed files with 8 additions and 12 deletions

View file

@ -301,7 +301,7 @@ class CategoryPicker extends React.Component
_categoryUsageCount: (props, categories) =>
categoryUsageCount = {}
_.flatten(@_threads(props).map(@_threadCategories)).forEach (category) ->
_.flatten(_.pluck(@_threads(props), 'categories')).forEach (category) ->
categoryUsageCount[category.id] ?= 0
categoryUsageCount[category.id] += 1
return categoryUsageCount
@ -339,13 +339,6 @@ class CategoryPicker extends React.Component
item.numThreads = numThreads
item
_threadCategories: (thread) =>
if @_account.usesLabels()
return (thread.labels ? [])
else if @_account.usesFolders()
return (thread.folders ? [])
else throw new Error("Invalid organizationUnit")
_threads: (props = @props) =>
if props.items then return (props.items ? [])
else if props.thread then return [props.thread]

View file

@ -8,6 +8,7 @@ MessageItemContainer = require './message-item-container'
Message,
DraftStore,
MessageStore,
AccountStore,
DatabaseStore,
WorkspaceStore,
ChangeLabelsTask,
@ -244,6 +245,8 @@ class MessageList extends React.Component
</div>
_renderLabels: =>
account = AccountStore.accountForId(@state.currentThread.accountId)
return false unless account.usesLabels()
labels = @state.currentThread.sortedCategories()
labels = _.reject labels, (l) -> l.name is 'important'
labels.map (label) =>

View file

@ -53,7 +53,7 @@ class MailImportantIcon extends React.Component
render: =>
return false unless @state.visible
isImportant = @state.categoryId and _.findWhere(@props.thread.labels, {id: @state.categoryId})?
isImportant = @state.categoryId and _.findWhere(@props.thread.categories, {id: @state.categoryId})?
classes = classNames
'mail-important-icon': true

View file

@ -15,7 +15,7 @@ join table associating the ID of the model with the IDs of models in the collect
Collection attributes have an additional clause builder, `contains`:
```coffee
DatabaseStore.findAll(Thread).where([Thread.attributes.labels.contains('inbox')])
DatabaseStore.findAll(Thread).where([Thread.attributes.categories.contains('inbox')])
```
This is equivalent to writing the following SQL:

View file

@ -25,7 +25,7 @@ query.then (thread) ->
```coffee
query = DatabaseStore.findAll(Thread)
query.where([Thread.attributes.labels.contains('label-id')])
query.where([Thread.attributes.categories.contains('label-id')])
.order([Thread.attributes.lastMessageReceivedTimestamp.descending()])
.limit(100).offset(50)
.then (threads) ->

View file

@ -35,7 +35,7 @@ class DatabaseSetupQueryBuilder
# Identify collection attributes that can be matched against. These require
# JOIN tables. (Right now the only one of these is Thread.folders or
# Thread.labels)
# Thread.categories)
collectionAttributes = _.filter attributes, (attr) ->
attr.queryable && attr instanceof AttributeCollection
collectionAttributes.forEach (attribute) ->