2016-09-28 01:48:01 -04:00
|
|
|
import React from 'react';
|
|
|
|
import CopyToClipboard from '../../components/CopyToClipboard';
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
qe: React.PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
qe: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class CopyQueryTabUrl extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
const uri = window.location.toString();
|
|
|
|
const search = window.location.search;
|
|
|
|
const cleanUri = search ? uri.substring(0, uri.indexOf('?')) : uri;
|
|
|
|
const query = search.substring(1);
|
|
|
|
this.state = {
|
|
|
|
uri,
|
|
|
|
cleanUri,
|
|
|
|
query,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
getQueryLink() {
|
|
|
|
const params = [];
|
|
|
|
const qe = this.props.qe;
|
|
|
|
if (qe.dbId) params.push('dbid=' + qe.dbId);
|
2016-10-11 18:50:36 -04:00
|
|
|
if (qe.title) params.push('title=' + encodeURIComponent(qe.title));
|
|
|
|
if (qe.schema) params.push('schema=' + encodeURIComponent(qe.schema));
|
2016-09-28 01:48:01 -04:00
|
|
|
if (qe.autorun) params.push('autorun=' + qe.autorun);
|
2016-10-11 18:50:36 -04:00
|
|
|
if (qe.sql) params.push('sql=' + encodeURIComponent(qe.sql));
|
2016-09-28 01:48:01 -04:00
|
|
|
|
|
|
|
const queryString = params.join('&');
|
|
|
|
const queryLink = this.state.cleanUri + '?' + queryString;
|
|
|
|
|
|
|
|
return queryLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<CopyToClipboard
|
|
|
|
inMenu
|
|
|
|
text={this.getQueryLink()}
|
2016-10-11 18:50:36 -04:00
|
|
|
copyNode={<span>share query</span>}
|
|
|
|
tooltipText="copy URL to clipboard"
|
2016-09-28 01:48:01 -04:00
|
|
|
shouldShowText={false}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyQueryTabUrl.propTypes = propTypes;
|
|
|
|
CopyQueryTabUrl.defaultProps = defaultProps;
|