2016-09-17 05:46:44 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-10-21 17:20:36 +00:00
|
|
|
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
|
2016-09-17 05:46:44 +00:00
|
|
|
import KeyValueEditor from './base/KeyValueEditor';
|
|
|
|
import RequestHeadersEditor from './editors/RequestHeadersEditor';
|
|
|
|
import ContentTypeDropdown from './dropdowns/ContentTypeDropdown';
|
|
|
|
import RenderedQueryString from './RenderedQueryString';
|
2016-11-22 19:42:10 +00:00
|
|
|
import BodyEditor from './editors/body/BodyEditor';
|
2016-09-17 05:46:44 +00:00
|
|
|
import AuthEditor from './editors/AuthEditor';
|
2016-11-07 20:24:38 +00:00
|
|
|
import RequestUrlBar from './RequestUrlBar.js';
|
2016-11-10 02:40:53 +00:00
|
|
|
import {MOD_SYM, getContentTypeName, getContentTypeFromHeaders} from '../../common/constants';
|
|
|
|
import {debounce} from '../../common/misc';
|
2016-11-22 22:26:52 +00:00
|
|
|
import {getBodyDescription} from '../../models/request';
|
2016-09-17 05:46:44 +00:00
|
|
|
|
|
|
|
class RequestPane extends Component {
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
request,
|
2016-11-17 18:45:54 +00:00
|
|
|
environmentId,
|
|
|
|
handleImportFile,
|
2016-09-17 05:46:44 +00:00
|
|
|
showPasswords,
|
|
|
|
editorFontSize,
|
|
|
|
editorLineWrapping,
|
2016-11-16 17:18:39 +00:00
|
|
|
handleCreateRequest,
|
|
|
|
handleSend,
|
2016-09-17 05:46:44 +00:00
|
|
|
useBulkHeaderEditor,
|
|
|
|
updateRequestUrl,
|
|
|
|
updateRequestMethod,
|
|
|
|
updateRequestBody,
|
|
|
|
updateRequestParameters,
|
|
|
|
updateRequestAuthentication,
|
|
|
|
updateRequestHeaders,
|
2016-11-22 19:42:10 +00:00
|
|
|
updateRequestMimeType,
|
2016-09-17 05:46:44 +00:00
|
|
|
updateSettingsUseBulkHeaderEditor
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!request) {
|
|
|
|
return (
|
2016-09-20 21:17:01 +00:00
|
|
|
<section className="request-pane pane">
|
|
|
|
<header className="pane__header"></header>
|
|
|
|
<div className="pane__body pane__body--placeholder">
|
|
|
|
<div>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>New Request</td>
|
|
|
|
<td className="text-right">
|
|
|
|
<code>{MOD_SYM}N</code>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Switch Requests</td>
|
|
|
|
<td className="text-right">
|
|
|
|
<code>{MOD_SYM}P</code>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<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>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2016-09-17 05:46:44 +00:00
|
|
|
|
2016-09-20 21:17:01 +00:00
|
|
|
<div className="text-center pane__body--placeholder__cta">
|
2016-11-16 17:18:39 +00:00
|
|
|
<button onClick={e => handleImportFile()}
|
2016-09-20 21:17:01 +00:00
|
|
|
className="btn inline-block btn--super-compact btn--outlined">
|
|
|
|
Import from File
|
|
|
|
</button>
|
2016-11-16 17:18:39 +00:00
|
|
|
<button onClick={e => handleCreateRequest()}
|
2016-09-20 21:17:01 +00:00
|
|
|
className="btn inline-block btn--super-compact btn--outlined">
|
|
|
|
New Request
|
|
|
|
</button>
|
2016-09-17 05:46:44 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2016-09-20 21:17:01 +00:00
|
|
|
</div>
|
|
|
|
</section>
|
2016-09-17 05:46:44 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-11-23 03:07:35 +00:00
|
|
|
const numParameters = request.parameters.filter(p => !p.disabled).length;
|
|
|
|
const numHeaders = request.headers.filter(h => !h.disabled).length;
|
|
|
|
const hasAuth = !request.authentication.disabled;
|
|
|
|
|
2016-09-17 05:46:44 +00:00
|
|
|
return (
|
2016-09-20 21:17:01 +00:00
|
|
|
<section className="pane request-pane">
|
2016-11-07 20:24:38 +00:00
|
|
|
<header className="pane__header">
|
|
|
|
<RequestUrlBar
|
2016-11-20 06:56:21 +00:00
|
|
|
key={request._id}
|
2016-11-07 20:24:38 +00:00
|
|
|
method={request.method}
|
|
|
|
onMethodChange={updateRequestMethod}
|
|
|
|
onUrlChange={debounce(updateRequestUrl)}
|
2016-11-16 17:18:39 +00:00
|
|
|
handleSend={handleSend}
|
2016-11-07 20:24:38 +00:00
|
|
|
url={request.url}
|
|
|
|
/>
|
|
|
|
</header>
|
2016-09-20 21:17:01 +00:00
|
|
|
<Tabs className="pane__body">
|
|
|
|
<TabList>
|
|
|
|
<Tab>
|
2016-10-27 03:41:30 +00:00
|
|
|
<button>
|
2016-11-22 20:00:04 +00:00
|
|
|
{getContentTypeName(request.body.mimeType)}
|
2016-09-20 21:17:01 +00:00
|
|
|
</button>
|
2016-11-22 20:00:04 +00:00
|
|
|
<ContentTypeDropdown updateRequestMimeType={updateRequestMimeType}/>
|
2016-09-20 21:17:01 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab>
|
2016-10-27 03:41:30 +00:00
|
|
|
<button>
|
2016-11-23 03:07:35 +00:00
|
|
|
Auth {hasAuth ? <i className="fa fa-lock txt-sm"></i> : null}
|
2016-09-20 21:17:01 +00:00
|
|
|
</button>
|
|
|
|
</Tab>
|
|
|
|
<Tab>
|
2016-10-27 03:41:30 +00:00
|
|
|
<button>
|
2016-11-23 03:07:35 +00:00
|
|
|
Query {numParameters ? <span className="txt-sm">({numParameters})</span> : null}
|
2016-09-20 21:17:01 +00:00
|
|
|
</button>
|
|
|
|
</Tab>
|
|
|
|
<Tab>
|
2016-10-27 03:41:30 +00:00
|
|
|
<button>
|
2016-11-23 03:07:35 +00:00
|
|
|
Headers {numHeaders ? <span className="txt-sm">({numHeaders})</span> : null}
|
2016-09-20 21:17:01 +00:00
|
|
|
</button>
|
|
|
|
</Tab>
|
|
|
|
</TabList>
|
|
|
|
<TabPanel className="editor-wrapper">
|
|
|
|
<BodyEditor
|
2016-11-20 06:56:21 +00:00
|
|
|
key={request._id}
|
2016-09-20 21:17:01 +00:00
|
|
|
request={request}
|
|
|
|
onChange={updateRequestBody}
|
|
|
|
fontSize={editorFontSize}
|
|
|
|
lineWrapping={editorLineWrapping}
|
|
|
|
/>
|
|
|
|
</TabPanel>
|
2016-09-21 00:03:26 +00:00
|
|
|
<TabPanel className="scrollable-container">
|
|
|
|
<div className="scrollable">
|
|
|
|
<AuthEditor
|
2016-11-20 06:56:21 +00:00
|
|
|
key={request._id}
|
2016-09-21 00:03:26 +00:00
|
|
|
showPasswords={showPasswords}
|
|
|
|
request={request}
|
|
|
|
onChange={updateRequestAuthentication}
|
|
|
|
/>
|
|
|
|
</div>
|
2016-09-20 21:17:01 +00:00
|
|
|
</TabPanel>
|
2016-09-21 00:03:26 +00:00
|
|
|
<TabPanel className="scrollable-container">
|
|
|
|
<div className="scrollable">
|
|
|
|
<div className="pad no-pad-bottom">
|
|
|
|
<label className="label--small">Url Preview</label>
|
|
|
|
<code className="txt-sm block">
|
|
|
|
<RenderedQueryString
|
|
|
|
request={request}
|
2016-11-17 18:45:54 +00:00
|
|
|
environmentId={environmentId}
|
2016-11-23 03:07:35 +00:00
|
|
|
placeholder="http://awesome-api.com?name=Gregory"
|
2016-09-21 00:03:26 +00:00
|
|
|
/>
|
|
|
|
</code>
|
|
|
|
</div>
|
|
|
|
<KeyValueEditor
|
2016-11-20 06:56:21 +00:00
|
|
|
key={request._id}
|
2016-09-21 00:03:26 +00:00
|
|
|
namePlaceholder="name"
|
|
|
|
valuePlaceholder="value"
|
|
|
|
pairs={request.parameters}
|
|
|
|
onChange={updateRequestParameters}
|
|
|
|
/>
|
2016-09-20 21:17:01 +00:00
|
|
|
</div>
|
|
|
|
</TabPanel>
|
2016-09-22 20:02:29 +00:00
|
|
|
<TabPanel className="header-editor">
|
|
|
|
<RequestHeadersEditor
|
2016-11-20 06:56:21 +00:00
|
|
|
key={request._id}
|
2016-09-22 20:02:29 +00:00
|
|
|
headers={request.headers}
|
|
|
|
onChange={updateRequestHeaders}
|
|
|
|
bulk={useBulkHeaderEditor}
|
|
|
|
/>
|
|
|
|
|
2016-09-22 20:04:23 +00:00
|
|
|
<div className="pad-right text-right">
|
2016-11-07 20:24:38 +00:00
|
|
|
<button
|
|
|
|
className="margin-top-sm btn btn--outlined btn--super-compact"
|
|
|
|
onClick={() => updateSettingsUseBulkHeaderEditor(!useBulkHeaderEditor)}>
|
2016-09-22 20:02:29 +00:00
|
|
|
{useBulkHeaderEditor ? 'Regular Edit' : 'Bulk Edit'}
|
|
|
|
</button>
|
2016-09-20 21:17:01 +00:00
|
|
|
</div>
|
|
|
|
</TabPanel>
|
|
|
|
</Tabs>
|
|
|
|
</section>
|
2016-09-17 05:46:44 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RequestPane.propTypes = {
|
|
|
|
// Functions
|
2016-11-16 17:18:39 +00:00
|
|
|
handleSend: PropTypes.func.isRequired,
|
|
|
|
handleCreateRequest: PropTypes.func.isRequired,
|
2016-09-17 05:46:44 +00:00
|
|
|
updateRequestUrl: PropTypes.func.isRequired,
|
|
|
|
updateRequestMethod: PropTypes.func.isRequired,
|
|
|
|
updateRequestBody: PropTypes.func.isRequired,
|
|
|
|
updateRequestParameters: PropTypes.func.isRequired,
|
|
|
|
updateRequestAuthentication: PropTypes.func.isRequired,
|
|
|
|
updateRequestHeaders: PropTypes.func.isRequired,
|
2016-11-22 19:42:10 +00:00
|
|
|
updateRequestMimeType: PropTypes.func.isRequired,
|
2016-09-17 05:46:44 +00:00
|
|
|
updateSettingsShowPasswords: PropTypes.func.isRequired,
|
|
|
|
updateSettingsUseBulkHeaderEditor: PropTypes.func.isRequired,
|
2016-11-16 17:18:39 +00:00
|
|
|
handleImportFile: PropTypes.func.isRequired,
|
2016-09-17 05:46:44 +00:00
|
|
|
|
|
|
|
// Other
|
|
|
|
useBulkHeaderEditor: PropTypes.bool.isRequired,
|
|
|
|
showPasswords: PropTypes.bool.isRequired,
|
|
|
|
editorFontSize: PropTypes.number.isRequired,
|
|
|
|
editorLineWrapping: PropTypes.bool.isRequired,
|
2016-11-17 18:45:54 +00:00
|
|
|
environmentId: PropTypes.string.isRequired,
|
2016-09-17 05:46:44 +00:00
|
|
|
|
|
|
|
// Optional
|
|
|
|
request: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RequestPane;
|