import React, { Component } from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import { RequestUtils, isValidHttpVersion, parseUrl } from '../../flow/utils.js' import { formatTimeStamp } from '../../utils.js' import ContentView from '../ContentView' import ContentViewOptions from '../ContentView/ContentViewOptions' import ValidateEditor from '../ValueEditor/ValidateEditor' import ValueEditor from '../ValueEditor/ValueEditor' import Headers from './Headers' import { startEdit, updateEdit } from '../../ducks/ui/flow' import * as FlowActions from '../../ducks/flows' import ToggleEdit from './ToggleEdit' function RequestLine({ flow, readonly, updateFlow }) { return (
updateFlow({ request: { method } })} />   updateFlow({ request: {path: '', ...parseUrl(url)}})} isValid={url => !!parseUrl(url).host} />   updateFlow({ request: { http_version } })} isValid={isValidHttpVersion} />
) } function ResponseLine({ flow, readonly, updateFlow }) { return (
updateFlow({ response: { http_version: nextVer } })} isValid={isValidHttpVersion} />   updateFlow({ response: { code: parseInt(code) } })} isValid={code => /^\d+$/.test(code)} />   updateFlow({ response: { msg } })} />
) } const Message = connect( state => ({ flow: state.ui.flow.modifiedFlow || state.flows.byId[state.flows.selected[0]], isEdit: !!state.ui.flow.modifiedFlow, }), { updateFlow: updateEdit, uploadContent: FlowActions.uploadContent } ) export class Request extends Component { render() { const { flow, isEdit, updateFlow, uploadContent } = this.props let noContent = !isEdit && (flow.request.contentLength == 0 || flow.request.contentLength == null) return (
updateFlow({ request: { headers } })} />
updateFlow({ request: {content}})} message={flow.request}/>
{!noContent && }
) } edit(k) { throw "unimplemented" /* 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}`) } */ } } Request = Message(Request) export class Response extends Component { render() { const { flow, isEdit, updateFlow, uploadContent } = this.props let noContent = !isEdit && (flow.response.contentLength == 0 || flow.response.contentLength == null) return (
updateFlow({ response: { headers } })} />
updateFlow({ response: {content}})} message={flow.response} />
{!noContent && }
) } edit(k) { throw "unimplemented" /* 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}`) } */ } } Response = Message(Response) ErrorView.propTypes = { flow: PropTypes.object.isRequired, } export function ErrorView({ flow }) { return (
{flow.error.msg}
{formatTimeStamp(flow.error.timestamp)}
) }