2015-02-07 06:46:30 +08:00
|
|
|
React = require 'react'
|
2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2015-02-07 06:46:30 +08:00
|
|
|
|
2015-07-16 22:41:04 +08:00
|
|
|
{Utils, Contact, ContactStore} = require 'nylas-exports'
|
2015-05-15 08:08:30 +08:00
|
|
|
{TokenizingTextField, Menu} = require 'nylas-component-kit'
|
2015-02-07 06:46:30 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
class ParticipantsTextField extends React.Component
|
|
|
|
@displayName: 'ParticipantsTextField'
|
2015-02-07 06:46:30 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
@propTypes:
|
2015-02-07 06:46:30 +08:00
|
|
|
# The tab index of the ParticipantsTextField
|
|
|
|
tabIndex: React.PropTypes.string,
|
|
|
|
|
|
|
|
# The name of the field, used for both display purposes and also
|
|
|
|
# to modify the `participants` provided.
|
|
|
|
field: React.PropTypes.string,
|
|
|
|
|
|
|
|
# An object containing arrays of participants. Typically, this is
|
|
|
|
# {to: [], cc: [], bcc: []}. Each ParticipantsTextField needs all of
|
|
|
|
# the values, because adding an element to one field may remove it
|
|
|
|
# from another.
|
|
|
|
participants: React.PropTypes.object.isRequired,
|
|
|
|
|
|
|
|
# The function to call with an updated `participants` object when
|
|
|
|
# changes are made.
|
|
|
|
change: React.PropTypes.func.isRequired,
|
|
|
|
|
feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.
This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.
When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.
Search bar doesn't need to do full refresh on clear if it never committed
Allow drafts to be switched to a different account when not in reply to an existing thread
Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal
Show many dots for many accounts in long polling status bar
add/remove accounts from prefs
Spec fixes!
Test Plan: Run tests, none broken!
Reviewers: evan, dillon
Reviewed By: evan, dillon
Differential Revision: https://phab.nylas.com/D1928
2015-08-22 06:29:58 +08:00
|
|
|
className: React.PropTypes.string
|
|
|
|
|
2015-12-09 09:44:20 +08:00
|
|
|
onEmptied: React.PropTypes.func
|
|
|
|
|
|
|
|
onFocus: React.PropTypes.func
|
|
|
|
|
feat(unsafe-components): Wrap injected components, catch exceptions, clean up ComponentRegistry
Summary:
This diff gives the ComponentRegistry a cleaner, smaller API. Instead of querying by name, location or role,
it's now just location and role, and you can register components for one or more location and one or more
roles without assigning the entries in the registry separate names.
When you register with the ComponentRegistry, the syntax is also cleaner and uses the component's displayName
instead of requiring you to provide a name. You also provide the actual component when unregistering, ensuring
that you can't unregister someone else's component.
InjectedComponent and InjectedComponentSet now wrap their children in UnsafeComponent, which prevents
render/component lifecycle problems from propogating.
Existing components have been updated:
1. maxWidth / minWidth are now containerStyles.maxWidth/minWidth
2. displayName is now required to use the CR.
3. containerRequired = false can be provided to exempt a component from being wrapped in an UnsafeComponent.
This is useful because it's slightly faster and keeps DOM flat.
This diff also makes the "Show Component Regions" more awesome. It displays column regions, since they now
use the InjectedComponentSet, and also shows for InjectedComponent as well as InjectedComponentSet.
Change ComponentRegistry syntax, lots more work on safely wrapping items. See description.
Fix for inline flexbox scenarios (message actions)
Allow ~/.inbox/packages to be symlinked to a github repo
Test Plan: Run tests!
Reviewers: evan
Reviewed By: evan
Differential Revision: https://review.inboxapp.com/D1457
2015-05-01 07:10:15 +08:00
|
|
|
@defaultProps:
|
2015-02-07 06:46:30 +08:00
|
|
|
visible: true
|
|
|
|
|
2015-07-16 22:41:04 +08:00
|
|
|
shouldComponentUpdate: (nextProps, nextState) =>
|
|
|
|
not Utils.isEqualReact(nextProps, @props) or
|
|
|
|
not Utils.isEqualReact(nextState, @state)
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
render: =>
|
2015-03-05 10:47:48 +08:00
|
|
|
classSet = {}
|
|
|
|
classSet[@props.field] = true
|
feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.
This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.
When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.
Search bar doesn't need to do full refresh on clear if it never committed
Allow drafts to be switched to a different account when not in reply to an existing thread
Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal
Show many dots for many accounts in long polling status bar
add/remove accounts from prefs
Spec fixes!
Test Plan: Run tests, none broken!
Reviewers: evan, dillon
Reviewed By: evan, dillon
Differential Revision: https://phab.nylas.com/D1928
2015-08-22 06:29:58 +08:00
|
|
|
<div className={@props.className}>
|
2015-02-07 06:46:30 +08:00
|
|
|
<TokenizingTextField
|
2015-02-11 03:10:14 +08:00
|
|
|
ref="textField"
|
2015-02-07 06:46:30 +08:00
|
|
|
tokens={@props.participants[@props.field]}
|
|
|
|
tokenKey={ (p) -> p.email }
|
2015-08-04 04:06:28 +08:00
|
|
|
tokenIsValid={ (p) -> ContactStore.isValidContact(p) }
|
2015-04-25 00:36:19 +08:00
|
|
|
tokenNode={@_tokenNode}
|
|
|
|
onRequestCompletions={ (input) -> ContactStore.searchContacts(input) }
|
|
|
|
completionNode={@_completionNode}
|
|
|
|
onAdd={@_add}
|
|
|
|
onRemove={@_remove}
|
2015-08-04 04:06:28 +08:00
|
|
|
onEdit={@_edit}
|
2015-04-25 00:36:19 +08:00
|
|
|
onEmptied={@props.onEmptied}
|
2015-12-09 09:44:20 +08:00
|
|
|
onFocus={@props.onFocus}
|
2015-04-25 00:36:19 +08:00
|
|
|
onTokenAction={@_showContextMenu}
|
|
|
|
tabIndex={@props.tabIndex}
|
|
|
|
menuClassSet={classSet}
|
|
|
|
menuPrompt={@props.field}
|
|
|
|
/>
|
2015-02-07 06:46:30 +08:00
|
|
|
</div>
|
|
|
|
|
2015-02-11 03:10:14 +08:00
|
|
|
# Public. Can be called by any component that has a ref to this one to
|
|
|
|
# focus the input field.
|
2015-05-01 04:08:29 +08:00
|
|
|
focus: => @refs.textField.focus()
|
2015-02-11 03:10:14 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_completionNode: (p) =>
|
2015-03-26 09:22:52 +08:00
|
|
|
<Menu.NameEmailItem name={p.name} email={p.email} />
|
2015-03-05 06:26:53 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_tokenNode: (p) =>
|
2015-03-05 07:52:40 +08:00
|
|
|
if p.name?.length > 0 and p.name isnt p.email
|
2015-03-05 04:30:54 +08:00
|
|
|
<div className="participant">
|
2015-03-05 06:26:53 +08:00
|
|
|
<span className="participant-primary">{p.name}</span>
|
2015-03-05 04:30:54 +08:00
|
|
|
</div>
|
2015-02-07 06:46:30 +08:00
|
|
|
else
|
2015-03-05 04:30:54 +08:00
|
|
|
<div className="participant">
|
2015-03-05 06:26:53 +08:00
|
|
|
<span className="participant-primary">{p.email}</span>
|
2015-03-05 04:30:54 +08:00
|
|
|
</div>
|
2015-02-07 06:46:30 +08:00
|
|
|
|
2015-08-04 04:06:28 +08:00
|
|
|
_tokensForString: (string, options = {}) =>
|
|
|
|
# If the input is a string, parse out email addresses and build
|
|
|
|
# an array of contact objects. For each email address wrapped in
|
|
|
|
# parentheses, look for a preceding name, if one exists.
|
|
|
|
if string.length is 0
|
2015-09-23 06:32:27 +08:00
|
|
|
return Promise.resolve([])
|
2015-08-04 04:06:28 +08:00
|
|
|
|
2015-09-23 06:32:27 +08:00
|
|
|
ContactStore.parseContactsInString(string, options).then (contacts) =>
|
|
|
|
if contacts.length > 0
|
|
|
|
return Promise.resolve(contacts)
|
|
|
|
else
|
|
|
|
# If no contacts are returned, treat the entire string as a single
|
|
|
|
# (malformed) contact object.
|
|
|
|
return [new Contact(email: string, name: null)]
|
2015-02-07 06:46:30 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_remove: (values) =>
|
2015-03-11 03:06:47 +08:00
|
|
|
field = @props.field
|
|
|
|
updates = {}
|
|
|
|
updates[field] = _.reject @props.participants[field], (p) ->
|
|
|
|
return true if p.email in values
|
|
|
|
return true if p.email in _.map values, (o) -> o.email
|
|
|
|
false
|
|
|
|
@props.change(updates)
|
|
|
|
|
2015-08-04 04:06:28 +08:00
|
|
|
_edit: (token, replacementString) =>
|
|
|
|
field = @props.field
|
|
|
|
tokenIndex = @props.participants[field].indexOf(token)
|
2015-09-23 10:56:06 +08:00
|
|
|
@_tokensForString(replacementString).then (replacements) =>
|
2015-09-23 06:32:27 +08:00
|
|
|
updates = {}
|
|
|
|
updates[field] = [].concat(@props.participants[field])
|
|
|
|
updates[field].splice(tokenIndex, 1, replacements...)
|
|
|
|
@props.change(updates)
|
2015-08-04 04:06:28 +08:00
|
|
|
|
2015-07-13 22:25:30 +08:00
|
|
|
_add: (values, options={}) =>
|
2015-04-01 06:54:16 +08:00
|
|
|
# If the input is a string, parse out email addresses and build
|
|
|
|
# an array of contact objects. For each email address wrapped in
|
|
|
|
# parentheses, look for a preceding name, if one exists.
|
|
|
|
if _.isString(values)
|
2015-09-23 06:32:27 +08:00
|
|
|
tokensPromise = @_tokensForString(values, options)
|
|
|
|
else
|
|
|
|
tokensPromise = Promise.resolve(values)
|
2015-02-07 06:46:30 +08:00
|
|
|
|
2015-09-23 06:32:27 +08:00
|
|
|
tokensPromise.then (tokens) =>
|
|
|
|
# Safety check: remove anything from the incoming tokens that isn't
|
|
|
|
# a Contact. We should never receive anything else in the tokens array.
|
|
|
|
tokens = _.filter tokens, (value) -> value instanceof Contact
|
2015-02-07 06:46:30 +08:00
|
|
|
|
2015-09-23 06:32:27 +08:00
|
|
|
updates = {}
|
2015-03-11 03:06:47 +08:00
|
|
|
for field in Object.keys(@props.participants)
|
2015-09-23 06:32:27 +08:00
|
|
|
updates[field] = [].concat(@props.participants[field])
|
2015-03-11 03:06:47 +08:00
|
|
|
|
2015-09-23 06:32:27 +08:00
|
|
|
for token in tokens
|
|
|
|
# first remove the participant from all the fields. This ensures
|
|
|
|
# that drag and drop isn't "drag and copy." and you can't have the
|
|
|
|
# same recipient in multiple places.
|
|
|
|
for field in Object.keys(@props.participants)
|
|
|
|
updates[field] = _.reject updates[field], (p) ->
|
|
|
|
p.email is token.email
|
2015-02-07 06:46:30 +08:00
|
|
|
|
2015-09-23 06:32:27 +08:00
|
|
|
# add the participant to field
|
|
|
|
updates[@props.field] = _.union(updates[@props.field], [token])
|
|
|
|
|
|
|
|
@props.change(updates)
|
|
|
|
return ""
|
2015-02-07 06:46:30 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_showContextMenu: (participant) =>
|
2015-02-07 06:46:30 +08:00
|
|
|
remote = require('remote')
|
2015-04-22 09:16:08 +08:00
|
|
|
|
|
|
|
# Warning: Menu is already initialized as Menu.cjsx!
|
|
|
|
|
|
|
|
MenuClass = remote.require('menu')
|
2015-02-07 06:46:30 +08:00
|
|
|
MenuItem = remote.require('menu-item')
|
|
|
|
|
2015-04-22 09:16:08 +08:00
|
|
|
menu = new MenuClass()
|
2015-02-07 06:46:30 +08:00
|
|
|
menu.append(new MenuItem(
|
2015-03-05 04:30:54 +08:00
|
|
|
label: "Copy #{participant.email}"
|
2015-05-01 04:08:29 +08:00
|
|
|
click: => require('clipboard').writeText(participant.email)
|
2015-02-07 06:46:30 +08:00
|
|
|
))
|
|
|
|
menu.append(new MenuItem(
|
|
|
|
type: 'separator'
|
|
|
|
))
|
|
|
|
menu.append(new MenuItem(
|
|
|
|
label: 'Remove',
|
2015-03-17 04:55:17 +08:00
|
|
|
click: => @_remove([participant])
|
2015-02-07 06:46:30 +08:00
|
|
|
))
|
|
|
|
menu.popup(remote.getCurrentWindow())
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
|
|
|
|
module.exports = ParticipantsTextField
|