mirror of
https://github.com/apache/superset.git
synced 2026-04-23 10:04:45 +00:00
Added url shortner for sharing query link (#1314)
* Added url shortner for sharing query link * Move shortener outside CopyToClipboard and move ajax call to common.js * transfer dbId to int to avoid failed prop
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { PropTypes } from 'react';
|
||||
import { Popover, OverlayTrigger } from 'react-bootstrap';
|
||||
import CopyToClipboard from './../../components/CopyToClipboard';
|
||||
import $ from 'jquery';
|
||||
import { getShortUrl } from '../../../utils/common';
|
||||
|
||||
const propTypes = {
|
||||
slice: PropTypes.object.isRequired,
|
||||
@@ -15,28 +15,17 @@ export default class URLShortLinkButton extends React.Component {
|
||||
};
|
||||
}
|
||||
|
||||
getShortUrl() {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/r/shortner/',
|
||||
data: {
|
||||
data: '/' + window.location.pathname + window.location.search,
|
||||
},
|
||||
success: (data) => {
|
||||
this.setState({
|
||||
shortUrl: data,
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
/* eslint no-console: 0 */
|
||||
if (console && console.warn) {
|
||||
console.warn('Something went wrong...');
|
||||
console.warn(error);
|
||||
}
|
||||
},
|
||||
onShortUrlSuccess(data) {
|
||||
this.setState({
|
||||
shortUrl: data,
|
||||
});
|
||||
}
|
||||
|
||||
getCopyUrl() {
|
||||
const longUrl = window.location.pathname + window.location.search;
|
||||
getShortUrl(longUrl, this.onShortUrlSuccess.bind(this));
|
||||
}
|
||||
|
||||
renderPopover() {
|
||||
return (
|
||||
<Popover id="shorturl-popover">
|
||||
@@ -54,7 +43,7 @@ export default class URLShortLinkButton extends React.Component {
|
||||
trigger="click"
|
||||
rootClose
|
||||
placement="left"
|
||||
onEnter={this.getShortUrl.bind(this)}
|
||||
onEnter={this.getCopyUrl.bind(this)}
|
||||
overlay={this.renderPopover()}
|
||||
>
|
||||
<span className="btn btn-default btn-sm">
|
||||
|
||||
Reference in New Issue
Block a user