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