File tree Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change
1
+ import defaults from 'lodash/defaults' ;
2
+
1
3
import React , { useState } from 'react' ;
2
- import { JsonApiVariableQuery } from './types' ;
4
+ import { JsonApiVariableQuery , defaultVariableQuery } from './types' ;
3
5
import { InlineFormLabel } from '@grafana/ui' ;
4
6
import { JsonPathQueryField } from './JsonPathQueryField' ;
5
7
@@ -9,7 +11,9 @@ interface VariableQueryProps {
9
11
}
10
12
11
13
export const VariableQueryEditor : React . FC < VariableQueryProps > = ( { onChange, query } ) => {
12
- const [ state , setState ] = useState < JsonApiVariableQuery > ( query ) ;
14
+ const init = defaults ( query , defaultVariableQuery ) ;
15
+
16
+ const [ state , setState ] = useState < JsonApiVariableQuery > ( init ) ;
13
17
14
18
const saveQuery = ( ) => {
15
19
onChange ( state , state . jsonPath ) ;
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ export const defaultQuery: Partial<JsonApiQuery> = {
22
22
queryParams : '' ,
23
23
} ;
24
24
25
+ export const defaultVariableQuery : Partial < JsonApiVariableQuery > = {
26
+ jsonPath : '' ,
27
+ queryParams : '' ,
28
+ } ;
29
+
25
30
export interface JsonApiDataSourceOptions extends DataSourceJsonData {
26
31
queryParams ?: string ;
27
32
}
You can’t perform that action at this time.
0 commit comments