_ = require 'underscore-plus'
React = require 'react/addons'
{ComponentRegistry,
DatabaseStore,
NamespaceStore,
TaskQueue,
Actions,
Contact,
Message} = require 'inbox-exports'
ActivityBarStore = require './activity-bar-store'
ActivityBarCurlItem = React.createClass
render: ->
{@props.item.statusCode}
Run
Copy
{@props.item.command}
_onCopyCommand: ->
clipboard = require('clipboard')
clipboard.writeText(@props.item.command)
_onRunCommand: ->
curlFile = "#{atom.getConfigDirPath()}/curl.command"
fs = require 'fs-plus'
if fs.existsSync(curlFile)
fs.unlinkSync(curlFile)
fs.writeFileSync(curlFile, @props.item.command)
fs.chmodSync(curlFile, '777')
shell = require 'shell'
shell.openItem(curlFile)
ActivityBarTask = React.createClass
render: ->
@setState expanded: not @state?.expanded}>
{@_taskSummary()}
{JSON.stringify(@props.task.toJSON())}
_taskSummary: ->
qs = @props.task.queueState
errType = ""
errCode = ""
errMessage = ""
if qs.localError?
localError = qs.localError
errType = localError.constructor.name
errMessage = localError.message ? JSON.stringify(localError)
else if qs.remoteError?
remoteError = qs.remoteError
errType = remoteError.constructor.name
errCode = remoteError.statusCode ? ""
errMessage = remoteError.body?.message ? remoteError?.message ? JSON.stringify(remoteError)
return "#{@props.task.constructor.name} #{errType} #{errCode} #{errMessage}"
_classNames: ->
qs = @props.task.queueState ? {}
React.addons.classSet
"task": true
"task-queued": @props.type is "queued"
"task-completed": @props.type is "completed"
"task-expanded": @state?.expanded
"task-local-error": qs.localError
"task-remote-error": qs.remoteError
"task-is-processing": qs.isProcessing
"task-success": qs.performedLocal and qs.performedRemote
module.exports =
ActivityBar = React.createClass
getInitialState: ->
_.extend @_getStateFromStores(),
open: false
componentDidMount: ->
@taskQueueUnsubscribe = TaskQueue.listen @_onChange
@activityStoreUnsubscribe = ActivityBarStore.listen @_onChange
@registryUnlisten = ComponentRegistry.listen @_onChange
componentWillUnmount: ->
@taskQueueUnsubscribe() if @taskQueueUnsubscribe
@activityStoreUnsubscribe() if @activityStoreUnsubscribe
@registryUnlisten() if @registryUnlisten
render: ->
if @state?.ResizableComponent?
ResizableComponent = @state.ResizableComponent
else
ResizableComponent = React.createClass(render: -> {@props.children}
)
expandedDiv =
if @state.expandedSection == 'curl'
curlDivs = @state.curlHistory.map (item) ->
expandedDiv = {curlDivs}
if @state.expandedSection == 'queue'
queueDivs = for i in [@state.queue.length - 1..0] by -1
task = @state.queue[i]
queueCompletedDivs = for i in [@state.completed.length - 1..0] by -1
task = @state.completed[i]
expandedDiv =
Clear Queue
{queueDivs}
{queueCompletedDivs}
{@_caret()}
Queue Length: {@state.queue?.length}
Long Polling: {@state.longPollState}
Requests: {@state.curlHistory.length}
{expandedDiv}
_expandedPanelClass: ->
React.addons.classSet
"message-area": true
"panel-open": @state.open
_caret: ->
if @state.open
else
_onChange: ->
@setState(@_getStateFromStores())
_onClearQueue: ->
Actions.clearQueue()
_onHide: -> @setState open: false
_onShow: -> @setState open: true
_onExpandCurlSection: ->
@setState open: true
Actions.developerPanelSelectSection('curl')
_onExpandQueueSection: ->
@setState open: true
Actions.developerPanelSelectSection('queue')
_onFeedback: ->
user = NamespaceStore.current().name
debugData = JSON.stringify({
queries: @state.curlHistory,
queue: @state.queue,
completed: @state.completed
}, null, '\t')
# Remove API tokens from URLs included in the debug data
# This regex detects ://user:pass@ and removes it.
debugData = debugData.replace(/:\/\/(\w)*:(\w)?@/g, '://')
draft = new Message
from: [NamespaceStore.current().me()]
to: [
new Contact
name: "Nilas Team"
email: "feedback@nilas.com"
]
date: (new Date)
draft: true
subject: "Feedback"
namespaceId: NamespaceStore.current().id
body: """
Hi, Edgehill team!
I have some feedback for you.
What happened
Impact
Feedback
Environment
I'm using Edgehill #{atom.getVersion()} and my platform is #{process.platform}-#{process.arch}.
--
#{user}
-- Extra Debugging Data --
#{debugData}
"""
DatabaseStore.persistModel(draft).then ->
DatabaseStore.localIdForModel(draft).then (localId) ->
Actions.composePopoutDraft(localId)
_getStateFromStores: ->
ResizableComponent: ComponentRegistry.findViewByName 'ResizableComponent'
expandedSection: ActivityBarStore.expandedSection()
curlHistory: ActivityBarStore.curlHistory()
queue: TaskQueue._queue
completed: TaskQueue._completed
longPollState: ActivityBarStore.longPollState()