Highlight first tempVar if selected is filtered out

pull/1326/head
Andrew Watkins 2017-04-24 17:54:39 -07:00
parent a7bb10723a
commit b763e00630
1 changed files with 8 additions and 0 deletions

View File

@ -138,6 +138,7 @@ class RawQueryEditor extends Component {
handleChange() {
const {templates} = this.props
const {selectedTemplate} = this.state
const value = this.editor.value
const matches = value.match(TEMPLATE_MATCHER)
if (matches) {
@ -147,8 +148,15 @@ class RawQueryEditor extends Component {
const filteredTemplates = templates.filter(t =>
t.tempVar.includes(matches[0].substring(1))
)
const found = filteredTemplates.find(
t => t.tempVar === selectedTemplate && selectedTemplate.tempVar
)
const newTemplate = found ? found : filteredTemplates[0]
this.setState({
isTemplating: true,
selectedTemplate: newTemplate,
filteredTemplates,
value,
})