insomnia/app/components/RequestPane.js

200 lines
6.6 KiB
JavaScript
Raw Normal View History

import React, {Component, PropTypes} from 'react';
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs'
import KeyValueEditor from './base/KeyValueEditor';
import ContentTypeDropdown from './dropdowns/ContentTypeDropdown';
import RenderedQueryString from './RenderedQueryString';
import BodyEditor from './editors/BodyEditor';
import AuthEditor from './editors/AuthEditor';
import RequestUrlBar from './RequestUrlBar';
import {getContentTypeName} from '../lib/contentTypes';
import {getContentTypeFromHeaders} from '../lib/contentTypes';
import {MOD_SYM} from '../lib/constants';
import {trackEvent} from '../lib/analytics';
2016-06-19 00:08:14 +00:00
class RequestPane extends Component {
render () {
const {
request,
2016-07-27 20:07:50 +00:00
importFile,
showPasswords,
2016-07-19 22:28:29 +00:00
editorFontSize,
editorLineWrapping,
requestCreate,
2016-06-19 00:08:14 +00:00
sendRequest,
updateRequestUrl,
updateRequestMethod,
updateRequestBody,
updateRequestParameters,
2016-06-19 00:08:14 +00:00
updateRequestAuthentication,
updateRequestHeaders,
updateRequestContentType
2016-06-19 00:08:14 +00:00
} = this.props;
if (!request) {
return (
<section className="request-pane pane">
<header className="pane__header"></header>
<div className="pane__body pane__body--placeholder">
2016-07-27 20:07:50 +00:00
<div>
<table>
<tbody>
<tr>
<td>New Request</td>
<td className="text-right">
<code>{MOD_SYM}N</code>
</td>
2016-07-27 20:07:50 +00:00
</tr>
<tr>
<td>Switch Requests</td>
<td className="text-right">
<code>{MOD_SYM}P</code>
</td>
2016-07-27 20:07:50 +00:00
</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>
2016-07-27 20:07:50 +00:00
</tr>
</tbody>
</table>
<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>
</div>
2016-06-19 00:08:14 +00:00
</section>
)
}
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
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>
<button onClick={e => trackEvent('Request Tab Clicked', {name: 'Body'})}>
{getContentTypeName(getContentTypeFromHeaders(request.headers))}
</button>
<ContentTypeDropdown updateRequestContentType={updateRequestContentType}/>
2016-06-19 00:08:14 +00:00
</Tab>
<Tab>
<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>
<button onClick={e => trackEvent('Request Tab Clicked', {name: 'Params'})}>
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 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">
<BodyEditor
key={request._id}
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>
<AuthEditor
key={request._id}
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>
<code className="txt-sm block">
2016-07-22 20:11:20 +00:00
<RenderedQueryString
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
key={request._id}
2016-06-19 00:08:14 +00:00
namePlaceholder="name"
valuePlaceholder="value"
pairs={request.parameters}
onChange={updateRequestParameters}
2016-06-19 00:08:14 +00:00
/>
</TabPanel>
<TabPanel className="scrollable">
<KeyValueEditor
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
}
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,
2016-07-27 20:07:50 +00:00
importFile: PropTypes.func.isRequired,
// Other
showPasswords: PropTypes.bool.isRequired,
2016-07-19 22:28:29 +00:00
editorFontSize: PropTypes.number.isRequired,
editorLineWrapping: PropTypes.bool.isRequired,
// Optional
request: PropTypes.object,
};
export default RequestPane;