Mailspring/internal_packages/preferences/lib/preferences-root.cjsx
Ben Gotow 606909e256 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 02:19:32 -05:00

87 lines
2.7 KiB
CoffeeScript

React = require 'react'
_ = require 'underscore'
{RetinaImg,
Flexbox,
ConfigPropContainer,
ScrollRegion,
KeyCommandsRegion} = require 'nylas-component-kit'
{PreferencesUIStore} = require 'nylas-exports'
PreferencesSidebar = require './preferences-sidebar'
class PreferencesRoot extends React.Component
@displayName: 'PreferencesRoot'
@containerRequired: false
constructor: (@props) ->
@state = @getStateFromStores()
componentDidMount: =>
React.findDOMNode(@).focus()
@unlisteners = []
@unlisteners.push PreferencesUIStore.listen =>
@setState(@getStateFromStores())
@_focusContent()
componentDidUpdate: =>
@_focusContent()
componentWillUnmount: =>
unlisten() for unlisten in @unlisteners
_localHandlers: ->
stopPropagation = (e) -> e.stopPropagation()
# This prevents some basic commands from propagating to the threads list and
# producing unexpected results
#
# TODO This is a partial/temporary solution and should go away when we do the
# Keymap/Commands/Menu refactor
return {
'core:next-item': stopPropagation
'core:previous-item': stopPropagation
'core:select-up': stopPropagation
'core:select-down': stopPropagation
'core:select-item': stopPropagation
'core:remove-from-view': stopPropagation
'core:messages-page-up': stopPropagation
'core:messages-page-down': stopPropagation
'core:list-page-up': stopPropagation
'core:list-page-down': stopPropagation
'application:archive-item': stopPropagation
'application:delete-item': stopPropagation
'application:print-thread': stopPropagation
}
getStateFromStores: =>
tabs: PreferencesUIStore.tabs()
selection: PreferencesUIStore.selection()
render: =>
tabId = @state.selection.get('tabId')
tab = @state.tabs.find (s) => s.tabId is tabId
if tab
bodyElement = <tab.component accountId={@state.selection.get('accountId')} />
else
bodyElement = <div></div>
<KeyCommandsRegion className="preferences-wrap" tabIndex="1" localHandlers={@_localHandlers()}>
<Flexbox direction="row">
<PreferencesSidebar tabs={@state.tabs}
selection={@state.selection} />
<ScrollRegion className="preferences-content">
<ConfigPropContainer ref="content">
{bodyElement}
</ConfigPropContainer>
</ScrollRegion>
</Flexbox>
</KeyCommandsRegion>
# Focus the first thing with a tabindex when we update.
# inside the content area. This makes it way easier to interact with prefs.
_focusContent: =>
React.findDOMNode(@refs.content).querySelector('[tabindex]')?.focus()
module.exports = PreferencesRoot