import React, { Component, PropTypes } from 'react' import _ from 'lodash' import { RequestUtils, isValidHttpVersion, parseUrl, parseHttpVersion } from '../../flow/utils.js' import { Key, formatTimeStamp } from '../../utils.js' import ContentView from '../ContentView' import ValueEditor from '../ValueEditor' import Headers from './Headers' class RequestLine extends Component { render() { const { flow, updateFlow } = this.props return (
updateFlow({ request: { method } })} inline />   updateFlow({ request: Object.assign({ path: '' }, parseUrl(url)) })} isValid={url => !!parseUrl(url).host} inline />   updateFlow({ request: { http_version: parseHttpVersion(ver) } })} isValid={isValidHttpVersion} inline />
) } } class ResponseLine extends Component { render() { const { flow, updateFlow } = this.props return (
updateFlow({ response: { http_version: parseHttpVersion(nextVer) } })} isValid={isValidHttpVersion} inline />   updateFlow({ response: { code: parseInt(code) } })} isValid={code => /^\d+$/.test(code)} inline />   updateFlow({ response: { msg } })} inline />
) } } export class Request extends Component { render() { const { flow, updateFlow } = this.props return (
updateFlow({ request: { headers } })} />
) } edit(k) { switch (k) { case 'm': this.refs.requestLine.refs.method.focus() break case 'u': this.refs.requestLine.refs.url.focus() break case 'v': this.refs.requestLine.refs.httpVersion.focus() break case 'h': this.refs.headers.edit() break default: throw new Error(`Unimplemented: ${k}`) } } } export class Response extends Component { render() { const { flow, updateFlow } = this.props return (
updateFlow({ response: { headers } })} />
) } edit(k) { switch (k) { case 'c': this.refs.responseLine.refs.status_code.focus() break case 'm': this.refs.responseLine.refs.msg.focus() break case 'v': this.refs.responseLine.refs.httpVersion.focus() break case 'h': this.refs.headers.edit() break default: throw new Error(`'Unimplemented: ${k}`) } } } ErrorView.propTypes = { flow: PropTypes.object.isRequired, } export function ErrorView({ flow }) { return (
{flow.error.msg}
{formatTimeStamp(flow.error.timestamp)}
) }