Mailspring/internal_packages/worker-ui/lib/developer-bar-curl-item.cjsx
Evan Morikawa 900cd69438 fix(developer): visual improvements to developer bar
Summary: Make ETIMEDOUT red

Test Plan: manual

Reviewers: bengotow, dillon

Reviewed By: dillon

Differential Revision: https://phab.nylas.com/D2126
2015-10-07 17:28:45 -07:00

47 lines
1.4 KiB
CoffeeScript

classNames = require 'classnames'
React = require 'react/addons'
class DeveloperBarCurlItem extends React.Component
@displayName: 'DeveloperBarCurlItem'
render: =>
classes = classNames
"item": true
"error-code": @_isError()
<div className={classes}>
<div className="code">{@props.item.statusCode}{@_errorMessage()}</div>
<span className="timestamp">{@props.item.startMoment.format("HH:mm:ss")}&nbsp;&nbsp;</span>
<a onClick={@_onRunCommand}>Run</a>
<a onClick={@_onCopyCommand}>Copy</a>
{@props.item.command}
</div>
shouldComponentUpdate: (nextProps) =>
return @props.item isnt nextProps.item
_onCopyCommand: =>
clipboard = require('clipboard')
clipboard.writeText(@props.item.command)
_isError: ->
return false if @props.item.statusCode is "pending"
return not (parseInt(@props.item.statusCode) <= 399)
_errorMessage: ->
if (@props.item.errorMessage ? "").length > 0
return " | #{@props.item.errorMessage}"
else
return ""
_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)
module.exports = DeveloperBarCurlItem