2016-07-16 02:06:10 +00:00
|
|
|
import React, {PropTypes, Component} from 'react';
|
2016-04-26 07:29:24 +00:00
|
|
|
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs'
|
|
|
|
|
2016-07-16 02:06:10 +00:00
|
|
|
import StatusTag from './StatusTag';
|
|
|
|
import SizeTag from './SizeTag';
|
|
|
|
import TimeTag from './TimeTag';
|
2016-07-22 20:02:17 +00:00
|
|
|
import PreviewModeDropdown from './PreviewModeDropdown';
|
|
|
|
import ResponseBodyViewer from './ResponseBodyViewer';
|
|
|
|
import ResponseHeadersViewer from './ResponseHeadersViewer';
|
2016-07-16 02:06:10 +00:00
|
|
|
import {getPreviewModeName} from '../lib/previewModes';
|
|
|
|
import {PREVIEW_MODE_SOURCE} from '../lib/previewModes';
|
|
|
|
import {REQUEST_TIME_TO_SHOW_COUNTER} from '../lib/constants';
|
2016-07-25 22:27:29 +00:00
|
|
|
import {MOD_SYM} from '../lib/constants';
|
2016-04-26 07:29:24 +00:00
|
|
|
|
2016-06-19 00:08:14 +00:00
|
|
|
class ResponsePane extends Component {
|
|
|
|
render () {
|
2016-07-07 20:10:55 +00:00
|
|
|
const {
|
|
|
|
response,
|
|
|
|
request,
|
|
|
|
previewMode,
|
|
|
|
updatePreviewMode,
|
2016-07-19 22:28:29 +00:00
|
|
|
loadingRequests,
|
|
|
|
editorLineWrapping,
|
|
|
|
editorFontSize
|
2016-07-07 20:10:55 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2016-07-07 22:06:18 +00:00
|
|
|
const loadStartTime = loadingRequests[request ? request._id : '__NONE__'];
|
2016-07-07 20:10:55 +00:00
|
|
|
let timer = null;
|
|
|
|
|
|
|
|
if (loadStartTime) {
|
|
|
|
// Set a timer to update the UI again soon
|
|
|
|
setTimeout(() => {
|
|
|
|
this.forceUpdate();
|
|
|
|
}, 30);
|
|
|
|
|
2016-07-07 20:39:24 +00:00
|
|
|
// NOTE: We subtract 200ms because the request has some time padding on either end
|
2016-07-07 20:10:55 +00:00
|
|
|
const elapsedTime = Math.round((Date.now() - loadStartTime - 200) / 100) / 10;
|
|
|
|
|
|
|
|
timer = (
|
|
|
|
<div className="response-pane__overlay">
|
|
|
|
{elapsedTime > REQUEST_TIME_TO_SHOW_COUNTER ? (
|
|
|
|
<h2>{elapsedTime} seconds...</h2>
|
|
|
|
) : (
|
|
|
|
<h2>Loading...</h2>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<i className="fa fa-refresh fa-spin"></i>
|
|
|
|
|
|
|
|
{false && elapsedTime > REQUEST_TIME_TO_SHOW_COUNTER ? (
|
|
|
|
// TODO: implement cancel requests
|
|
|
|
<button className="btn btn--compact bg-danger">Cancel Request</button>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2016-07-21 03:58:52 +00:00
|
|
|
if (!request) {
|
|
|
|
return (
|
|
|
|
<section className="response-pane pane">
|
|
|
|
<header className="pane__header"></header>
|
|
|
|
<div className="pane__body pane__body--placeholder text-center pad"></div>
|
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
2016-07-06 22:11:37 +00:00
|
|
|
|
2016-06-19 00:08:14 +00:00
|
|
|
if (!response) {
|
|
|
|
return (
|
|
|
|
<section className="response-pane pane">
|
2016-07-07 20:10:55 +00:00
|
|
|
{timer}
|
|
|
|
|
2016-06-19 00:08:14 +00:00
|
|
|
<header className="pane__header"></header>
|
2016-07-25 22:27:29 +00:00
|
|
|
<div className="pane__body pane__body--placeholder">
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>Send Request</td>
|
|
|
|
<td><code>{MOD_SYM}Enter</code></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Switch Requests</td>
|
|
|
|
<td><code>{MOD_SYM}P</code></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Focus Url Bar</td>
|
|
|
|
<td><code>{MOD_SYM}L</code></td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2016-06-19 00:08:14 +00:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-04-26 07:29:24 +00:00
|
|
|
return (
|
2016-05-01 19:56:30 +00:00
|
|
|
<section className="response-pane pane">
|
2016-07-07 20:10:55 +00:00
|
|
|
{timer}
|
2016-07-06 22:11:37 +00:00
|
|
|
|
2016-06-19 00:27:21 +00:00
|
|
|
<header className="pane__header pad no-wrap">
|
2016-06-19 00:08:14 +00:00
|
|
|
{!response ? null : (
|
|
|
|
<div>
|
|
|
|
<StatusTag
|
|
|
|
statusCode={response.statusCode}
|
|
|
|
statusMessage={response.statusMessage}
|
|
|
|
/>
|
2016-07-22 20:38:28 +00:00
|
|
|
<TimeTag milliseconds={response.elapsedTime}/>
|
|
|
|
<SizeTag bytes={response.bytesRead}/>
|
2016-06-19 00:08:14 +00:00
|
|
|
</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 ? (
|
2016-07-22 20:02:17 +00:00
|
|
|
<ResponseBodyViewer
|
2016-06-19 00:08:14 +00:00
|
|
|
contentType={response.contentType}
|
|
|
|
previewMode={PREVIEW_MODE_SOURCE}
|
2016-07-19 22:28:29 +00:00
|
|
|
editorLineWrapping={editorLineWrapping}
|
|
|
|
editorFontSize={editorFontSize}
|
2016-06-19 00:08:14 +00:00
|
|
|
body={response.error}
|
2016-06-19 07:21:43 +00:00
|
|
|
url={response.url}
|
2016-06-19 00:08:14 +00:00
|
|
|
/>
|
|
|
|
) : (
|
2016-07-22 20:02:17 +00:00
|
|
|
<ResponseBodyViewer
|
2016-06-19 00:08:14 +00:00
|
|
|
contentType={response.contentType}
|
|
|
|
previewMode={previewMode}
|
2016-07-19 22:28:29 +00:00
|
|
|
editorLineWrapping={editorLineWrapping}
|
|
|
|
editorFontSize={editorFontSize}
|
2016-06-19 00:08:14 +00:00
|
|
|
body={response.body}
|
2016-06-19 07:21:43 +00:00
|
|
|
url={response.url}
|
2016-06-19 00:08:14 +00:00
|
|
|
wrap={true} // TODO: Make this a user preference
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</TabPanel>
|
|
|
|
<TabPanel className="scrollable pad">
|
2016-07-22 20:02:17 +00:00
|
|
|
<ResponseHeadersViewer headers={response.headers}/>
|
2016-06-19 00:08:14 +00:00
|
|
|
</TabPanel>
|
|
|
|
</Tabs>
|
2016-04-26 07:29:24 +00:00
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
2016-06-19 00:08:14 +00:00
|
|
|
}
|
2016-04-26 07:29:24 +00:00
|
|
|
|
|
|
|
ResponsePane.propTypes = {
|
2016-04-30 05:01:57 +00:00
|
|
|
// Functions
|
|
|
|
updatePreviewMode: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
// Required
|
|
|
|
previewMode: PropTypes.string.isRequired,
|
2016-07-06 22:11:37 +00:00
|
|
|
loadingRequests: PropTypes.object.isRequired,
|
2016-07-19 22:28:29 +00:00
|
|
|
editorFontSize: PropTypes.number.isRequired,
|
|
|
|
editorLineWrapping: PropTypes.bool.isRequired,
|
2016-04-30 05:01:57 +00:00
|
|
|
|
|
|
|
// Other
|
2016-07-07 20:10:55 +00:00
|
|
|
response: PropTypes.object,
|
2016-07-19 22:28:29 +00:00
|
|
|
request: PropTypes.object
|
2016-04-26 07:29:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponsePane;
|