[sqllab] config item for SQLLAB_DEFAULT_DBID (#1793)

This commit is contained in:
Maxime Beauchemin
2016-12-07 21:01:02 -08:00
committed by GitHub
parent a95cd71456
commit aeda5bd260
5 changed files with 44 additions and 27 deletions

View File

@@ -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 ...',
@@ -216,6 +218,7 @@ function mapStateToProps(state) {
tabHistory: state.tabHistory,
networkOn: state.networkOn,
tables: state.tables,
defaultDbId: state.defaultDbId,
};
}
function mapDispatchToProps(dispatch) {

View File

@@ -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';
@@ -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');
@@ -25,5 +29,5 @@ render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('app')
appContainer
);

View File

@@ -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 = {
@@ -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);