2016-07-16 02:06:10 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-04-26 07:29:24 +00:00
|
|
|
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs'
|
|
|
|
|
2016-07-25 22:27:29 +00:00
|
|
|
import KeyValueEditor from './base/KeyValueEditor';
|
2016-04-26 07:29:24 +00:00
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
import ContentTypeDropdown from './dropdowns/ContentTypeDropdown';
|
2016-07-25 22:27:29 +00:00
|
|
|
import RenderedQueryString from './RenderedQueryString';
|
2016-08-15 17:04:36 +00:00
|
|
|
import BodyEditor from './editors/BodyEditor';
|
|
|
|
import AuthEditor from './editors/AuthEditor';
|
|
|
|
import RequestUrlBar from './RequestUrlBar';
|
2016-04-26 07:29:24 +00:00
|
|
|
|
2016-07-16 02:06:10 +00:00
|
|
|
import {getContentTypeName} from '../lib/contentTypes';
|
2016-07-22 20:02:17 +00:00
|
|
|
import {getContentTypeFromHeaders} from '../lib/contentTypes';
|
2016-07-25 22:27:29 +00:00
|
|
|
import {MOD_SYM} from '../lib/constants';
|
2016-07-28 20:10:26 +00:00
|
|
|
import {trackEvent} from '../lib/analytics';
|
2016-04-28 06:22:50 +00:00
|
|
|
|
2016-06-19 00:08:14 +00:00
|
|
|
class RequestPane extends Component {
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
request,
|
2016-07-27 20:07:50 +00:00
|
|
|
importFile,
|
2016-07-19 19:13:51 +00:00
|
|
|
showPasswords,
|
2016-07-19 22:28:29 +00:00
|
|
|
editorFontSize,
|
|
|
|
editorLineWrapping,
|
2016-08-15 17:04:36 +00:00
|
|
|
requestCreate,
|
2016-06-19 00:08:14 +00:00
|
|
|
sendRequest,
|
|
|
|
updateRequestUrl,
|
|
|
|
updateRequestMethod,
|
|
|
|
updateRequestBody,
|
2016-07-19 04:01:31 +00:00
|
|
|
updateRequestParameters,
|
2016-06-19 00:08:14 +00:00
|
|
|
updateRequestAuthentication,
|
|
|
|
updateRequestHeaders,
|
2016-08-15 17:04:36 +00:00
|
|
|
updateRequestContentType
|
2016-06-19 00:08:14 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!request) {
|
|
|
|
return (
|
|
|
|
<section className="request-pane pane">
|
|
|
|
<header className="pane__header"></header>
|
2016-07-25 22:27:29 +00:00
|
|
|
<div className="pane__body pane__body--placeholder">
|
2016-07-27 20:07:50 +00:00
|
|
|
<div>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>New Request</td>
|
2016-08-15 17:04:36 +00:00
|
|
|
<td className="text-right">
|
|
|
|
<code>{MOD_SYM}N</code>
|
|
|
|
</td>
|
2016-07-27 20:07:50 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2016-08-15 17:04:36 +00:00
|
|
|
<td>Switch Requests</td>
|
|
|
|
<td className="text-right">
|
|
|
|
<code>{MOD_SYM}P</code>
|
|
|
|
</td>
|
2016-07-27 20:07:50 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2016-08-15 17:04:36 +00:00
|
|
|
<td>Manage Cookies</td>
|
|
|
|
<td className="text-right">
|
|
|
|
<code>{MOD_SYM}K</code>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Edit Environments</td>
|
|
|
|
<td className="text-right">
|
|
|
|
<code>{MOD_SYM}E</code>
|
|
|
|
</td>
|
2016-07-27 20:07:50 +00:00
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
<div className="text-center pane__body--placeholder__cta">
|
|
|
|
<button onClick={e => importFile()}
|
|
|
|
className="btn inline-block btn--super-compact btn--outlined">
|
|
|
|
Import from File
|
|
|
|
</button>
|
|
|
|
<button onClick={e => requestCreate()}
|
|
|
|
className="btn inline-block btn--super-compact btn--outlined">
|
|
|
|
Create Request
|
|
|
|
</button>
|
|
|
|
</div>
|
2016-07-27 20:07:50 +00:00
|
|
|
</div>
|
2016-07-25 22:27:29 +00:00
|
|
|
</div>
|
2016-06-19 00:08:14 +00:00
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
2016-04-26 07:29:24 +00:00
|
|
|
|
|
|
|
return (
|
2016-05-01 19:56:30 +00:00
|
|
|
<section className="request-pane pane">
|
2016-06-19 00:08:14 +00:00
|
|
|
<header className="pane__header">
|
|
|
|
<RequestUrlBar
|
2016-07-28 20:10:26 +00:00
|
|
|
key={request._id}
|
2016-06-19 00:08:14 +00:00
|
|
|
sendRequest={() => sendRequest(request)}
|
|
|
|
onUrlChange={updateRequestUrl}
|
|
|
|
onMethodChange={updateRequestMethod}
|
|
|
|
url={request.url}
|
|
|
|
method={request.method}
|
|
|
|
/>
|
|
|
|
</header>
|
|
|
|
<Tabs className="pane__body">
|
|
|
|
<TabList>
|
|
|
|
<Tab>
|
2016-07-28 20:10:26 +00:00
|
|
|
<button onClick={e => trackEvent('Request Tab Clicked', {name: 'Body'})}>
|
|
|
|
{getContentTypeName(getContentTypeFromHeaders(request.headers))}
|
|
|
|
</button>
|
2016-07-22 20:02:17 +00:00
|
|
|
<ContentTypeDropdown updateRequestContentType={updateRequestContentType}/>
|
2016-06-19 00:08:14 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab>
|
2016-07-28 20:10:26 +00:00
|
|
|
<button onClick={e => trackEvent('Request Tab Clicked', {name: 'Auth'})}>
|
2016-06-19 00:51:15 +00:00
|
|
|
Auth {request.authentication.username ? <i className="fa fa-lock txt-sm"></i> : ''}
|
2016-06-19 00:08:14 +00:00
|
|
|
</button>
|
|
|
|
</Tab>
|
|
|
|
<Tab>
|
2016-07-28 20:10:26 +00:00
|
|
|
<button onClick={e => trackEvent('Request Tab Clicked', {name: 'Params'})}>
|
2016-07-19 19:13:51 +00:00
|
|
|
Params {request.parameters.length ?
|
|
|
|
<span className="txt-sm">({request.parameters.length})</span> : null}
|
2016-06-19 00:08:14 +00:00
|
|
|
</button>
|
|
|
|
</Tab>
|
|
|
|
<Tab>
|
2016-07-28 20:10:26 +00:00
|
|
|
<button onClick={e => trackEvent('Request Tab Clicked', {name: 'Headers'})}>
|
2016-06-19 00:17:20 +00:00
|
|
|
Headers {request.headers.length ? (
|
|
|
|
<span className="txt-sm">({request.headers.length})</span> ) : null}
|
2016-06-19 00:08:14 +00:00
|
|
|
</button>
|
|
|
|
</Tab>
|
|
|
|
</TabList>
|
|
|
|
<TabPanel className="editor-wrapper">
|
2016-08-15 17:04:36 +00:00
|
|
|
<BodyEditor
|
2016-07-28 20:10:26 +00:00
|
|
|
key={request._id}
|
2016-07-22 20:02:17 +00:00
|
|
|
request={request}
|
2016-06-19 00:08:14 +00:00
|
|
|
onChange={updateRequestBody}
|
2016-07-19 22:28:29 +00:00
|
|
|
fontSize={editorFontSize}
|
|
|
|
lineWrapping={editorLineWrapping}
|
2016-06-19 00:08:14 +00:00
|
|
|
/>
|
|
|
|
</TabPanel>
|
2016-06-19 00:51:15 +00:00
|
|
|
<TabPanel>
|
2016-08-15 17:04:36 +00:00
|
|
|
<AuthEditor
|
2016-07-28 20:10:26 +00:00
|
|
|
key={request._id}
|
2016-07-19 19:13:51 +00:00
|
|
|
showPasswords={showPasswords}
|
2016-06-19 00:51:15 +00:00
|
|
|
request={request}
|
|
|
|
onChange={updateRequestAuthentication}
|
|
|
|
/>
|
|
|
|
</TabPanel>
|
2016-06-19 00:08:14 +00:00
|
|
|
<TabPanel className="scrollable">
|
2016-07-20 23:16:28 +00:00
|
|
|
<div className="pad no-pad-bottom">
|
2016-07-21 19:15:35 +00:00
|
|
|
<label className="label--small">Url Preview</label>
|
2016-08-15 17:04:36 +00:00
|
|
|
<code className="txt-sm block">
|
2016-07-22 20:11:20 +00:00
|
|
|
<RenderedQueryString
|
2016-07-28 20:10:26 +00:00
|
|
|
key={request._id}
|
2016-07-22 20:11:20 +00:00
|
|
|
request={request}
|
|
|
|
placeholder="http://myproduct.com?name=Gregory"
|
|
|
|
/>
|
2016-07-20 23:16:28 +00:00
|
|
|
</code>
|
|
|
|
</div>
|
2016-06-19 00:08:14 +00:00
|
|
|
<KeyValueEditor
|
2016-07-28 20:10:26 +00:00
|
|
|
key={request._id}
|
2016-06-19 00:08:14 +00:00
|
|
|
namePlaceholder="name"
|
|
|
|
valuePlaceholder="value"
|
2016-07-19 04:01:31 +00:00
|
|
|
pairs={request.parameters}
|
|
|
|
onChange={updateRequestParameters}
|
2016-06-19 00:08:14 +00:00
|
|
|
/>
|
|
|
|
</TabPanel>
|
|
|
|
<TabPanel className="scrollable">
|
|
|
|
<KeyValueEditor
|
2016-07-28 20:10:26 +00:00
|
|
|
key={request._id}
|
2016-06-19 00:08:14 +00:00
|
|
|
namePlaceholder="My-Header"
|
|
|
|
valuePlaceholder="Value"
|
|
|
|
pairs={request.headers}
|
|
|
|
onChange={updateRequestHeaders}
|
|
|
|
/>
|
|
|
|
</TabPanel>
|
|
|
|
</Tabs>
|
2016-04-29 04:57:03 +00:00
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
2016-06-19 00:08:14 +00:00
|
|
|
}
|
2016-04-26 07:29:24 +00:00
|
|
|
|
|
|
|
RequestPane.propTypes = {
|
|
|
|
// Functions
|
|
|
|
sendRequest: PropTypes.func.isRequired,
|
2016-08-15 17:04:36 +00:00
|
|
|
requestCreate: PropTypes.func.isRequired,
|
2016-04-26 07:29:24 +00:00
|
|
|
updateRequestUrl: PropTypes.func.isRequired,
|
|
|
|
updateRequestMethod: PropTypes.func.isRequired,
|
|
|
|
updateRequestBody: PropTypes.func.isRequired,
|
2016-07-19 04:01:31 +00:00
|
|
|
updateRequestParameters: PropTypes.func.isRequired,
|
2016-04-26 07:29:24 +00:00
|
|
|
updateRequestAuthentication: PropTypes.func.isRequired,
|
|
|
|
updateRequestHeaders: PropTypes.func.isRequired,
|
2016-04-28 06:22:50 +00:00
|
|
|
updateRequestContentType: PropTypes.func.isRequired,
|
2016-07-19 19:13:51 +00:00
|
|
|
updateSettingsShowPasswords: PropTypes.func.isRequired,
|
2016-07-27 20:07:50 +00:00
|
|
|
importFile: PropTypes.func.isRequired,
|
2016-04-26 07:29:24 +00:00
|
|
|
|
|
|
|
// Other
|
2016-07-19 19:13:51 +00:00
|
|
|
showPasswords: PropTypes.bool.isRequired,
|
2016-07-19 22:28:29 +00:00
|
|
|
editorFontSize: PropTypes.number.isRequired,
|
|
|
|
editorLineWrapping: PropTypes.bool.isRequired,
|
2016-07-19 19:13:51 +00:00
|
|
|
|
|
|
|
// Optional
|
|
|
|
request: PropTypes.object,
|
2016-04-26 07:29:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default RequestPane;
|