Mailspring/internal_packages/sidebar-inbox-internal/lib/sidebar-internal.cjsx
Ben Gotow 607ca3bf10 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-21 15:29:58 -07:00

130 lines
3.6 KiB
CoffeeScript

_ = require 'underscore'
React = require "react"
moment = require 'moment-timezone'
InternalAdminStore = require "./internal-admin-store"
AccountStates =
"developer_program": "Developer Program"
"trial-expired": "Trial Expired"
"paid": "Paid"
"cancelled": "Cancelled"
AccountKeys =
"deleted_at": "Deleted At"
"healthy": "Healthy"
"initial_sync": "Initial Sync"
"is_enabled": "Enabled"
"account_id": "Account Id"
"provider": "Provider"
"remote_count": "Remote Count"
"state": "State"
"status": "Status"
"sync_disabled_reason": "Sync Disabled Reason"
"sync_end_time": "Sync End Time"
"sync_error": "Sync Error"
"sync_host": "Sync Host"
"sync_restart_time": "Sync Restart Time"
"sync_start_time": "Sync Start Time"
"sync_type": "Sync Type"
class SidebarInternal extends React.Component
@displayName: "SidebarInternal"
@containerStyles:
order: 10
maxWidth: 300
minWidth: 200
constructor: (@props) ->
@state = @_getStateFromStores()
componentDidMount: =>
@unsubscribe = InternalAdminStore.listen @_onChange
componentWillUnmount: =>
@unsubscribe()
render: =>
return <div></div> unless @state.enabled
<div className="internal-sidebar">
<div className="internal-sidebar-sections">
<div className="sidebar-section">
<h2 className="sidebar-h2">Mailsync Account</h2>
{@_renderAccount()}
</div>
<div className="sidebar-section">
<h2 className="sidebar-h2">Authenticated Applications</h2>
{@_renderApplications()}
</div>
</div>
</div>
_renderAccount: =>
if @state.error
return <div>{@_errorString()}</div>
else if @state.data.loading
return <div>Loading...</div>
else
acct = @state.data.account
if acct
<div className="sidebar-item">
<h3 className="sidebar-h3"><a href={@_accountUrl(acct)}>{acct.email} ({acct.id})</a></h3>
<div className="sidebar-extra-info">{@_accountDetails(acct)}</div>
</div>
else
<div>No Matching Account</div>
_renderApplications: =>
if @state.error
return <div>{@_errorString()}</div>
else if @state.data.loading
return <div>Loading...</div>
else if @state.data.apps
@state.data.apps.map (app) =>
<div className="sidebar-item">
<h3 className="sidebar-h3"><a href={@_appUrl(app)}>{app.name}</a></h3>
<div className="sidebar-extra-info">{@_appDetails(app)}</div>
</div>
else
<div>No Matching Applications</div>
_errorString: =>
if @state.error.toString().indexOf('ENOTFOUND') >= 0
"Unable to reach admin.nylas.com"
else
@state.error.toString()
_accountUrl: (account) =>
"https://admin.nylas.com/accounts/#{account.id}"
_accountDetails: (account) =>
cjsx = []
for key, value of account
displayName = AccountKeys[key]
continue unless displayName
continue unless value
value = "True" if value is true
value = "False" if value is false
value = moment.unix(value).format("DD / MM / YYYY h:mm a z") if key.indexOf("_time") > 0
cjsx.push <div style={textAlign:'right'} key={key}><span style={float:'left'}>{displayName}:</span>{value}</div>
cjsx
_appUrl: (app) =>
"https://admin.nylas.com/apps/#{app.id}"
_appDetails: (app) =>
"No Extra Details"
_onChange: =>
@setState(@_getStateFromStores())
_getStateFromStores: =>
data: InternalAdminStore.dataForFocusedContact()
enabled: InternalAdminStore.enabled()
error: InternalAdminStore.error()
module.exports = SidebarInternal