Skip to content

Commit

Permalink
Resolve comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Kyryliuk committed Feb 11, 2017
1 parent 428a3d0 commit ef4d1de
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
60 changes: 30 additions & 30 deletions superset/assets/javascripts/SqlLab/components/SqlEditorLeftBar.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
require('es6-promise').polyfill();
require('isomorphic-fetch');
const $ = window.$ = require('jquery');
import React from 'react';
import Select from 'react-select';
import { Label, Button } from 'react-bootstrap';
import TableElement from './TableElement';
import AsyncSelect from '../../components/AsyncSelect';
import fetch from 'isomorphic-fetch';

const propTypes = {
queryEditor: React.PropTypes.object.isRequired,
Expand Down Expand Up @@ -34,7 +31,7 @@ class SqlEditorLeftBar extends React.PureComponent {
}
componentWillMount() {
this.fetchSchemas(this.props.queryEditor.dbId);
this.fetchTables(this.props.queryEditor.dbId);
this.fetchTables(this.props.queryEditor.dbId, this.props.queryEditor.schema);
}
onChange(db) {
const val = (db) ? db.value : null;
Expand Down Expand Up @@ -65,14 +62,11 @@ class SqlEditorLeftBar extends React.PureComponent {
if (!this.props.queryEditor.dbId || !input) {
return Promise.resolve({ options: [] });
}
return fetch(
`/superset/tables/${this.props.queryEditor.dbId}/`
`${this.props.queryEditor.schema}/${input}`,
{ method: 'GET', credentials: 'include' }
)
.then(response => response.json())
.then(json => ({ options: json.options }));
const url = `/superset/tables/${this.props.queryEditor.dbId}/\
${this.props.queryEditor.schema}/${input}`;
return $.get(url).then((data) => ({ options: data.options }));
}
// TODO: move fetching methods to the actions.
fetchTables(dbId, schema, substr) {
if (dbId) {
this.setState({ tableLoading: true, tableOptions: [] });
Expand Down Expand Up @@ -104,6 +98,8 @@ class SqlEditorLeftBar extends React.PureComponent {
this.fetchTables(this.props.queryEditor.dbId, schemaName);
}
this.setState({ tableLoading: true });
// TODO: handle setting the tableLoading state depending on success or
// failure of the addTable async call in the action.
this.props.actions.addTable(this.props.queryEditor, tableName, schemaName);
this.setState({ tableLoading: false });
}
Expand Down Expand Up @@ -169,25 +165,29 @@ class SqlEditorLeftBar extends React.PureComponent {
/>
</div>
<div className="m-t-5">
{this.props.queryEditor.schema && <Select
name="select-table"
ref="selectTable"
isLoading={this.state.tableLoading}
value={this.state.tableName}
placeholder={`Add a table (${this.state.tableOptions.length})`}
autosize={false}
onChange={this.changeTable.bind(this)}
options={this.state.tableOptions}
/>}
{!this.props.queryEditor.schema && <Select.Async
name="async-select-table"
ref="selectTable"
value={this.state.tableName}
placeholder={"Type to search .."}
autosize={false}
onChange={this.changeTable.bind(this)}
loadOptions={this.getTableNamesBySubStr.bind(this)}
/>}
{this.props.queryEditor.schema &&
<Select
name="select-table"
ref="selectTable"
isLoading={this.state.tableLoading}
value={this.state.tableName}
placeholder={`Add a table (${this.state.tableOptions.length})`}
autosize={false}
onChange={this.changeTable.bind(this)}
options={this.state.tableOptions}
/>
}
{!this.props.queryEditor.schema &&
<Select.Async
name="async-select-table"
ref="selectTable"
value={this.state.tableName}
placeholder={"Type to search ..."}
autosize={false}
onChange={this.changeTable.bind(this)}
loadOptions={this.getTableNamesBySubStr.bind(this)}
/>
}
</div>
<hr />
<div className="m-t-5">
Expand Down
2 changes: 0 additions & 2 deletions superset/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@
"datamaps": "^0.5.8",
"datatables-bootstrap3-plugin": "^0.5.0",
"datatables.net-bs": "^1.10.12",
"es6-promise": "^4.0.5",
"font-awesome": "^4.6.3",
"gridster": "^0.5.6",
"immutability-helper": "^2.0.0",
"immutable": "^3.8.1",
"isomorphic-fetch": "^2.2.1",
"jquery": "^2.2.1",
"jquery-ui": "1.10.5",
"lodash.throttle": "^4.1.1",
Expand Down
1 change: 0 additions & 1 deletion superset/cache_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def wrapped_f(cls, *args, **kwargs):
if o is not None:
return o
o = f(cls, *args, **kwargs)
print('cache_key: {}'.format(cache_key))
tables_cache.set(cache_key, o, timeout=timeout)
return o
return wrapped_f
Expand Down
2 changes: 1 addition & 1 deletion superset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def rejected_datasources(self, sql, database, schema):
return [
t for t in superset_query.tables if not
self.datasource_access_by_fullname(database, t, schema)]

def accessible_by_user(self, database, datasource_names, schema=None):
if self.database_access(database) or self.all_datasource_access():
return datasource_names
Expand Down Expand Up @@ -1791,7 +1792,6 @@ def activity_per_day(self):
@has_access_api
@expose("/schemas/<db_id>")
def schemas(self, db_id):
# db_id = request.args.get('db_id')
database = (
db.session
.query(models.Database)
Expand Down

0 comments on commit ef4d1de

Please sign in to comment.