From b763e00630361bf6d8857046e757b753c00f5d81 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Mon, 24 Apr 2017 17:54:39 -0700 Subject: [PATCH] Highlight first tempVar if selected is filtered out --- ui/src/data_explorer/components/RawQueryEditor.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/src/data_explorer/components/RawQueryEditor.js b/ui/src/data_explorer/components/RawQueryEditor.js index f5a2a6135..a7af4dc8e 100644 --- a/ui/src/data_explorer/components/RawQueryEditor.js +++ b/ui/src/data_explorer/components/RawQueryEditor.js @@ -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, })