diff --git a/setup.cfg b/setup.cfg index eef0e3778..e7eedf76a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -45,7 +45,7 @@ combine_as_imports = true include_trailing_comma = true line_length = 88 known_first_party = superset -known_third_party =alembic,apispec,backoff,bleach,cachelib,celery,click,colorama,contextlib2,croniter,cryptography,dateutil,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,geohash,geopy,humanize,isodate,jinja2,markdown,markupsafe,marshmallow,msgpack,numpy,pandas,parsedatetime,pathlib2,polyline,prison,pyarrow,pyhive,pytz,retry,selenium,setuptools,simplejson,slack,sphinx_rtd_theme,sqlalchemy,sqlalchemy_utils,sqlparse,werkzeug,wtforms,wtforms_json,yaml +known_third_party =alembic,apispec,backoff,bleach,cachelib,celery,click,colorama,contextlib2,croniter,cryptography,dateutil,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,geohash,geopy,humanize,isodate,jinja2,markdown,markupsafe,marshmallow,msgpack,numpy,pandas,parameterized,parsedatetime,pathlib2,polyline,prison,pyarrow,pyhive,pytz,retry,selenium,setuptools,simplejson,slack,sphinx_rtd_theme,sqlalchemy,sqlalchemy_utils,sqlparse,werkzeug,wtforms,wtforms_json,yaml multi_line_output = 3 order_by_type = false diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index 122d9ecf6..8f9f509fa 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -101,6 +101,7 @@ export const CtasEnum = { TABLE: 'TABLE', VIEW: 'VIEW', }; +const ERR_MSG_CANT_LOAD_QUERY = t("The query couldn't be loaded"); // a map of SavedQuery field names to the different names used client-side, // because for now making the names consistent is too complicated @@ -1182,7 +1183,7 @@ export function popStoredQuery(urlId) { }), ), ) - .catch(() => dispatch(addDangerToast(t("The query couldn't be loaded")))); + .catch(() => dispatch(addDangerToast(ERR_MSG_CANT_LOAD_QUERY))); }; } export function popSavedQuery(saveQueryId) { @@ -1197,7 +1198,26 @@ export function popSavedQuery(saveQueryId) { }; return dispatch(addQueryEditor(queryEditorProps)); }) - .catch(() => dispatch(addDangerToast(t("The query couldn't be loaded")))); + .catch(() => dispatch(addDangerToast(ERR_MSG_CANT_LOAD_QUERY))); + }; +} +export function popQuery(queryId) { + return function (dispatch) { + return SupersetClient.get({ + endpoint: `/api/v1/query/${queryId}`, + }) + .then(({ json }) => { + const queryData = json.result; + const queryEditorProps = { + dbId: queryData.database.id, + schema: queryData.schema, + sql: queryData.sql, + title: `Copy of ${queryData.tab_name}`, + autorun: false, + }; + return dispatch(addQueryEditor(queryEditorProps)); + }) + .catch(() => dispatch(addDangerToast(ERR_MSG_CANT_LOAD_QUERY))); }; } export function popDatasourceQuery(datasourceKey, sql) { diff --git a/superset-frontend/src/SqlLab/components/QueryTable.jsx b/superset-frontend/src/SqlLab/components/QueryTable.jsx index b16aad4ad..3e227df01 100644 --- a/superset-frontend/src/SqlLab/components/QueryTable.jsx +++ b/superset-frontend/src/SqlLab/components/QueryTable.jsx @@ -28,7 +28,6 @@ import ResultSet from './ResultSet'; import ModalTrigger from '../../components/ModalTrigger'; import HighlightedSql from './HighlightedSql'; import { fDuration } from '../../modules/dates'; -import { storeQuery } from '../../utils/common'; import QueryStateLabel from './QueryStateLabel'; const propTypes = { @@ -57,18 +56,10 @@ class QueryTable extends React.PureComponent { activeQuery: null, }; } - callback(url) { + openQuery(id) { + const url = `/superset/sqllab?queryId=${id}`; window.open(url); } - openQuery(dbId, schema, sql) { - const newQuery = { - dbId, - title: t('Untitled Query'), - schema, - sql, - }; - storeQuery(newQuery).then(url => this.callback(url)); - } hideVisualizeModal() { this.setState({ showVisualizeModal: false }); } @@ -127,10 +118,10 @@ class QueryTable extends React.PureComponent {