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-16 02:06:10 +00:00
|
|
|
import KeyValueEditor from '../components/base/KeyValueEditor';
|
2016-04-26 07:29:24 +00:00
|
|
|
|
2016-07-16 02:06:10 +00:00
|
|
|
import ContentTypeDropdown from '../components/ContentTypeDropdown';
|
2016-07-20 23:16:28 +00:00
|
|
|
import RenderedQueryString from '../components/RenderedQueryString';
|
2016-07-16 02:06:10 +00:00
|
|
|
import RequestBodyEditor from '../components/RequestBodyEditor';
|
|
|
|
import RequestAuthEditor from '../components/RequestAuthEditor';
|
|
|
|
import RequestUrlBar from '../components/RequestUrlBar';
|
2016-04-26 07:29:24 +00:00
|
|
|
|
2016-07-16 02:06:10 +00:00
|
|
|
import {getContentTypeName} from '../lib/contentTypes';
|
2016-07-20 23:16:28 +00:00
|
|
|
import {renderRequest} from '../lib/render';
|
2016-07-22 20:02:17 +00:00
|
|
|
import {getContentTypeFromHeaders} from '../lib/contentTypes';
|
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-19 19:13:51 +00:00
|
|
|
showPasswords,
|
2016-07-19 22:28:29 +00:00
|
|
|
editorFontSize,
|
|
|
|
editorLineWrapping,
|
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-07-19 19:13:51 +00:00
|
|
|
updateRequestContentType,
|
|
|
|
updateSettingsShowPasswords
|
2016-06-19 00:08:14 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!request) {
|
|
|
|
return (
|
|
|
|
<section className="request-pane pane">
|
|
|
|
<header className="pane__header"></header>
|
2016-06-19 00:40:14 +00:00
|
|
|
<div className="pane__body text-center pad"></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
|
|
|
|
sendRequest={() => sendRequest(request)}
|
|
|
|
onUrlChange={updateRequestUrl}
|
|
|
|
onMethodChange={updateRequestMethod}
|
2016-07-14 22:48:56 +00:00
|
|
|
requestId={request._id}
|
2016-06-19 00:08:14 +00:00
|
|
|
url={request.url}
|
|
|
|
method={request.method}
|
|
|
|
/>
|
|
|
|
</header>
|
|
|
|
<Tabs className="pane__body">
|
|
|
|
<TabList>
|
|
|
|
<Tab>
|
2016-07-22 20:02:17 +00:00
|
|
|
<button>{getContentTypeName(getContentTypeFromHeaders(request.headers))}</button>
|
|
|
|
<ContentTypeDropdown updateRequestContentType={updateRequestContentType}/>
|
2016-06-19 00:08:14 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab>
|
|
|
|
<button>
|
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>
|
|
|
|
<button>
|
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>
|
|
|
|
<button>
|
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">
|
|
|
|
<RequestBodyEditor
|
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>
|
|
|
|
<RequestAuthEditor
|
2016-07-19 19:13:51 +00:00
|
|
|
showPasswords={showPasswords}
|
2016-06-19 00:51:15 +00:00
|
|
|
request={request}
|
|
|
|
onChange={updateRequestAuthentication}
|
|
|
|
/>
|
2016-07-19 19:13:51 +00:00
|
|
|
<div className="pad pull-right txt-sm">
|
|
|
|
<button className="btn btn--super-compact btn--outlined faint"
|
|
|
|
onClick={e => updateSettingsShowPasswords(!showPasswords)}>
|
|
|
|
{showPasswords ? 'Hide Password' : 'Show Password'}
|
|
|
|
</button>
|
|
|
|
</div>
|
2016-06-19 00:51:15 +00:00
|
|
|
</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>
|
|
|
|
<code className="txt-sm block selectable">
|
2016-07-20 23:16:28 +00:00
|
|
|
<RenderedQueryString request={request}/>
|
|
|
|
</code>
|
|
|
|
</div>
|
2016-06-19 00:08:14 +00:00
|
|
|
<KeyValueEditor
|
|
|
|
namePlaceholder="name"
|
|
|
|
valuePlaceholder="value"
|
|
|
|
uniquenessKey={request._id}
|
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
|
|
|
|
namePlaceholder="My-Header"
|
|
|
|
valuePlaceholder="Value"
|
|
|
|
uniquenessKey={request._id}
|
|
|
|
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,
|
|
|
|
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-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;
|