mirror of https://github.com/apache/superset.git
[Bugfix] autocomplete in sqleditor doesnot use newly loaded table columns (#1712)
This commit is contained in:
parent
94dde075b3
commit
32fc0ff6d0
|
@ -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 });
|
||||
|
||||
this.setState({ words }, () => {
|
||||
const completer = {
|
||||
getCompletions: this.getCompletions.bind(this),
|
||||
};
|
||||
if (langTools) {
|
||||
langTools.setCompleters([completer, langTools.keyWordCompleter]);
|
||||
}
|
||||
});
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
|
|
Loading…
Reference in New Issue