-
Notifications
You must be signed in to change notification settings - Fork 16.8k
Added url shortner for sharing query link #1314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0373f1d
ad662cc
b0bac1e
eaf51d8
cbc21d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import React from 'react'; | ||
| import CopyToClipboard from '../../components/CopyToClipboard'; | ||
| import { getShortUrl } from '../../../utils/common'; | ||
|
|
||
| const propTypes = { | ||
| qe: React.PropTypes.object, | ||
|
|
@@ -12,18 +13,12 @@ const defaultProps = { | |
| 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, | ||
| shortUrl: '', | ||
| }; | ||
| } | ||
|
|
||
| getQueryLink() { | ||
| componentWillMount() { | ||
| const params = []; | ||
| const qe = this.props.qe; | ||
| if (qe.dbId) params.push('dbid=' + qe.dbId); | ||
|
|
@@ -33,16 +28,21 @@ export default class CopyQueryTabUrl extends React.Component { | |
| if (qe.sql) params.push('sql=' + encodeURIComponent(qe.sql)); | ||
|
|
||
| const queryString = params.join('&'); | ||
| const queryLink = this.state.cleanUri + '?' + queryString; | ||
| const queryLink = window.location.pathname + '?' + queryString; | ||
| getShortUrl(queryLink, this.onShortUrlSuccess.bind(this)); | ||
| } | ||
|
|
||
| return queryLink; | ||
| onShortUrlSuccess(data) { | ||
|
||
| this.setState({ | ||
| shortUrl: data, | ||
| }); | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <CopyToClipboard | ||
| inMenu | ||
| text={this.getQueryLink()} | ||
| text={this.state.shortUrl} | ||
| copyNode={<span>share query</span>} | ||
| tooltipText="copy URL to clipboard" | ||
| shouldShowText={false} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import { bindActionCreators } from 'redux'; | |
| import * as Actions from '../actions'; | ||
| import SqlEditor from './SqlEditor'; | ||
| import shortid from 'shortid'; | ||
| import { getParamFromQuery, getLink } from '../../../utils/common'; | ||
| import { getParamFromQuery } from '../../../utils/common'; | ||
| import CopyQueryTabUrl from './CopyQueryTabUrl'; | ||
|
|
||
| const propTypes = { | ||
|
|
@@ -41,7 +41,7 @@ class TabbedSqlEditors extends React.Component { | |
| const queryEditorProps = { | ||
| id: shortid.generate(), | ||
| title: getParamFromQuery(this.state.query, 'title'), | ||
| dbId: getParamFromQuery(this.state.query, 'dbid'), | ||
| dbId: parseInt(getParamFromQuery(this.state.query, 'dbid'), 10), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously the database was not set in DatabaseSelect when loading the shared url because the passed string failed the prop as integer. Fixed it here |
||
| schema: getParamFromQuery(this.state.query, 'schema'), | ||
| autorun: getParamFromQuery(this.state.query, 'autorun'), | ||
| sql: getParamFromQuery(this.state.query, 'sql'), | ||
|
|
@@ -51,16 +51,6 @@ class TabbedSqlEditors extends React.Component { | |
| window.history.replaceState({}, document.title, this.state.cleanUri); | ||
| } | ||
| } | ||
| getQueryLink(qe) { | ||
| const params = []; | ||
| if (qe.dbId) params.push('dbid=' + qe.dbId); | ||
| if (qe.title) params.push('title=' + qe.title); | ||
| if (qe.schema) params.push('schema=' + qe.schema); | ||
| if (qe.autorun) params.push('autorun=' + qe.autorun); | ||
| if (qe.sql) params.push('sql=' + qe.sql); | ||
|
|
||
| return getLink(this.state.cleanUri, params); | ||
| } | ||
| renameTab(qe) { | ||
| /* eslint no-alert: 0 */ | ||
| const newTitle = prompt('Enter a new title for the tab'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like you are not handling error case here, what setting the state directly in the componentWillMount ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the error case the state won't get updated, so the shortUrl stays as empty string.