This is an automated email from the ASF dual-hosted git repository. hugh pushed a commit to branch hxgh/ch3715/sql-lab-doesn-t-select-a-database-by-default in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit 0679db9881cbad5320b0aea378901a3493eb9e38 Author: hughhhh <[email protected]> AuthorDate: Thu Dec 3 17:03:07 2020 -0800 get database ids initially --- .../src/SqlLab/components/TabbedSqlEditors.jsx | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx b/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx index f0f6d48..be10002 100644 --- a/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx +++ b/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx @@ -32,6 +32,22 @@ import * as Actions from '../actions/sqlLab'; import SqlEditor from './SqlEditor'; import TabStatusIcon from './TabStatusIcon'; + +import { makeApi } from '@superset-ui/core'; +import rison from 'rison'; + + +const getDatabasesIds = async () => { + const queryParams = rison.encode({}); + const response = await makeApi({ + method: 'GET', + endpoint: '/api/v1/database', + })(`q=${queryParams}`); + + console.log(response.ids); + return response; +}; + const propTypes = { actions: PropTypes.object.isRequired, defaultDbId: PropTypes.number, @@ -76,6 +92,7 @@ class TabbedSqlEditors extends React.PureComponent { queriesArray: [], dataPreviewQueries: [], hideLeftBar: false, + databaseIds: getDatabasesIds(), }; this.removeQueryEditor = this.removeQueryEditor.bind(this); this.renameTab = this.renameTab.bind(this); @@ -164,7 +181,6 @@ class TabbedSqlEditors extends React.PureComponent { this.popNewTab(); } else if (query.new || this.props.queryEditors.length === 0) { this.newQueryEditor(); - if (query.new) { window.history.replaceState({}, document.title, this.state.sqlLabUrl); } @@ -240,11 +256,10 @@ class TabbedSqlEditors extends React.PureComponent { } newQueryEditor() { + console.log(this.state.databaseIds); queryCount += 1; const activeQueryEditor = this.activeQueryEditor(); - const firstDbId = Math.min( - ...Object.values(this.props.databases).map(database => database.id), - ); + const firstDbId = Math.min(this.state.databaseIds); const warning = isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE) ? '' : `${t(
