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

[sql lab] fix table dropdown with large schema make UI unresponsive #2547

Merged
merged 1 commit into from
Apr 4, 2017
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 @@ -3,12 +3,15 @@ import Button from '../../components/Button';

const propTypes = {
allowAsync: PropTypes.bool.isRequired,
dbId: PropTypes.number.isRequired,
dbId: PropTypes.number,
queryState: PropTypes.string.isRequired,
runQuery: PropTypes.func.isRequired,
selectedText: PropTypes.string,
stopQuery: PropTypes.func.isRequired,
};
const defaultProps = {
allowAsync: false,
};

export default function RunQueryActionButton(props) {
const runBtnText = props.selectedText ? 'Run Selected Query' : 'Run Query';
Expand Down Expand Up @@ -69,3 +72,4 @@ export default function RunQueryActionButton(props) {
}

RunQueryActionButton.propTypes = propTypes;
RunQueryActionButton.defaultProps = defaultProps;
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class SqlEditor extends React.PureComponent {
<div className="pull-left">
<Form inline>
<RunQueryActionButton
allowAsync={this.props.database && this.props.database.allow_run_async}
allowAsync={this.props.database ? this.props.database.allow_run_async : false}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[not that important] I'm surprised this doesn't cause an eslint error, was it complaining about not being a boolean? !!this.props.database && this.props.database.allow_run_async or Boolean(this.props.database) && this.props.database.allow_run_async could be alternatives.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use this in a fair amount of places. The casting to boolean is implicit. I know the equivalent is considered pythonesque in python but not sure about JS...

dbId={this.props.queryEditor.dbId}
queryState={this.props.latestQuery && this.props.latestQuery.state}
runQuery={this.runQuery.bind(this)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,22 @@ class SqlEditorLeftBar extends React.PureComponent {
`${this.props.queryEditor.schema}/${input}`;
return $.get(url).then((data) => ({ options: data.options }));
}
// TODO: move fetching methods to the actions.
fetchTables(dbId, schema, substr) {
// This can be large so it shouldn't be put in the Redux store
if (dbId && schema) {
this.setState({ tableLoading: true, tableOptions: [] });
const url = `/superset/tables/${dbId}/${schema}/${substr}/`;
$.get(url, (data) => {
const filterOptions = createFilterOptions({ options: data.options });
this.setState({
filterOptions,
tableLoading: false,
tableOptions: data.options,
tableLength: data.tableLength,
});
});
} else {
this.setState({ tableLoading: false, tableOptions: [] });
this.setState({ tableLoading: false, tableOptions: [], filterOptions: null });
}
}
changeTable(tableOpt) {
Expand Down Expand Up @@ -126,8 +128,6 @@ class SqlEditorLeftBar extends React.PureComponent {
}
render() {
const shouldShowReset = window.location.search === '?reset=1';
const options = this.state.tableOptions;
const filterOptions = createFilterOptions({ options });
return (
<div className="scrollbar-container">
<div className="clearfix sql-toolbar scrollbar-content">
Expand Down Expand Up @@ -173,7 +173,7 @@ class SqlEditorLeftBar extends React.PureComponent {
placeholder={`Add a table (${this.state.tableOptions.length})`}
autosize={false}
onChange={this.changeTable.bind(this)}
filterOptions={filterOptions}
filterOptions={this.state.filterOptions}
options={this.state.tableOptions}
/>
}
Expand Down