This is an automated email from the ASF dual-hosted git repository. maximebeauchemin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push: new 1781ebb fix: [search query view] edit link is broken (#10128) 1781ebb is described below commit 1781ebbaa40b0bad89ea101ca91431cb07b9dbed Author: Maxime Beauchemin <maximebeauche...@gmail.com> AuthorDate: Thu Jun 25 12:20:10 2020 -0700 fix: [search query view] edit link is broken (#10128) * fix: [search query view] edit link is broken * eslint + mypy * rever app.py changes * addressing comments * use api/v1/query * fix test --- setup.cfg | 2 +- superset-frontend/src/SqlLab/actions/sqlLab.js | 24 ++++++++++++++++++++-- .../src/SqlLab/components/QueryTable.jsx | 19 +++++------------ .../src/SqlLab/components/RunQueryActionButton.tsx | 2 +- .../src/SqlLab/components/TabbedSqlEditors.jsx | 10 ++++++++- superset/models/sql_lab.py | 1 + superset/queries/api.py | 1 + tests/queries/api_tests.py | 4 +++- 8 files changed, 43 insertions(+), 20 deletions(-) diff --git a/setup.cfg b/setup.cfg index eef0e37..e7eedf7 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,s [...] +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_them [...] 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 122d9ec..8f9f509 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 b16aad4..3e227df 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 { <div style={{ width: '100px' }}> <button className="btn btn-link btn-xs" - onClick={this.openQuery.bind(this, q.dbId, q.schema, q.sql)} + onClick={this.openQuery.bind(this, q.queryId)} > - <i className="fa fa-external-link" /> - {t('Open in SQL Editor')} + <i className="fa fa-external-link m-r-3" /> + {t('Edit')} </button> </div> ); diff --git a/superset-frontend/src/SqlLab/components/RunQueryActionButton.tsx b/superset-frontend/src/SqlLab/components/RunQueryActionButton.tsx index d6c1974..f1b4c5c 100644 --- a/superset-frontend/src/SqlLab/components/RunQueryActionButton.tsx +++ b/superset-frontend/src/SqlLab/components/RunQueryActionButton.tsx @@ -40,7 +40,7 @@ const RunQueryActionButton = ({ runQuery = NO_OP, selectedText, stopQuery = NO_OP, - sql, + sql = '', }: Props) => { const runBtnText = selectedText ? t('Run Selected Query') : t('Run'); const btnStyle = selectedText ? 'warning' : 'primary'; diff --git a/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx b/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx index dc7d557..6fda416 100644 --- a/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx +++ b/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx @@ -108,11 +108,19 @@ class TabbedSqlEditors extends React.PureComponent { }; // Popping a new tab based on the querystring - if (query.id || query.sql || query.savedQueryId || query.datasourceKey) { + if ( + query.id || + query.sql || + query.savedQueryId || + query.datasourceKey || + query.queryId + ) { if (query.id) { this.props.actions.popStoredQuery(query.id); } else if (query.savedQueryId) { this.props.actions.popSavedQuery(query.savedQueryId); + } else if (query.queryId) { + this.props.actions.popQuery(query.queryId); } else if (query.datasourceKey) { this.props.actions.popDatasourceQuery(query.datasourceKey, query.sql); } else if (query.sql) { diff --git a/superset/models/sql_lab.py b/superset/models/sql_lab.py index 886d0c5..414dec4 100644 --- a/superset/models/sql_lab.py +++ b/superset/models/sql_lab.py @@ -112,6 +112,7 @@ class Query(Model, ExtraJSONMixin): "errorMessage": self.error_message, "executedSql": self.executed_sql, "id": self.client_id, + "queryId": self.id, "limit": self.limit, "progress": self.progress, "rows": self.rows, diff --git a/superset/queries/api.py b/superset/queries/api.py index 0d49bc3..7f2b32e 100644 --- a/superset/queries/api.py +++ b/superset/queries/api.py @@ -49,6 +49,7 @@ class QueryRestApi(BaseSupersetModelRestApi): "status", "tab_name", "sql_editor_id", + "database.id", "schema", "sql", "select_sql", diff --git a/tests/queries/api_tests.py b/tests/queries/api_tests.py index 4f43c77..5016812 100644 --- a/tests/queries/api_tests.py +++ b/tests/queries/api_tests.py @@ -78,8 +78,9 @@ class QueryApiTests(SupersetTestCase): """ admin = self.get_user("admin") client_id = self.get_random_string() + example_db = get_example_database() query = self.insert_query( - get_example_database().id, + example_db.id, admin.id, client_id, sql="SELECT col1, col2 from table1", @@ -92,6 +93,7 @@ class QueryApiTests(SupersetTestCase): self.assertEqual(rv.status_code, 200) expected_result = { + "database": {"id": example_db.id}, "client_id": client_id, "end_result_backend_time": None, "error_message": None,