_ = require 'underscore'
React = require 'react'
{DatabaseStore,
AccountStore,
TaskQueue,
Actions,
Contact,
Message} = require 'nylas-exports'
{InjectedComponentSet} = require 'nylas-component-kit'
DeveloperBarStore = require './developer-bar-store'
DeveloperBarTask = require './developer-bar-task'
DeveloperBarCurlItem = require './developer-bar-curl-item'
DeveloperBarLongPollItem = require './developer-bar-long-poll-item'
class DeveloperBar extends React.Component
@displayName: "DeveloperBar"
@containerRequired: false
constructor: (@props) ->
@state = _.extend @_getStateFromStores(),
section: 'curl'
filter: ''
componentDidMount: =>
@taskQueueUnsubscribe = TaskQueue.listen @_onChange
@activityStoreUnsubscribe = DeveloperBarStore.listen @_onChange
componentWillUnmount: =>
@taskQueueUnsubscribe() if @taskQueueUnsubscribe
@activityStoreUnsubscribe() if @activityStoreUnsubscribe
render: =>
@_onExpandSection('queue')}>
Client Tasks ({@state.queue?.length})
@_onExpandSection('providerSyncbackRequests')}>
Provider Syncback Requests
@_onExpandSection('long-polling')}>
{@_renderDeltaStates()}
Delta Streaming
@_onExpandSection('curl')}>
Requests: {@state.curlHistory.length}
@_onExpandSection('local-sync')}>
Local Sync Engine
{@_sectionContent()}
_renderDeltaStates: =>
_.map @state.longPollStates, (deltaStatus, accountId) =>
{ _.map deltaStatus, (val, deltaName) =>
}
_sectionContent: =>
expandedDiv =
matchingFilter = (item) =>
return true if @state.filter is ''
return JSON.stringify(item).indexOf(@state.filter) >= 0
if @state.section == 'curl'
itemDivs = @state.curlHistory.filter(matchingFilter).map (item) ->
expandedDiv = {itemDivs}
else if @state.section == 'long-polling'
itemDivs = @state.longPollHistory.filter(matchingFilter).map (item) ->
expandedDiv = {itemDivs}
else if @state.section == 'local-sync'
expandedDiv =
else if @state.section == 'providerSyncbackRequests'
reqs = @state.providerSyncbackRequests.map (req) =>
{req.type}: {req.status} - {JSON.stringify(req.props)}
expandedDiv = {reqs}
else if @state.section == 'queue'
queue = @state.queue.filter(matchingFilter)
queueDivs = for i in [@state.queue.length - 1..0] by -1
task = @state.queue[i]
# We need to pass the task separately because we want to update
# when just that variable changes. Otherwise, since the `task`
# pointer doesn't change, the `DeveloperBarTask` doesn't know to
# update.
status = @state.queue[i].queueState.status
queueCompleted = @state.completed.filter(matchingFilter)
queueCompletedDivs = for i in [@state.completed.length - 1..0] by -1
task = @state.completed[i]
expandedDiv =
Remove Queued Tasks
{queueDivs}
{queueCompletedDivs}
expandedDiv
_onChange: =>
@setState(@_getStateFromStores())
_onClear: =>
Actions.clearDeveloperConsole()
_onFilter: (ev) =>
@setState(filter: ev.target.value)
_onDequeueAll: =>
Actions.dequeueAllTasks()
_onExpandSection: (section) =>
@setState(@_getStateFromStores())
@setState(section: section)
_getStateFromStores: =>
queue: TaskQueue._queue
completed: TaskQueue._completed
curlHistory: DeveloperBarStore.curlHistory()
longPollHistory: DeveloperBarStore.longPollHistory()
longPollStates: DeveloperBarStore.longPollStates()
providerSyncbackRequests: DeveloperBarStore.providerSyncbackRequests()
module.exports = DeveloperBar