insomnia/app/components/ResponsePane.js

111 lines
3.2 KiB
JavaScript
Raw Normal View History

2016-06-19 00:08:14 +00:00
import React, {PropTypes, Component} from 'react'
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs'
2016-06-15 03:20:05 +00:00
import StatusTag from './StatusTag'
import SizeTag from './SizeTag'
import TimeTag from './TimeTag'
2016-04-30 05:01:57 +00:00
import PreviewModeDropdown from '../components/PreviewModeDropdown'
import ResponseViewer from '../components/ResponseViewer'
import {getPreviewModeName} from '../lib/previewModes'
2016-06-18 21:02:27 +00:00
import {PREVIEW_MODE_SOURCE} from "../lib/previewModes";
2016-06-19 00:08:14 +00:00
class ResponsePane extends Component {
render () {
const {response, previewMode, updatePreviewMode} = this.props;
if (!response) {
return (
<section className="response-pane pane">
<header className="pane__header"></header>
<div className="pane__body pane__body--placeholder">
<h1>Nothing Yet...</h1>
<p>Click the <em>Send</em> button to trigger a request</p>
</div>
</section>
)
}
return (
2016-05-01 19:56:30 +00:00
<section className="response-pane pane">
2016-06-19 00:08:14 +00:00
<header className="pane__header">
{!response ? null : (
<div>
<StatusTag
statusCode={response.statusCode}
statusMessage={response.statusMessage}
/>
<TimeTag milliseconds={response.millis}/>
<SizeTag bytes={response.bytes}/>
</div>
)}
</header>
<Tabs className="pane__body">
<TabList>
<Tab>
<button>{getPreviewModeName(previewMode)}</button>
<PreviewModeDropdown
previewMode={previewMode}
updatePreviewMode={updatePreviewMode}
/>
</Tab>
2016-06-19 00:17:20 +00:00
<Tab>
<button>
Headers {response.headers.length ? (
<span className="txt-sm">({response.headers.length})</span> ) : null}
</button>
</Tab>
2016-06-19 00:08:14 +00:00
</TabList>
<TabPanel>
{response.error ? (
<ResponseViewer
contentType={response.contentType}
previewMode={PREVIEW_MODE_SOURCE}
body={response.error}
wrap={true}
/>
) : (
<ResponseViewer
contentType={response.contentType}
previewMode={previewMode}
body={response.body}
wrap={true} // TODO: Make this a user preference
/>
)}
</TabPanel>
<TabPanel className="scrollable pad">
<table className="wide">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{response.headers.map((h, i) => (
<tr className="selectable" key={i}>
<td>{h.name}</td>
<td>{h.value}</td>
</tr>
))}
</tbody>
</table>
</TabPanel>
</Tabs>
</section>
)
}
2016-06-19 00:08:14 +00:00
}
ResponsePane.propTypes = {
2016-04-30 05:01:57 +00:00
// Functions
updatePreviewMode: PropTypes.func.isRequired,
// Required
previewMode: PropTypes.string.isRequired,
// Other
response: PropTypes.object
2016-04-30 05:01:57 +00:00
};
export default ResponsePane;