[Bugfix] autocomplete in sqleditor doesnot use newly loaded table columns (#1712)

This commit is contained in:
vera-liu 2016-11-30 09:09:35 -08:00 committed by GitHub
parent 94dde075b3
commit 32fc0ff6d0
1 changed files with 13 additions and 11 deletions

View File

@ -33,11 +33,11 @@ class AceEditorWrapper extends React.PureComponent {
componentDidMount() {
// Making sure no text is selected from previous mount
this.props.actions.queryEditorSetSelectedText(this.props.queryEditor, null);
this.setAutoCompleter();
this.setAutoCompleter(this.props);
}
componentWillReceiveProps(nextProps) {
if (!areArraysShallowEqual(this.props.tables, nextProps.tables)) {
this.setAutoCompleter();
this.setAutoCompleter(nextProps);
}
}
textChange(text) {
@ -63,11 +63,11 @@ class AceEditorWrapper extends React.PureComponent {
this.props.queryEditor, editor.getSelectedText());
});
}
setAutoCompleter() {
setAutoCompleter(props) {
// Loading table and column names as auto-completable words
let words = [];
const columns = {};
const tables = this.props.tables || [];
const tables = props.tables || [];
tables.forEach(t => {
words.push({ name: t.name, value: t.name, score: 55, meta: 'table' });
const cols = t.columns || [];
@ -78,13 +78,15 @@ class AceEditorWrapper extends React.PureComponent {
words = words.concat(Object.keys(columns).map(col => (
{ name: col, value: col, score: 50, meta: 'column' }
)));
this.setState({ words });
const completer = {
getCompletions: this.getCompletions.bind(this),
};
if (langTools) {
langTools.setCompleters([completer, langTools.keyWordCompleter]);
}
this.setState({ words }, () => {
const completer = {
getCompletions: this.getCompletions.bind(this),
};
if (langTools) {
langTools.setCompleters([completer, langTools.keyWordCompleter]);
}
});
}
render() {
return (