insomnia/app/components/ResponsePane.js

103 lines
2.8 KiB
JavaScript
Raw Normal View History

2016-04-29 04:57:03 +00:00
import React, {PropTypes} 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-04-30 05:01:57 +00:00
const ResponsePane = ({response, previewMode, updatePreviewMode}) => {
2016-04-29 04:57:03 +00:00
if (!response) {
return (
2016-05-01 19:56:30 +00:00
<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>
)
}
2016-04-29 04:57:03 +00:00
return (
2016-05-01 19:56:30 +00:00
<section className="response-pane pane">
2016-06-18 21:02:27 +00:00
<header className="pane__header">
2016-05-01 19:56:30 +00:00
{!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
2016-04-30 05:01:57 +00:00
previewMode={previewMode}
2016-05-01 19:56:30 +00:00
updatePreviewMode={updatePreviewMode}
2016-04-30 05:01:57 +00:00
/>
2016-05-01 19:56:30 +00:00
</Tab>
<Tab><button>Headers</button></Tab>
</TabList>
<TabPanel>
2016-06-18 21:02:27 +00:00
{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
/>
)}
2016-05-01 19:56:30 +00:00
</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>
2016-04-29 04:57:03 +00:00
</section>
)
};
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;