2015-11-24 04:20:51 +08:00
|
|
|
React = require 'react'
|
2015-12-01 03:43:49 +08:00
|
|
|
Immutable = require 'immutable'
|
2015-11-24 04:20:51 +08:00
|
|
|
_ = require 'underscore'
|
2015-12-01 03:43:49 +08:00
|
|
|
classNames = require 'classnames'
|
|
|
|
{RetinaImg, Flexbox, DisclosureTriangle} = require 'nylas-component-kit'
|
|
|
|
{Actions, AccountStore} = require 'nylas-exports'
|
|
|
|
{PreferencesUIStore} = require 'nylas-exports'
|
|
|
|
|
|
|
|
class PreferencesSidebarItem extends React.Component
|
|
|
|
@displayName: 'PreferencesSidebarItem'
|
|
|
|
@propTypes:
|
|
|
|
accounts: React.PropTypes.array
|
|
|
|
selection: React.PropTypes.instanceOf(Immutable.Map).isRequired
|
|
|
|
tabItem: React.PropTypes.instanceOf(PreferencesUIStore.TabItem).isRequired
|
|
|
|
|
|
|
|
constructor: ->
|
|
|
|
@state =
|
|
|
|
collapsed: true
|
|
|
|
|
|
|
|
render: =>
|
|
|
|
{tabId, displayName, componentRequiresAccount} = @props.tabItem
|
|
|
|
|
|
|
|
subitems = @_renderSubitems()
|
|
|
|
subitemsComponent = <ul className="subitems">{subitems}</ul>
|
|
|
|
if @state.collapsed
|
|
|
|
subitemsComponent = false
|
|
|
|
|
|
|
|
classes = classNames
|
|
|
|
"item": true
|
|
|
|
"active": tabId is @props.selection.get('tabId')
|
|
|
|
"has-subitems": subitems isnt false
|
|
|
|
|
feat(mail-rules): Per-account mail rules filter incoming, existing mail
Summary:
Originally, this was going to be a totally independent package, but
I wasn't able to isolate the functionality and get it tied in to
the delta-stream consumption. Here's how it currently works:
- The preferences package has a new tab which allows you to edit
mail filters. Filters are saved in a new core store, and a new
stock component (ScenarioEditor) renders the editor. The editor
takes a set of templates that define a value space, and outputs
a valid set of values.
- A new MailFilterProcessor takes messages and creates tasks to
apply the actions from the MailFiltersStore.
- The worker-sync package now uses the MailFilterProcessor to
apply filters /before/ it calls didPassivelyReceiveNewModels,
so filtrs are applied before any notifications are created.
- A new task, ReprocessMailFiltersTask allows you to run filters
on all of your existing mail. It leverages the existing TaskQueue
architecture to: a) resume where it left off if you quit midway,
b) be queryable (for status) from all windows and c) cancelable.
The TaskQueue is a bit strange because it runs performLocal and
performRemote very differently, and I had to use `performRemote`.
(todo refactor soon.)
This diff also changes the EditableList a bit to behave like a
controlled component and render focused / unfocused states.
Test Plan: Run tests, only for actual filter processing atm.
Reviewers: juan, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D2379
2015-12-23 15:19:32 +08:00
|
|
|
<div className={classes} onClick={@_onClick}>
|
2015-12-01 03:43:49 +08:00
|
|
|
<DisclosureTriangle
|
|
|
|
collapsed={@state.collapsed}
|
|
|
|
visible={subitems isnt false}
|
|
|
|
onToggleCollapsed={@_onClick} />
|
|
|
|
<div className="name">{displayName}</div>
|
|
|
|
{subitemsComponent}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_renderSubitems: =>
|
|
|
|
if @props.tabItem.componentRequiresAccount
|
|
|
|
@props.accounts.map (account) =>
|
|
|
|
classes = classNames
|
|
|
|
"subitem": true
|
|
|
|
"active": account.id is @props.selection.get('accountId')
|
|
|
|
|
2015-12-01 09:11:57 +08:00
|
|
|
<li key={account.id}
|
|
|
|
className={classes}
|
|
|
|
onClick={ (event) => @_onClickAccount(event, account.id)}>
|
2015-12-01 03:43:49 +08:00
|
|
|
{account.emailAddress}
|
|
|
|
</li>
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
|
|
|
|
_onClick: =>
|
|
|
|
if @props.tabItem.componentRequiresAccount
|
|
|
|
@setState(collapsed: !@state.collapsed)
|
|
|
|
else
|
|
|
|
Actions.switchPreferencesTab(@props.tabItem.tabId)
|
|
|
|
|
|
|
|
_onClickAccount: (event, accountId) =>
|
|
|
|
Actions.switchPreferencesTab(@props.tabItem.tabId, {accountId})
|
|
|
|
event.stopPropagation()
|
|
|
|
|
2015-11-24 04:20:51 +08:00
|
|
|
|
|
|
|
class PreferencesSidebar extends React.Component
|
|
|
|
@displayName: 'PreferencesSidebar'
|
|
|
|
|
|
|
|
@propTypes:
|
2015-12-01 03:43:49 +08:00
|
|
|
tabs: React.PropTypes.instanceOf(Immutable.List).isRequired
|
|
|
|
selection: React.PropTypes.instanceOf(Immutable.Map).isRequired
|
|
|
|
|
|
|
|
constructor: ->
|
|
|
|
@state =
|
|
|
|
accounts: AccountStore.items()
|
|
|
|
|
|
|
|
componentDidMount: =>
|
|
|
|
@unsub = AccountStore.listen @_onAccountsChanged
|
|
|
|
|
|
|
|
componentWillUnmount: =>
|
|
|
|
@unsub?()
|
2015-11-24 04:20:51 +08:00
|
|
|
|
|
|
|
render: =>
|
|
|
|
<div className="preferences-sidebar">
|
2015-12-01 03:43:49 +08:00
|
|
|
{ @props.tabs.map (tabItem) =>
|
|
|
|
<PreferencesSidebarItem
|
feat(mail-rules): Per-account mail rules filter incoming, existing mail
Summary:
Originally, this was going to be a totally independent package, but
I wasn't able to isolate the functionality and get it tied in to
the delta-stream consumption. Here's how it currently works:
- The preferences package has a new tab which allows you to edit
mail filters. Filters are saved in a new core store, and a new
stock component (ScenarioEditor) renders the editor. The editor
takes a set of templates that define a value space, and outputs
a valid set of values.
- A new MailFilterProcessor takes messages and creates tasks to
apply the actions from the MailFiltersStore.
- The worker-sync package now uses the MailFilterProcessor to
apply filters /before/ it calls didPassivelyReceiveNewModels,
so filtrs are applied before any notifications are created.
- A new task, ReprocessMailFiltersTask allows you to run filters
on all of your existing mail. It leverages the existing TaskQueue
architecture to: a) resume where it left off if you quit midway,
b) be queryable (for status) from all windows and c) cancelable.
The TaskQueue is a bit strange because it runs performLocal and
performRemote very differently, and I had to use `performRemote`.
(todo refactor soon.)
This diff also changes the EditableList a bit to behave like a
controlled component and render focused / unfocused states.
Test Plan: Run tests, only for actual filter processing atm.
Reviewers: juan, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D2379
2015-12-23 15:19:32 +08:00
|
|
|
key={tabItem.tabId}
|
2015-12-01 03:43:49 +08:00
|
|
|
tabItem={tabItem}
|
|
|
|
accounts={@state.accounts}
|
|
|
|
selection={@props.selection} />
|
2015-11-24 04:20:51 +08:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
2015-12-01 03:43:49 +08:00
|
|
|
_onAccountsChanged: =>
|
|
|
|
@setState(accounts: AccountStore.items())
|
2015-11-24 04:20:51 +08:00
|
|
|
|
|
|
|
module.exports = PreferencesSidebar
|