Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sqllab] config item for SQLLAB_DEFAULT_DBID #1793

Merged
merged 1 commit into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ class TabbedSqlEditors extends React.PureComponent {
const activeQueryEditor = this.activeQueryEditor();
const qe = {
title: `Untitled Query ${queryCount}`,
dbId: (activeQueryEditor) ? activeQueryEditor.dbId : null,
dbId: (activeQueryEditor && activeQueryEditor.dbId) ?
activeQueryEditor.dbId :
this.props.defaultDbId,
schema: (activeQueryEditor) ? activeQueryEditor.schema : null,
autorun: false,
sql: 'SELECT ...',
Expand Down Expand Up @@ -216,6 +218,7 @@ function mapStateToProps(state) {
tabHistory: state.tabHistory,
networkOn: state.networkOn,
tables: state.tables,
defaultDbId: state.defaultDbId,
};
}
function mapDispatchToProps(dispatch) {
Expand Down
10 changes: 7 additions & 3 deletions superset/assets/javascripts/SqlLab/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('bootstrap');

import React from 'react';
import { render } from 'react-dom';
import { initialState, sqlLabReducer } from './reducers';
import { getInitialState, sqlLabReducer } from './reducers';
import { enhancer } from '../reduxUtils';
import { createStore, compose, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
Expand All @@ -15,8 +15,12 @@ import App from './components/App';

require('./main.css');

const appContainer = document.getElementById('app');
const bootstrapData = JSON.parse(appContainer.getAttribute('data-bootstrap'));
const state = Object.assign({}, getInitialState(bootstrapData.defaultDbId), bootstrapData);

let store = createStore(
sqlLabReducer, initialState, compose(applyMiddleware(thunkMiddleware), enhancer()));
sqlLabReducer, state, compose(applyMiddleware(thunkMiddleware), enhancer()));

// jquery hack to highlight the navbar menu
$('a:contains("SQL Lab")').parent().addClass('active');
Expand All @@ -25,5 +29,5 @@ render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('app')
appContainer
);
44 changes: 23 additions & 21 deletions superset/assets/javascripts/SqlLab/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@ import { now } from '../modules/dates';
import { addToObject, alterInObject, alterInArr, removeFromArr, getFromArr, addToArr }
from '../reduxUtils.js';

export const defaultQueryEditor = {
id: shortid.generate(),
title: 'Untitled Query',
sql: 'SELECT *\nFROM\nWHERE',
selectedText: null,
latestQueryId: null,
autorun: false,
dbId: null,
};
export function getInitialState(defaultDbId) {
const defaultQueryEditor = {
id: shortid.generate(),
title: 'Untitled Query',
sql: 'SELECT *\nFROM\nWHERE',
selectedText: null,
latestQueryId: null,
autorun: false,
dbId: defaultDbId,
};

export const initialState = {
alerts: [],
networkOn: true,
queries: {},
databases: {},
queryEditors: [defaultQueryEditor],
tabHistory: [defaultQueryEditor.id],
tables: [],
queriesLastUpdate: 0,
activeSouthPaneTab: 'Results',
};
return {
alerts: [],
networkOn: true,
queries: {},
databases: {},
queryEditors: [defaultQueryEditor],
tabHistory: [defaultQueryEditor.id],
tables: [],
queriesLastUpdate: 0,
activeSouthPaneTab: 'Results',
};
}

export const sqlLabReducer = function (state, action) {
const actionHandlers = {
Expand Down Expand Up @@ -70,7 +72,7 @@ export const sqlLabReducer = function (state, action) {
return Object.assign({}, state, { queries: newQueries });
},
[actions.RESET_STATE]() {
return Object.assign({}, initialState);
return Object.assign({}, getInitialState());
},
[actions.MERGE_TABLE]() {
const at = Object.assign({}, action.table);
Expand Down
3 changes: 3 additions & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ class CeleryConfig(object):
# Timeout duration for SQL Lab synchronous queries
SQLLAB_TIMEOUT = 30

# SQLLAB_DEFAULT_DBID
SQLLAB_DEFAULT_DBID = None

# An instantiated derivative of werkzeug.contrib.cache.BaseCache
# if enabled, it can be used to store the results of long-running queries
# in SQL Lab by using the "Run Async" button/feature
Expand Down
9 changes: 7 additions & 2 deletions superset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2702,8 +2702,13 @@ def profile(self, username):
@expose("/sqllab")
def sqllab(self):
"""SQL Editor"""
return self.render_template('superset/sqllab.html')

d = {
'defaultDbId': config.get('SQLLAB_DEFAULT_DBID'),
}
return self.render_template(
'superset/sqllab.html',
bootstrap_data=json.dumps(d, default=utils.json_iso_dttm_ser)
)
appbuilder.add_view_no_menu(Superset)

if config['DRUID_IS_ACTIVE']:
Expand Down