insomnia/app/components/RequestPane.js

143 lines
4.5 KiB
JavaScript
Raw Normal View History

import React, {Component, PropTypes} from 'react';
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs'
import KeyValueEditor from '../components/base/KeyValueEditor';
import ContentTypeDropdown from '../components/ContentTypeDropdown';
import RequestBodyEditor from '../components/RequestBodyEditor';
import RequestAuthEditor from '../components/RequestAuthEditor';
import RequestUrlBar from '../components/RequestUrlBar';
import {getContentTypeName} from '../lib/contentTypes';
2016-06-19 00:08:14 +00:00
class RequestPane extends Component {
render () {
const {
request,
showPasswords,
2016-06-19 00:08:14 +00:00
sendRequest,
updateRequestUrl,
updateRequestMethod,
updateRequestBody,
updateRequestParameters,
2016-06-19 00:08:14 +00:00
updateRequestAuthentication,
updateRequestHeaders,
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>
)
}
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>
<button>{getContentTypeName(request.contentType)}</button>
<ContentTypeDropdown
activeContentType={request.contentType}
updateRequestContentType={updateRequestContentType}
/>
</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>
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
onChange={updateRequestBody}
requestId={request._id}
contentType={request.contentType}
body={request.body}
/>
</TabPanel>
2016-06-19 00:51:15 +00:00
<TabPanel>
<RequestAuthEditor
showPasswords={showPasswords}
2016-06-19 00:51:15 +00:00
request={request}
onChange={updateRequestAuthentication}
/>
<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">
<KeyValueEditor
className="pad"
namePlaceholder="name"
valuePlaceholder="value"
uniquenessKey={request._id}
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
}
RequestPane.propTypes = {
// Functions
sendRequest: 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,
// Other
showPasswords: PropTypes.bool.isRequired,
// Optional
request: PropTypes.object,
};
export default RequestPane;