- {t('Share query')}
+ {t('share query')}
- )}
- tooltipText={t('Copy URL to clipboard')}
+ }
+ tooltipText={t('copy URL to clipboard')}
shouldShowText={false}
- getText={this.getUrl.bind(this)}
+ getText={this.getUrl}
/>
);
}
diff --git a/superset/assets/src/SqlLab/components/ExploreResultsButton.jsx b/superset/assets/src/SqlLab/components/ExploreResultsButton.jsx
index 207ac4c631462..329f73165780c 100644
--- a/superset/assets/src/SqlLab/components/ExploreResultsButton.jsx
+++ b/superset/assets/src/SqlLab/components/ExploreResultsButton.jsx
@@ -54,9 +54,7 @@ class ExploreResultsButton extends React.PureComponent {
this.dialog.show({
title: t('Explore'),
body: msg,
- actions: [
- Dialog.DefaultAction('Ok', () => {}, 'btn-primary'),
- ],
+ actions: [Dialog.DefaultAction('Ok', () => {}, 'btn-primary')],
bsSize: 'large',
bsStyle: 'warning',
onHide: (dialog) => {
@@ -106,10 +104,10 @@ class ExploreResultsButton extends React.PureComponent {
};
}
visualize() {
- this.props.actions.createDatasource(this.buildVizOptions(), this)
- .done((resp) => {
+ this.props.actions
+ .createDatasource(this.buildVizOptions())
+ .then((data) => {
const columns = this.getColumns();
- const data = JSON.parse(resp);
const formData = {
datasource: `${data.table_id}__table`,
metrics: [],
@@ -119,28 +117,28 @@ class ExploreResultsButton extends React.PureComponent {
all_columns: columns.map(c => c.name),
row_limit: 1000,
};
+
this.props.actions.addInfoToast(t('Creating a data source and creating a new tab'));
// open new window for data visualization
exportChart(formData);
})
- .fail(() => {
- this.props.actions.addDangerToast(this.props.errorMessage);
+ .catch(() => {
+ this.props.actions.addDangerToast(this.props.errorMessage || t('An error occurred'));
});
}
renderTimeoutWarning() {
return (
- {
- t('This query took %s seconds to run, ', Math.round(this.getQueryDuration())) +
+ {t('This query took %s seconds to run, ', Math.round(this.getQueryDuration())) +
t('and the explore view times out at %s seconds ', this.props.timeout) +
t('following this flow will most likely lead to your query timing out. ') +
t('We recommend your summarize your data further before following that flow. ') +
- t('If activated you can use the ')
- }
+ t('If activated you can use the ')}
CREATE TABLE AS
{t('feature to store a summarized data set that you can then explore.')}
- );
+
+ );
}
renderInvalidColumnMessage() {
const invalidColumns = this.getInvalidColumns();
@@ -150,15 +148,20 @@ class ExploreResultsButton extends React.PureComponent {
return (
{t('Column name(s) ')}
- {invalidColumns.join(', ')}
+
+ {invalidColumns.join(', ')}
+
{t('cannot be used as a column name. Please use aliases (as in ')}
- SELECT count(*)
+
+ SELECT count(*)
AS my_alias){' '}
- {t('limited to alphanumeric characters and underscores. Column aliases ending with ' +
- 'double underscores followed by a numeric value are not allowed for reasons ' +
- 'discussed in Github issue #5739.')}
-
);
+ {t(`limited to alphanumeric characters and underscores. Column aliases ending with
+ double underscores followed by a numeric value are not allowed for reasons
+ discussed in Github issue #5739.
+ `)}
+
+ );
}
render() {
return (
@@ -173,12 +176,9 @@ class ExploreResultsButton extends React.PureComponent {
this.dialog = el;
}}
/>
- {t('Explore')}
- );
+ {t('Explore')}
+
+ );
}
}
ExploreResultsButton.propTypes = propTypes;
@@ -198,4 +198,7 @@ function mapDispatchToProps(dispatch) {
}
export { ExploreResultsButton };
-export default connect(mapStateToProps, mapDispatchToProps)(ExploreResultsButton);
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps,
+)(ExploreResultsButton);
diff --git a/superset/assets/src/SqlLab/components/QueryAutoRefresh.jsx b/superset/assets/src/SqlLab/components/QueryAutoRefresh.jsx
index 0839c25cb7379..0b0936458362b 100644
--- a/superset/assets/src/SqlLab/components/QueryAutoRefresh.jsx
+++ b/superset/assets/src/SqlLab/components/QueryAutoRefresh.jsx
@@ -2,9 +2,9 @@ import React from 'react';
import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
-import * as Actions from '../actions';
+import { SupersetClient } from '@superset-ui/core';
-const $ = require('jquery');
+import * as Actions from '../actions';
const QUERY_UPDATE_FREQ = 2000;
const QUERY_UPDATE_BUFFER_MS = 5000;
@@ -19,16 +19,19 @@ class QueryAutoRefresh extends React.PureComponent {
}
shouldCheckForQueries() {
// if there are started or running queries, this method should return true
- const { queries } = this.props;
+ const { queries, queriesLastUpdate } = this.props;
const now = new Date().getTime();
- return Object.values(queries)
- .some(
+
+ return (
+ queriesLastUpdate > 0 &&
+ Object.values(queries).some(
q => ['running', 'started', 'pending', 'fetching', 'rendering'].indexOf(q.state) >= 0 &&
now - q.startDttm < MAX_QUERY_AGE_TO_POLL,
- );
+ )
+ );
}
startTimer() {
- if (!(this.timer)) {
+ if (!this.timer) {
this.timer = setInterval(this.stopwatch.bind(this), QUERY_UPDATE_FREQ);
}
}
@@ -39,10 +42,11 @@ class QueryAutoRefresh extends React.PureComponent {
stopwatch() {
// only poll /superset/queries/ if there are started or running queries
if (this.shouldCheckForQueries()) {
- const url = `/superset/queries/${this.props.queriesLastUpdate - QUERY_UPDATE_BUFFER_MS}`;
- $.getJSON(url, (data) => {
- if (Object.keys(data).length > 0) {
- this.props.actions.refreshQueries(data);
+ SupersetClient.get({
+ endpoint: `/superset/queries/${this.props.queriesLastUpdate - QUERY_UPDATE_BUFFER_MS}`,
+ }).then(({ json }) => {
+ if (Object.keys(json).length > 0) {
+ this.props.actions.refreshQueries(json);
}
});
}
@@ -70,4 +74,7 @@ function mapDispatchToProps(dispatch) {
};
}
-export default connect(mapStateToProps, mapDispatchToProps)(QueryAutoRefresh);
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps,
+)(QueryAutoRefresh);
diff --git a/superset/assets/src/SqlLab/components/QuerySearch.jsx b/superset/assets/src/SqlLab/components/QuerySearch.jsx
index 237ed11c7b534..a3d9ddf3a93c4 100644
--- a/superset/assets/src/SqlLab/components/QuerySearch.jsx
+++ b/superset/assets/src/SqlLab/components/QuerySearch.jsx
@@ -2,6 +2,8 @@ import React from 'react';
import PropTypes from 'prop-types';
import { Button } from 'react-bootstrap';
import Select from 'react-select';
+import { SupersetClient } from '@superset-ui/core';
+
import Loading from '../../components/Loading';
import QueryTable from './QueryTable';
import {
@@ -14,8 +16,6 @@ import { STATUS_OPTIONS, TIME_OPTIONS } from '../constants';
import AsyncSelect from '../../components/AsyncSelect';
import { t } from '../../locales';
-const $ = require('jquery');
-
const propTypes = {
actions: PropTypes.object.isRequired,
height: PropTypes.string.isRequired,
@@ -49,28 +49,34 @@ class QuerySearch extends React.PureComponent {
this.onUserClicked = this.onUserClicked.bind(this);
this.onDbClicked = this.onDbClicked.bind(this);
}
+
componentDidMount() {
this.refreshQueries();
}
+
onUserClicked(userId) {
this.setState({ userId }, () => {
this.refreshQueries();
});
}
+
onDbClicked(dbId) {
this.setState({ databaseId: dbId }, () => {
this.refreshQueries();
});
}
+
onChange(db) {
const val = db ? db.value : null;
this.setState({ databaseId: val });
}
+
onKeyDown(event) {
if (event.keyCode === 13) {
this.refreshQueries();
}
}
+
getTimeFromSelection(selection) {
switch (selection) {
case 'now':
@@ -91,37 +97,45 @@ class QuerySearch extends React.PureComponent {
return null;
}
}
+
changeFrom(user) {
const val = user ? user.value : null;
this.setState({ from: val });
}
+
changeTo(status) {
const val = status ? status.value : null;
this.setState({ to: val });
}
+
changeUser(user) {
const val = user ? user.value : null;
this.setState({ userId: val });
}
+
insertParams(baseUrl, params) {
const validParams = params.filter(function (p) {
return p !== '';
});
return baseUrl + '?' + validParams.join('&');
}
+
changeStatus(status) {
const val = status ? status.value : null;
this.setState({ status: val });
}
+
changeSearch(event) {
this.setState({ searchText: event.target.value });
}
+
userLabel(user) {
if (user.first_name && user.last_name) {
return user.first_name + ' ' + user.last_name;
}
return user.username;
}
+
userMutator(data) {
const options = [];
for (let i = 0; i < data.pks.length; i++) {
@@ -129,6 +143,7 @@ class QuerySearch extends React.PureComponent {
}
return options;
}
+
dbMutator(data) {
const options = data.result.map(db => ({ value: db.id, label: db.database_name }));
this.props.actions.setDatabases(data.result);
@@ -137,6 +152,7 @@ class QuerySearch extends React.PureComponent {
}
return options;
}
+
refreshQueries() {
this.setState({ queriesLoading: true });
const params = [
@@ -148,13 +164,15 @@ class QuerySearch extends React.PureComponent {
this.state.to ? `to=${this.getTimeFromSelection(this.state.to)}` : '',
];
- const url = this.insertParams('/superset/search_queries', params);
- $.getJSON(url, (data, status) => {
- if (status === 'success') {
- this.setState({ queriesArray: data, queriesLoading: false });
- }
- });
+ SupersetClient.get({ endpoint: this.insertParams('/superset/search_queries', params) })
+ .then(({ json }) => {
+ this.setState({ queriesArray: json, queriesLoading: false });
+ })
+ .catch(() => {
+ this.props.actions.addDangerToast(t('An error occurred when refreshing queries'));
+ });
}
+
render() {
return (