@ -8,7 +8,6 @@ import Highlighter from 'react-highlight-words';
import { GrafanaTheme2 , SelectableValue , toOption } from '@grafana/data' ;
import { selectors } from '@grafana/e2e-selectors' ;
import { EditorField , EditorFieldGroup } from '@grafana/experimental' ;
import { config } from '@grafana/runtime' ;
import {
AsyncSelect ,
Button ,
@ -67,8 +66,6 @@ export function MetricSelect({
resultsTruncated? : boolean ;
} > ( { } ) ;
const prometheusMetricEncyclopedia = config . featureToggles . prometheusMetricEncyclopedia ;
const metricsModalOption : SelectableValue [ ] = [
{
value : 'BrowseMetrics' ,
@ -77,33 +74,25 @@ export function MetricSelect({
} ,
] ;
const customFilterOption = useCallback (
( option : SelectableValue , searchQuery : string ) = > {
const label = option . label ? ? option . value ;
if ( ! label ) {
return false ;
}
// custom value is not a string label but a react node
if ( ! label . toLowerCase ) {
return true ;
}
const searchWords = searchQuery . split ( splitSeparator ) ;
const customFilterOption = useCallback ( ( option : SelectableValue , searchQuery : string ) = > {
const label = option . label ? ? option . value ;
if ( ! label ) {
return false ;
}
return searchWords . reduce ( ( acc , cur ) = > {
const matcheSearch = label . toLowerCase ( ) . includes ( cur . toLowerCase ( ) ) ;
// custom value is not a string label but a react node
if ( ! label . toLowerCase ) {
return true ;
}
let browseOption = false ;
if ( prometheusMetricEncyclopedia ) {
browseOption = label === 'Metrics explorer' ;
}
const searchWords = searchQuery . split ( splitSeparator ) ;
return acc && ( matcheSearch || browseOption ) ;
} , true ) ;
} ,
[ prometheusMetricEncyclopedia ]
) ;
return searchWords . reduce ( ( acc , cur ) = > {
const matcheSearch = label . toLowerCase ( ) . includes ( cur . toLowerCase ( ) ) ;
const browseOption = label === 'Metrics explorer' ;
return acc && ( matcheSearch || browseOption ) ;
} , true ) ;
} , [ ] ) ;
const formatOptionLabel = useCallback (
( option : SelectableValue , meta : FormatOptionLabelMeta < any > ) = > {
@ -159,11 +148,7 @@ export function MetricSelect({
} ;
} ) ;
if ( prometheusMetricEncyclopedia ) {
return [ . . . metricsModalOption , . . . resultsOptions ] ;
} else {
return resultsOptions ;
}
return [ . . . metricsModalOption , . . . resultsOptions ] ;
} ) ;
} ;
@ -286,22 +271,14 @@ export function MetricSelect({
truncateResult ( metrics ) ;
}
if ( prometheusMetricEncyclopedia ) {
setState ( {
// add the modal button option to the options
metrics : [ . . . metricsModalOption , . . . metrics ] ,
isLoading : undefined ,
// pass the initial metrics into the metrics explorer
initialMetrics : initialMetrics ,
resultsTruncated : resultsLength > metrics . length ,
} ) ;
} else {
setState ( {
metrics ,
isLoading : undefined ,
resultsTruncated : resultsLength > metrics . length ,
} ) ;
}
setState ( {
// add the modal button option to the options
metrics : [ . . . metricsModalOption , . . . metrics ] ,
isLoading : undefined ,
// pass the initial metrics into the metrics explorer
initialMetrics : initialMetrics ,
resultsTruncated : resultsLength > metrics . length ,
} ) ;
} }
loadOptions = { metricLookupDisabled ? metricLookupDisabledSearch : debouncedSearch }
isLoading = { state . isLoading }
@ -309,8 +286,8 @@ export function MetricSelect({
onChange = { ( input ) = > {
const value = input ? . value ;
if ( value ) {
// if there is no metric and the m.e. is enabled , open the modal
if ( prometheusMetricEncyclopedia && value === 'BrowseMetrics' ) {
// if there is no metric and the value is the custom m.e. option , open the modal
if ( value === 'BrowseMetrics' ) {
tracking ( 'grafana_prometheus_metric_encyclopedia_open' , null , '' , query ) ;
setState ( { . . . state , metricsModalOpen : true } ) ;
} else {
@ -320,9 +297,7 @@ export function MetricSelect({
onChange ( { . . . query , metric : '' } ) ;
}
} }
components = {
prometheusMetricEncyclopedia ? { Option : CustomOption , MenuList : CustomMenu } : { MenuList : CustomMenu }
}
components = { { Option : CustomOption , MenuList : CustomMenu } }
onBlur = { onBlur }
/ >
) ;
@ -330,7 +305,7 @@ export function MetricSelect({
return (
< >
{ prometheusMetricEncyclopedia && ! datasource . lookupsDisabled && state . metricsModalOpen && (
{ ! datasource . lookupsDisabled && state . metricsModalOpen && (
< MetricsModal
datasource = { datasource }
isOpen = { state . metricsModalOpen }