Skip to content

Commit 1631631

Browse files
committed
Set default query for variable query editor
Fixes #156
1 parent 972a899 commit 1631631

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/components/VariableQueryEditor.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { TimeRange } from '@grafana/data';
22
import { JsonDataSource } from 'datasource';
3+
import defaults from 'lodash/defaults';
34
import React from 'react';
4-
import { JsonApiQuery } from '../types';
5+
import { defaultQuery, JsonApiQuery } from '../types';
56
import { QueryEditor } from './QueryEditor';
67

78
interface VariableQueryProps {
@@ -15,6 +16,8 @@ interface VariableQueryProps {
1516
export const VariableQueryEditor: React.FC<VariableQueryProps> = (props) => {
1617
const { query, onChange } = props;
1718

19+
const q = defaults(query, defaultQuery);
20+
1821
const saveQuery = (newQuery: JsonApiQuery) => {
1922
if (newQuery) {
2023
onChange(newQuery, newQuery.fields[0].jsonPath);
@@ -26,7 +29,7 @@ export const VariableQueryEditor: React.FC<VariableQueryProps> = (props) => {
2629
{...props}
2730
onRunQuery={() => {}}
2831
onChange={saveQuery}
29-
query={query}
32+
query={q}
3033
limitFields={2}
3134
editorContext="variables"
3235
/>

0 commit comments

Comments
 (0)