Mailspring/internal_packages/sidebar-inbox-internal/lib/sidebar-internal.cjsx
Ben Gotow 9ffe0d74dd 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-04-30 16:10:15 -07:00

129 lines
3.6 KiB
CoffeeScript

_ = require 'underscore-plus'
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"
"namespace_id": "Namespace 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:
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.nilas.com"
else
@state.error.toString()
_accountUrl: (account) =>
"https://admin.inboxapp.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'}><span style={float:'left'}>{displayName}:</span>{value}</div>
cjsx
_appUrl: (app) =>
"https://admin.inboxapp.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