2015-02-25 08:19:47 +08:00
|
|
|
React = require 'react/addons'
|
2015-04-25 02:33:10 +08:00
|
|
|
classNames = require 'classnames'
|
2015-05-15 05:12:53 +08:00
|
|
|
_ = require 'underscore-plus'
|
2015-05-15 08:08:30 +08:00
|
|
|
{Utils} = require 'nylas-exports'
|
2015-02-25 08:19:47 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
class ActivityBarTask extends React.Component
|
|
|
|
@displayName: 'ActivityBarTask'
|
2015-02-25 08:19:47 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
constructor: (@props) ->
|
|
|
|
@state = expanded: false
|
2015-02-25 08:19:47 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
render: =>
|
2015-02-25 08:19:47 +08:00
|
|
|
<div className={@_classNames()} onClick={=> @setState expanded: not @state.expanded}>
|
|
|
|
<div className="task-summary">
|
|
|
|
{@_taskSummary()}
|
|
|
|
</div>
|
|
|
|
<div className="task-details">
|
|
|
|
{JSON.stringify(@props.task.toJSON())}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2015-05-15 05:12:53 +08:00
|
|
|
shouldComponentUpdate: (nextProps, nextState) =>
|
|
|
|
return not Utils.isEqualReact(nextProps, @props) or not Utils.isEqualReact(nextState, @state)
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_taskSummary: =>
|
2015-02-25 08:19:47 +08:00
|
|
|
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}"
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_classNames: =>
|
2015-02-25 08:19:47 +08:00
|
|
|
qs = @props.task.queueState ? {}
|
2015-04-25 02:33:10 +08:00
|
|
|
classNames
|
2015-02-25 08:19:47 +08:00
|
|
|
"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
|
2015-05-01 04:08:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = ActivityBarTask
|