2016-11-26 08:29:16 +00:00
|
|
|
import React, {PropTypes, PureComponent} from 'react';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2016-11-10 05:56:23 +00:00
|
|
|
import * as querystring from '../../common/querystring';
|
2017-03-06 17:51:58 +00:00
|
|
|
import * as misc from '../../common/misc';
|
2016-07-20 23:09:05 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2016-11-26 08:29:16 +00:00
|
|
|
class RenderedQueryString extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
2017-03-06 17:51:58 +00:00
|
|
|
this._interval = null;
|
2017-03-03 01:44:07 +00:00
|
|
|
this.state = {
|
|
|
|
string: ''
|
|
|
|
};
|
|
|
|
}
|
2016-07-20 23:09:05 +00:00
|
|
|
|
2017-03-06 17:51:58 +00:00
|
|
|
async _debouncedUpdate (props) {
|
|
|
|
clearTimeout(this._interval);
|
|
|
|
this._interval = setTimeout(() => {
|
|
|
|
this._update(props);
|
|
|
|
}, 300);
|
|
|
|
}
|
|
|
|
|
|
|
|
async _update (props) {
|
|
|
|
const {request} = props;
|
|
|
|
const enabledParameters = request.parameters.filter(p => !p.disabled);
|
|
|
|
const {url, parameters} = await props.handleRender({
|
|
|
|
url: request.url,
|
|
|
|
parameters: enabledParameters
|
|
|
|
});
|
|
|
|
const qs = querystring.buildFromParams(parameters);
|
|
|
|
const fullUrl = querystring.joinUrl(url, qs);
|
|
|
|
this.setState({string: misc.prepareUrlForSending(fullUrl)});
|
2016-07-20 23:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this._update(this.props);
|
|
|
|
}
|
|
|
|
|
2016-08-17 18:05:52 +00:00
|
|
|
componentWillUnmount () {
|
2017-03-06 17:51:58 +00:00
|
|
|
clearTimeout(this._interval);
|
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
|
|
|
if (nextProps.request._id !== this.props.request._id) {
|
2017-03-06 17:51:58 +00:00
|
|
|
this._update(nextProps);
|
|
|
|
} else {
|
|
|
|
this._debouncedUpdate(nextProps);
|
2016-07-21 19:15:35 +00:00
|
|
|
}
|
2016-07-20 23:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
if (this.state.string) {
|
2017-03-03 20:09:08 +00:00
|
|
|
return <span className="selectable force-wrap">{this.state.string}</span>;
|
2016-07-20 23:16:28 +00:00
|
|
|
} else {
|
2017-03-03 20:09:08 +00:00
|
|
|
return <span className="super-duper-faint italic">...</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,
|
2017-03-03 20:09:08 +00:00
|
|
|
handleRender: PropTypes.func.isRequired
|
2016-07-20 23:09:05 +00:00
|
|
|
};
|
|
|
|
|
2016-07-20 23:16:28 +00:00
|
|
|
export default RenderedQueryString;
|