2016-07-20 23:16:28 +00:00
|
|
|
import React, {PropTypes, Component} from 'react';
|
2016-11-10 05:56:23 +00:00
|
|
|
import {getRenderedRequest} from '../../common/render';
|
|
|
|
import * as querystring from '../../common/querystring';
|
2016-11-10 02:40:53 +00:00
|
|
|
import * as util from '../../common/misc';
|
2016-07-20 23:09:05 +00:00
|
|
|
|
|
|
|
|
2016-07-20 23:16:28 +00:00
|
|
|
class RenderedQueryString extends Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
string: ''
|
2016-07-20 23:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 19:15:35 +00:00
|
|
|
_update (props, delay = false) {
|
2016-11-22 19:42:10 +00:00
|
|
|
clearTimeout(this._triggerTimeout);
|
|
|
|
this._triggerTimeout = setTimeout(async () => {
|
2016-11-17 18:45:54 +00:00
|
|
|
const {request, environmentId} = props;
|
|
|
|
const {url, parameters} = await getRenderedRequest(request, environmentId);
|
2016-10-02 20:57:00 +00:00
|
|
|
const qs = querystring.buildFromParams(parameters);
|
2016-11-23 19:33:24 +00:00
|
|
|
const fullUrl = querystring.joinUrl(url, qs);
|
2016-10-02 20:57:00 +00:00
|
|
|
this.setState({string: util.prepareUrlForSending(fullUrl)});
|
2016-11-22 19:42:10 +00:00
|
|
|
}, delay ? 200 : 0);
|
2016-07-20 23:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this._update(this.props);
|
|
|
|
}
|
|
|
|
|
2016-08-17 18:05:52 +00:00
|
|
|
componentWillUnmount () {
|
2016-11-22 19:42:10 +00:00
|
|
|
clearTimeout(this._triggerTimeout);
|
2016-08-17 18:05:52 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 23:16:28 +00:00
|
|
|
componentWillReceiveProps (nextProps) {
|
2016-07-21 19:15:35 +00:00
|
|
|
let delay = true;
|
|
|
|
|
|
|
|
// Update right away if we're switching requests
|
|
|
|
if (nextProps.request._id !== this.props.request._id) {
|
|
|
|
delay = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._update(nextProps, delay);
|
2016-07-20 23:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
if (this.state.string) {
|
2016-08-29 17:58:59 +00:00
|
|
|
return <span className="selectable force-wrap">{this.state.string}</span>
|
2016-07-20 23:16:28 +00:00
|
|
|
} else {
|
2016-07-22 20:11:20 +00:00
|
|
|
return <span className="super-faint">{this.props.placeholder || ''}</span>
|
2016-07-20 23:16:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-20 23:09:05 +00:00
|
|
|
|
|
|
|
|
2016-07-20 23:16:28 +00:00
|
|
|
RenderedQueryString.propTypes = {
|
2016-07-22 20:11:20 +00:00
|
|
|
request: PropTypes.object.isRequired,
|
2016-11-17 18:45:54 +00:00
|
|
|
environmentId: PropTypes.string.isRequired,
|
2016-07-22 20:11:20 +00:00
|
|
|
|
|
|
|
// Optional
|
|
|
|
placeholder: PropTypes.string
|
2016-07-20 23:09:05 +00:00
|
|
|
};
|
|
|
|
|
2016-07-20 23:16:28 +00:00
|
|
|
export default RenderedQueryString;
|