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';
|
|
|
|
import BodyEditor from './editors/BodyEditor';
|
|
|
|
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-09-17 05:46:44 +00:00
|
|
|
|
|
|
|
class RequestPane extends Component {
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
request,
|
|
|
|
importFile,
|
|
|
|
showPasswords,
|
|
|
|
editorFontSize,
|
|
|
|
editorLineWrapping,
|
|
|
|
requestCreate,
|
|
|
|
sendRequest,
|
|
|
|
useBulkHeaderEditor,
|
|
|
|
updateRequestUrl,
|
|
|
|
updateRequestMethod,
|
|
|
|
updateRequestBody,
|
|
|
|
updateRequestParameters,
|
|
|
|
updateRequestAuthentication,
|
|
|
|
updateRequestHeaders,
|
|
|
|
updateRequestContentType,
|
|
|
|
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">
|
|
|
|
<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">
|
|
|
|
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
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
method={request.method}
|
|
|
|
onMethodChange={updateRequestMethod}
|
|
|
|
onUrlChange={debounce(updateRequestUrl)}
|
|
|
|
sendRequest={sendRequest.bind(null, request)}
|
|
|
|
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-09-20 21:17:01 +00:00
|
|
|
{getContentTypeName(getContentTypeFromHeaders(request.headers))}
|
|
|
|
</button>
|
|
|
|
<ContentTypeDropdown
|
|
|
|
updateRequestContentType={updateRequestContentType}/>
|
|
|
|
</Tab>
|
|
|
|
<Tab>
|
2016-10-27 03:41:30 +00:00
|
|
|
<button>
|
2016-09-20 21:17:01 +00:00
|
|
|
Auth {request.authentication.username ?
|
|
|
|
<i className="fa fa-lock txt-sm"></i> : ''}
|
|
|
|
</button>
|
|
|
|
</Tab>
|
|
|
|
<Tab>
|
2016-10-27 03:41:30 +00:00
|
|
|
<button>
|
2016-09-20 21:17:01 +00:00
|
|
|
Query {request.parameters.length ?
|
|
|
|
<span
|
|
|
|
className="txt-sm">({request.parameters.length})</span> : null}
|
|
|
|
</button>
|
|
|
|
</Tab>
|
|
|
|
<Tab>
|
2016-10-27 03:41:30 +00:00
|
|
|
<button>
|
2016-09-20 21:17:01 +00:00
|
|
|
Headers {request.headers.length ? (
|
|
|
|
<span
|
|
|
|
className="txt-sm">({request.headers.length})</span> ) : null}
|
|
|
|
</button>
|
|
|
|
</Tab>
|
|
|
|
</TabList>
|
|
|
|
<TabPanel className="editor-wrapper">
|
|
|
|
<BodyEditor
|
|
|
|
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
|
|
|
|
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}
|
|
|
|
placeholder="http://myproduct.com?name=Gregory"
|
|
|
|
/>
|
|
|
|
</code>
|
|
|
|
</div>
|
|
|
|
<KeyValueEditor
|
|
|
|
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
|
|
|
|
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
|
|
|
|
sendRequest: PropTypes.func.isRequired,
|
|
|
|
requestCreate: PropTypes.func.isRequired,
|
|
|
|
updateRequestUrl: PropTypes.func.isRequired,
|
|
|
|
updateRequestMethod: PropTypes.func.isRequired,
|
|
|
|
updateRequestBody: PropTypes.func.isRequired,
|
|
|
|
updateRequestParameters: PropTypes.func.isRequired,
|
|
|
|
updateRequestAuthentication: PropTypes.func.isRequired,
|
|
|
|
updateRequestHeaders: PropTypes.func.isRequired,
|
|
|
|
updateRequestContentType: PropTypes.func.isRequired,
|
|
|
|
updateSettingsShowPasswords: PropTypes.func.isRequired,
|
|
|
|
updateSettingsUseBulkHeaderEditor: PropTypes.func.isRequired,
|
|
|
|
importFile: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
// Other
|
|
|
|
useBulkHeaderEditor: PropTypes.bool.isRequired,
|
|
|
|
showPasswords: PropTypes.bool.isRequired,
|
|
|
|
editorFontSize: PropTypes.number.isRequired,
|
|
|
|
editorLineWrapping: PropTypes.bool.isRequired,
|
|
|
|
|
|
|
|
// Optional
|
|
|
|
request: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RequestPane;
|