@ -1,5 +1,5 @@
import { trim } from 'lodash' ;
import React , { useState } from 'react' ;
import React , { useMemo , use State } from 'react' ;
import { CoreApp , isValidDuration , SelectableValue } from '@grafana/data' ;
import { EditorField , EditorRow } from '@grafana/experimental' ;
@ -70,11 +70,18 @@ export const LokiQueryBuilderOptions = React.memo<Props>(
const queryType = query . queryType ? ? ( query . instant ? LokiQueryType.Instant : LokiQueryType.Range ) ;
const isLogQuery = isLogsQuery ( query . expr ) ;
const isValidStep = useMemo ( ( ) = > {
if ( ! query . step || isValidDuration ( query . step ) || ! isNaN ( Number ( query . step ) ) ) {
return true ;
}
return false ;
} , [ query . step ] ) ;
return (
< EditorRow >
< QueryOptionGroup
title = "Options"
collapsedInfo = { getCollapsedInfo ( query , queryType , maxLines , isLogQuery ) }
collapsedInfo = { getCollapsedInfo ( query , queryType , maxLines , isLogQuery , isValidStep ) }
queryStats = { queryStats }
>
< EditorField
@ -109,6 +116,8 @@ export const LokiQueryBuilderOptions = React.memo<Props>(
< EditorField
label = "Step"
tooltip = "Use the step parameter when making metric queries to Loki. If not filled, Grafana's calculated interval will be used. Example valid values: 1s, 5m, 10h, 1d."
invalid = { ! isValidStep }
error = { 'Invalid step. Example valid values: 1s, 5m, 10h, 1d.' }
>
< AutoSizeInput
className = "width-6"
@ -153,7 +162,13 @@ export const LokiQueryBuilderOptions = React.memo<Props>(
}
) ;
function getCollapsedInfo ( query : LokiQuery , queryType : LokiQueryType , maxLines : number , isLogQuery : boolean ) : string [ ] {
function getCollapsedInfo (
query : LokiQuery ,
queryType : LokiQueryType ,
maxLines : number ,
isLogQuery : boolean ,
isValidStep : boolean
) : string [ ] {
const queryTypeLabel = queryTypeOptions . find ( ( x ) = > x . value === queryType ) ;
const resolutionLabel = RESOLUTION_OPTIONS . find ( ( x ) = > x . value === ( query . resolution ? ? 1 ) ) ;
@ -175,7 +190,7 @@ function getCollapsedInfo(query: LokiQuery, queryType: LokiQueryType, maxLines:
if ( ! isLogQuery ) {
if ( query . step ) {
items . push ( ` Step: ${ query . step } ` ) ;
items . push ( ` Step: ${ isValidStep ? query . step : 'Invalid value' } ` ) ;
}
if ( query . resolution ) {