2020-02-06 12:37:30 +00:00
// Libraries
import React , { memo } from 'react' ;
2020-09-28 21:25:16 +02:00
import { css , cx } from 'emotion' ;
2020-02-06 12:37:30 +00:00
// Types
2020-09-28 21:25:16 +02:00
import { InlineFormLabel , RadioButtonGroup } from '@grafana/ui' ;
2020-02-06 12:37:30 +00:00
export interface PromExploreExtraFieldProps {
2020-09-28 21:25:16 +02:00
queryType : string ;
stepValue : string ;
onStepChange : ( e : React.SyntheticEvent < HTMLInputElement > ) = > void ;
2020-02-06 12:37:30 +00:00
onKeyDownFunc : ( e : React.KeyboardEvent < HTMLInputElement > ) = > void ;
2020-09-28 21:25:16 +02:00
onQueryTypeChange : ( value : string ) = > void ;
2020-02-06 12:37:30 +00:00
}
2020-09-28 21:25:16 +02:00
export const PromExploreExtraField : React.FC < PromExploreExtraFieldProps > = memo (
( { queryType , stepValue , onStepChange , onQueryTypeChange , onKeyDownFunc } ) = > {
const rangeOptions = [
{ value : 'range' , label : 'Range' } ,
{ value : 'instant' , label : 'Instant' } ,
{ value : 'both' , label : 'Both' } ,
] ;
2020-02-06 12:37:30 +00:00
2020-09-28 21:25:16 +02:00
return (
< div aria-label = "Prometheus extra field" className = "gf-form-inline" >
2020-11-20 11:12:34 +01:00
{ /*Query type field*/ }
2020-09-28 21:25:16 +02:00
< div
data - testid = "queryTypeField"
className = { cx (
'gf-form explore-input-margin' ,
css `
flex - wrap : nowrap ;
`
) }
aria - label = "Query type field"
>
2020-11-20 12:08:10 +01:00
< InlineFormLabel
width = "auto"
tooltip = "Choose the type of query you would like to run. An instant query queries against a single point in time. A range query queries over a range of time. With both, you'll run two queries - one instant and one range. "
>
Query type
< / InlineFormLabel >
2020-02-06 12:37:30 +00:00
2020-09-28 21:25:16 +02:00
< RadioButtonGroup options = { rangeOptions } value = { queryType } onChange = { onQueryTypeChange } / >
< / div >
{ /*Step field*/ }
< div
data - testid = "stepField"
className = { cx (
'gf-form' ,
css `
flex - wrap : nowrap ;
`
) }
aria - label = "Step field"
>
< InlineFormLabel
width = { 5 }
tooltip = {
'Time units can be used here, for example: 5s, 1m, 3h, 1d, 1y (Default if no unit is specified: s)'
}
>
Step
< / InlineFormLabel >
< input
type = { 'text' }
className = "gf-form-input width-4"
placeholder = { 'auto' }
onChange = { onStepChange }
onKeyDown = { onKeyDownFunc }
value = { stepValue }
/ >
< / div >
< / div >
) ;
}
) ;