1
1
import defaults from 'lodash/defaults' ;
2
- import React , { ChangeEvent } from 'react' ;
3
- import { Icon , InlineFormLabel , Segment } from '@grafana/ui' ;
2
+ import React from 'react' ;
3
+ import { Icon , InlineFieldRow , InlineField , Segment , Input } from '@grafana/ui' ;
4
4
import { QueryEditorProps } from '@grafana/data' ;
5
5
import { DataSource } from '../datasource' ;
6
6
import { JsonApiDataSourceOptions , JsonApiQuery , defaultQuery } from '../types' ;
7
7
import { JsonPathQueryField } from './JsonPathQueryField' ;
8
- import { cx } from 'emotion' ;
9
8
10
9
type Props = QueryEditorProps < DataSource , JsonApiQuery , JsonApiDataSourceOptions > ;
11
10
12
11
export const QueryEditor : React . FC < Props > = ( { onRunQuery, onChange, query } ) => {
13
12
const { fields } = defaults ( query , defaultQuery ) ;
14
13
15
- const onFieldNameChange = ( i : number ) => ( event : ChangeEvent < HTMLInputElement > ) => {
16
- fields [ i ] = { ...fields [ i ] , name : event . target . value } ;
17
- onChange ( { ...query , fields } ) ;
18
- onRunQuery ( ) ;
19
- } ;
20
-
21
14
const onChangePath = ( i : number ) => ( e : string ) => {
22
15
fields [ i ] = { ...fields [ i ] , jsonPath : e } ;
23
16
onChange ( { ...query , fields } ) ;
@@ -40,76 +33,59 @@ export const QueryEditor: React.FC<Props> = ({ onRunQuery, onChange, query }) =>
40
33
41
34
return (
42
35
< >
43
- < div className = "gf-form-inline" >
44
- < InlineFormLabel
45
- width = { 7 }
46
- className = "query-keyword"
36
+ < InlineFieldRow >
37
+ < InlineField
38
+ label = "Cache Time"
47
39
tooltip = "Time in seconds that the response will be cached in Grafana after receiving it."
48
40
>
49
- Cache Time
50
- </ InlineFormLabel >
51
- < Segment
52
- value = { { label : formatCacheTimeLabel ( query . cacheDurationSeconds ) , value : query . cacheDurationSeconds } }
53
- options = { [ 0 , 5 , 10 , 30 , 60 , 60 * 2 , 60 * 5 , 60 * 10 , 60 * 30 , 3600 , 3600 * 2 , 3600 * 5 ] . map ( value => ( {
54
- label : formatCacheTimeLabel ( value ) ,
55
- value,
56
- description : value ? '' : 'Response is not cached at all' ,
57
- } ) ) }
58
- onChange = { ( { value } ) => onChange ( { ...query , cacheDurationSeconds : value ! } ) }
59
- />
60
- < div className = "gf-form gf-form--grow" >
61
- < div className = "gf-form-label gf-form-label--grow" />
62
- </ div >
63
- </ div >
64
- < div className = "gf-form" >
65
- < InlineFormLabel
66
- width = { 12 }
67
- className = "query-keyword"
41
+ < Segment
42
+ value = { { label : formatCacheTimeLabel ( query . cacheDurationSeconds ) , value : query . cacheDurationSeconds } }
43
+ options = { [ 0 , 5 , 10 , 30 , 60 , 60 * 2 , 60 * 5 , 60 * 10 , 60 * 30 , 3600 , 3600 * 2 , 3600 * 5 ] . map ( value => ( {
44
+ label : formatCacheTimeLabel ( value ) ,
45
+ value,
46
+ description : value ? '' : 'Response is not cached at all' ,
47
+ } ) ) }
48
+ onChange = { ( { value } ) => onChange ( { ...query , cacheDurationSeconds : value ! } ) }
49
+ />
50
+ </ InlineField >
51
+ </ InlineFieldRow >
52
+ < InlineFieldRow >
53
+ < InlineField
54
+ label = "Custom query parameters"
68
55
tooltip = "Add custom parameters to your queries. Any parameters you add here overrides the custom parameters that have been configured by the data source."
56
+ grow
69
57
>
70
- Custom query parameters
71
- </ InlineFormLabel >
72
- < input
73
- className = "gf-form-input"
74
- placeholder = "page=1& limit = 100 "
75
- value = { query . queryParams }
76
- onChange = { e => onChange ( { ...query , queryParams : e . currentTarget . value } ) }
77
- > </ input >
78
- </ div >
58
+ < Input
59
+ placeholder = "page=1& limit = 100 "
60
+ value = { query . queryParams }
61
+ onChange = { e => onChange ( { ...query , queryParams : e . currentTarget . value } ) }
62
+ />
63
+ </ InlineField >
64
+ </ InlineFieldRow >
79
65
{ fields
80
66
? fields . map ( ( field , index ) => (
81
- < div key = { index } className = "gf-form" >
82
- < InlineFormLabel
83
- width = { 7 }
84
- className = "query-keyword"
67
+ < InlineFieldRow key = { index } >
68
+ < InlineField
69
+ label = "Query"
85
70
tooltip = {
86
71
< div >
87
72
A < a href = "https://goessner.net/articles/JsonPath/" > JSON Path</ a > query that selects one or more
88
73
values from a JSON object.
89
74
</ div >
90
75
}
76
+ grow
91
77
>
92
- Query
93
- </ InlineFormLabel >
94
- < JsonPathQueryField onBlur = { onRunQuery } onChange = { onChangePath ( index ) } query = { field . jsonPath } />
95
- < InlineFormLabel width = { 3 } className = "query-keyword" >
96
- Alias
97
- </ InlineFormLabel >
98
- < input
99
- className = "gf-form-input width-14"
100
- value = { field . name || '' }
101
- onChange = { onFieldNameChange ( index ) }
102
- > </ input >
103
-
104
- < a className = { cx ( 'gf-form-label' , 'gf-form-label--grow' ) } onClick = { addField ( index ) } >
78
+ < JsonPathQueryField onBlur = { onRunQuery } onChange = { onChangePath ( index ) } query = { field . jsonPath } />
79
+ </ InlineField >
80
+ < a className = "gf-form-label" onClick = { addField ( index ) } >
105
81
< Icon name = "plus" />
106
82
</ a >
107
83
{ fields . length > 1 ? (
108
- < a className = { cx ( ' gf-form-label' , 'gf-form-label--grow' ) } onClick = { removeField ( index ) } >
84
+ < a className = " gf-form-label" onClick = { removeField ( index ) } >
109
85
< Icon name = "minus" />
110
86
</ a >
111
87
) : null }
112
- </ div >
88
+ </ InlineFieldRow >
113
89
) )
114
90
: null }
115
91
</ >
0 commit comments