refactor(packages): move internal sidebar to own repo

Fixes T3425 Remove Nylas internal admin sidebar from default edgehill
This commit is contained in:
Evan Morikawa 2015-08-31 17:13:12 -07:00
parent e8bffef723
commit 91bc61e03a
5 changed files with 0 additions and 294 deletions

View file

@ -1,87 +0,0 @@
_ = require 'underscore'
Reflux = require 'reflux'
request = require 'request'
{FocusedContactsStore,
AccountStore,
PriorityUICoordinator} = require 'nylas-exports'
module.exports =
# The InternalAdminStore manages the data that backs the admin sidebar and emits
# a "trigger" event that the view listens to.
#
# If the Admin sidebar allowed you to take actions, like modifying someone's
# Nylas account, the InternalAdminStore would also listen for those user actions
# and perform business logic.
#
InternalAdminStore = Reflux.createStore
init: ->
@_accountCache = null
@_enabled = false
@_error = null
# Stores often listen to other stores to vend correct data to their views.
# Since we serve information about a contact we listen for changes to the
# focused contact. Since we only want to be enabled for @nylas.com emails,
# we listen for changes to available Accounts.
@listenTo FocusedContactsStore, @_onFocusedContacts
@listenTo AccountStore, @_onAccountChanged
@_onAccountChanged()
dataForFocusedContact: ->
return {loading: true} if @_accountCache is null
contact = FocusedContactsStore.focusedContact()
return {} unless contact
account = _.find @_accountCache, (account) -> account.email is contact.email
apps = undefined
apps = account.applications if account
# Coffeescript shorthand for {account: account, apps: apps}
{account, apps}
enabled: ->
@_enabled
error: ->
@_error
_onFocusedContacts: ->
# When the user focuses on a contact, we don't need to do any work because we
# cache everything. Just trigger so that our view updates and calls
# `dataForFocusedContact`.
@trigger(@)
_onAccountChanged: ->
clearInterval(@_fetchInterval) if @_fetchInterval
@_fetchInterval = null
# We only want to enable this package for users with nylas.com email addresses.
n = AccountStore.current()
if n and n.emailAddress.indexOf('@nylas.com') > 0
@_fetchInterval = setInterval(( => @_fetchAPIData()), 5 * 60 * 1000)
@_fetchAPIData()
@_enabled = true
else
@_accountCache = null
@_enabled = false
@trigger(@)
_fetchAPIData: ->
# Make a HTTP request to the Admin service using the `request` library. Using
# the priority UI coordinator ensures that the expensive JSON.parse operation
# doesn't happen while an animation is running.
request 'https://admin.nylas.com/api/status/accounts', (err, resp, data) =>
PriorityUICoordinator.settle.then =>
if err
@_error = err
else
@_error = null
try
@_accountCache = JSON.parse(data)
catch err
@_error = err
@_accountCache = null
@trigger(@)

View file

@ -1,16 +0,0 @@
_ = require 'underscore'
React = require "react"
SidebarInternal = require "./sidebar-internal"
{ComponentRegistry, WorkspaceStore} = require "nylas-exports"
module.exports =
item: null
activate: (@state={}) ->
ComponentRegistry.register SidebarInternal,
location: WorkspaceStore.Location.MessageListSidebar
deactivate: ->
ComponentRegistry.unregister(SidebarInternal)
serialize: -> @state

View file

@ -1,129 +0,0 @@
_ = 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

View file

@ -1,13 +0,0 @@
{
"name": "sidebar-inbox-internal",
"version": "0.1.0",
"main": "./lib/main",
"description": "View user data on the sidebar from inbox internal systems",
"license": "Proprietary",
"private": true,
"engines": {
"atom": "*"
},
"dependencies": {
}
}

View file

@ -1,49 +0,0 @@
@import "ui-variables";
.internal-sidebar {
padding: @spacing-standard;
padding-bottom: 0;
order: 4;
flex-shrink: 0;
a{text-decoration: none}
.sidebar-section {
margin-top: @spacing-double;
font-size: @font-size-smaller;
&:first-child {margin-top: 0}
}
.internal-prompt {
color: fade(@text-color, 30%);
ul {
list-style: none;
padding-left: 0;
}
}
.internal-no-connect-placeholder {
text-align: center;
margin: @spacing-double 0;
}
h3.sidebar-h3 {
font-size: @font-size-smaller;
font-weight: @font-weight-normal;
margin: 1em 0 0.4em 0;
}
.sidebar-extra-info {
font-size: 11px;
font-weight: @font-weight-medium;
color: @text-color-subtle;
}
h2.sidebar-h2 {
font-size: 11px;
font-weight: @font-weight-semi-bold;
text-transform: uppercase;
color: @text-color-very-subtle;
border-bottom: 1px solid @border-color-divider;
margin: 2em 0 1em 0;
}
}