@@ -8,16 +8,34 @@ interface Props {
8
8
query : JsonApiQuery ;
9
9
onChange : ( query : JsonApiQuery ) => void ;
10
10
onRunQuery : ( ) => void ;
11
+ editorContext : string ;
11
12
}
12
13
13
- export const ExperimentalEditor = ( { query, onChange, onRunQuery } : Props ) => {
14
+ export const ExperimentalEditor = ( { query, onChange, onRunQuery, editorContext } : Props ) => {
15
+ // Group by
14
16
const { groupByField } = query ;
15
17
16
18
const onGroupByChange = ( field ?: string ) => {
17
19
onChange ( { ...query , groupByField : field } ) ;
18
20
onRunQuery ( ) ;
19
21
} ;
20
22
23
+ // Variable label
24
+ const { variableTextField } = query ;
25
+
26
+ const onVariableLabelChange = ( field ?: string ) => {
27
+ onChange ( { ...query , variableTextField : field } ) ;
28
+ onRunQuery ( ) ;
29
+ } ;
30
+
31
+ // Variable value
32
+ const { variableValueField } = query ;
33
+
34
+ const onVariableValueChange = ( field ?: string ) => {
35
+ onChange ( { ...query , variableValueField : field } ) ;
36
+ onRunQuery ( ) ;
37
+ } ;
38
+
21
39
const fieldNames = query . fields
22
40
. map ( ( field ) => {
23
41
const pathArray = ( JSONPath as any ) . toPathArray ( field . jsonPath ) ;
@@ -30,30 +48,96 @@ export const ExperimentalEditor = ({ query, onChange, onRunQuery }: Props) => {
30
48
< InfoBox severity = "warning" >
31
49
{ `The features listed here are experimental. They might change or be removed without notice. In the tooltip for each feature, there's a link to a pull request where you can submit feedback for that feature.` }
32
50
</ InfoBox >
33
- < InlineFieldRow >
34
- < InlineField
35
- label = "Group by"
36
- tooltip = {
37
- < >
38
- < p >
39
- {
40
- 'Groups the query result into multiple results. This can be useful when you want to graph multiple time series in the same panel.'
41
- }
42
- </ p >
43
- < a href = "https://github.com/marcusolsson/grafana-json-datasource" > Submit feedback</ a >
44
- </ >
45
- }
46
- >
47
- < Select
48
- placeholder = { 'Field' }
49
- width = { 12 }
50
- isClearable = { true }
51
- value = { fieldNames . find ( ( v ) => v . value === groupByField ) }
52
- options = { fieldNames }
53
- onChange = { ( value ) => onGroupByChange ( value ?. value ) }
54
- />
55
- </ InlineField >
56
- </ InlineFieldRow >
51
+ { editorContext === 'default' && (
52
+ < >
53
+ < InlineFieldRow >
54
+ < InlineField
55
+ label = "Group by"
56
+ tooltip = {
57
+ < >
58
+ < p >
59
+ {
60
+ 'Groups the query result into multiple results. This can be useful when you want to graph multiple time series in the same panel.'
61
+ }
62
+ </ p >
63
+ < a
64
+ href = "https://github.com/marcusolsson/grafana-json-datasource/issues/36"
65
+ target = "_blank"
66
+ rel = "noreferrer"
67
+ >
68
+ Share feedback
69
+ </ a >
70
+ </ >
71
+ }
72
+ >
73
+ < Select
74
+ placeholder = { 'Field' }
75
+ width = { 12 }
76
+ isClearable = { true }
77
+ value = { fieldNames . find ( ( v ) => v . value === groupByField ) }
78
+ options = { fieldNames }
79
+ onChange = { ( value ) => onGroupByChange ( value ?. value ) }
80
+ />
81
+ </ InlineField >
82
+ </ InlineFieldRow >
83
+ </ >
84
+ ) }
85
+ { editorContext === 'variables' && (
86
+ < >
87
+ < InlineFieldRow >
88
+ < InlineField
89
+ label = "Variable text"
90
+ tooltip = {
91
+ < >
92
+ < p > { 'Field to use for the text label of a variable query.' } </ p >
93
+ < a
94
+ href = "https://github.com/marcusolsson/grafana-json-datasource/issues/79"
95
+ target = "_blank"
96
+ rel = "noreferrer"
97
+ >
98
+ Share feedback
99
+ </ a >
100
+ </ >
101
+ }
102
+ >
103
+ < Select
104
+ placeholder = { 'Field' }
105
+ width = { 12 }
106
+ isClearable = { true }
107
+ value = { fieldNames . find ( ( v ) => v . value === variableTextField ) }
108
+ options = { fieldNames }
109
+ onChange = { ( value ) => onVariableLabelChange ( value ?. value ) }
110
+ />
111
+ </ InlineField >
112
+ </ InlineFieldRow >
113
+ < InlineFieldRow >
114
+ < InlineField
115
+ label = "Variable value"
116
+ tooltip = {
117
+ < >
118
+ < p > { 'Field to use for the value of a variable query.' } </ p >
119
+ < a
120
+ href = "https://github.com/marcusolsson/grafana-json-datasource/issues/79"
121
+ target = "_blank"
122
+ rel = "noreferrer"
123
+ >
124
+ Share feedback
125
+ </ a >
126
+ </ >
127
+ }
128
+ >
129
+ < Select
130
+ placeholder = { 'Field' }
131
+ width = { 12 }
132
+ isClearable = { true }
133
+ value = { fieldNames . find ( ( v ) => v . value === variableValueField ) }
134
+ options = { fieldNames }
135
+ onChange = { ( value ) => onVariableValueChange ( value ?. value ) }
136
+ />
137
+ </ InlineField >
138
+ </ InlineFieldRow >
139
+ </ >
140
+ ) }
57
141
</ >
58
142
) ;
59
143
} ;
0 commit comments