2016-03-20 23:20:00 +00:00
|
|
|
import React, {Component, PropTypes} from 'react'
|
2016-04-09 18:47:51 +00:00
|
|
|
import DebouncingInput from './base/DebouncingInput';
|
2016-03-22 05:01:58 +00:00
|
|
|
import Dropdown from './base/Dropdown';
|
2016-03-21 05:47:49 +00:00
|
|
|
import {METHODS} from '../constants/global';
|
2016-03-20 23:20:00 +00:00
|
|
|
|
|
|
|
class UrlInput extends Component {
|
2016-04-09 18:47:51 +00:00
|
|
|
shouldComponentUpdate (nextProps) {
|
2016-04-17 05:28:51 +00:00
|
|
|
return this.props.request._id !== nextProps.request._id;
|
2016-03-22 18:20:05 +00:00
|
|
|
}
|
2016-04-09 18:47:51 +00:00
|
|
|
|
2016-03-20 23:20:00 +00:00
|
|
|
render () {
|
2016-04-09 21:08:55 +00:00
|
|
|
const {sendRequest, onUrlChange, onMethodChange, request} = this.props;
|
2016-03-20 23:20:00 +00:00
|
|
|
return (
|
2016-04-06 07:19:36 +00:00
|
|
|
<div className="grid wide form-control form-control--left form-control--right bg-super-light">
|
2016-03-21 05:47:49 +00:00
|
|
|
<Dropdown>
|
2016-04-06 07:19:36 +00:00
|
|
|
<button className="btn txt-lg">
|
2016-03-22 18:20:05 +00:00
|
|
|
{request.method} <i className="fa fa-caret-down"></i>
|
2016-03-21 05:47:49 +00:00
|
|
|
</button>
|
2016-04-04 07:15:30 +00:00
|
|
|
<ul>
|
2016-03-21 05:47:49 +00:00
|
|
|
{METHODS.map((method) => (
|
|
|
|
<li key={method}>
|
2016-03-22 03:22:45 +00:00
|
|
|
<button onClick={onMethodChange.bind(null, method)}>
|
2016-03-21 05:47:49 +00:00
|
|
|
{method}
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</Dropdown>
|
2016-04-09 21:08:55 +00:00
|
|
|
<form className="tall grid__cell" onSubmit={e => {e.preventDefault(); sendRequest(request)}}>
|
|
|
|
<DebouncingInput
|
|
|
|
type="text"
|
2016-04-17 05:22:10 +00:00
|
|
|
className="txt-md"
|
2016-04-09 21:08:55 +00:00
|
|
|
placeholder="http://echo.insomnia.rest/status/200"
|
|
|
|
value={request.url}
|
|
|
|
debounceMillis={1000}
|
|
|
|
onChange={onUrlChange}/>
|
|
|
|
</form>
|
2016-04-17 05:22:10 +00:00
|
|
|
<button className="btn txt-lg" onClick={sendRequest.bind(null, request)}>
|
|
|
|
Send
|
2016-03-20 23:20:00 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UrlInput.propTypes = {
|
2016-04-09 21:08:55 +00:00
|
|
|
sendRequest: PropTypes.func.isRequired,
|
2016-03-20 23:20:00 +00:00
|
|
|
onUrlChange: PropTypes.func.isRequired,
|
2016-03-20 23:27:46 +00:00
|
|
|
onMethodChange: PropTypes.func.isRequired,
|
2016-03-22 18:20:05 +00:00
|
|
|
request: PropTypes.shape({
|
|
|
|
url: PropTypes.string.isRequired,
|
|
|
|
method: PropTypes.string.isRequired
|
|
|
|
}).isRequired
|
2016-03-20 23:20:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default UrlInput;
|