2021-05-19 14:16:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								import  React ,  {  FunctionComponent ,  useMemo  }  from  'react' ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 21:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-19 14:16:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								import  {  SelectableValue  }  from  '@grafana/data' ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-15 22:12:26 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  {  EditorField ,  RadioButtonGroup  }  from  '@grafana/ui' ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 21:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-19 14:16:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								import  {  getAlignmentPickerData  }  from  '../functions' ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-22 21:33:13 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  {  MetricDescriptor ,  MetricKind ,  MetricQuery ,  PreprocessorType ,  ValueTypes  }  from  '../types' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-19 14:16:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								const  NONE_OPTION  =  {  label :  'None' ,  value : PreprocessorType.None  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								export  interface  Props  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  metricDescriptor? : MetricDescriptor ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  onChange :  ( query : MetricQuery )  = >  void ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  query : MetricQuery ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								export  const  Preprocessor : FunctionComponent < Props >  =  ( {  query ,  metricDescriptor ,  onChange  } )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const  options  =  useOptions ( metricDescriptor ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  return  ( 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-15 22:12:26 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    < EditorField 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-19 14:16:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								      label = "Pre-processing" 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-17 15:45:35 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      tooltip = "Preprocessing options are displayed when the selected metric has a metric kind of delta or cumulative. The specific options available are determined by the metric's value type. If you select 'Rate', data points are aligned and converted to a rate per time series. If you select 'Delta', data points are aligned by their delta (difference) per time series" 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-19 14:16:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      < RadioButtonGroup 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        onChange = { ( value : PreprocessorType )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          const  {  valueType ,  metricKind ,  perSeriesAligner : psa  }  =  query ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          const  {  perSeriesAligner  }  =  getAlignmentPickerData ( valueType ,  metricKind ,  psa ,  value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          onChange ( {  . . . query ,  preprocessor : value ,  perSeriesAligner  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        value = { query . preprocessor  ? ?  PreprocessorType . None } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        options = { options } 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-15 22:12:26 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								      / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    < / EditorField > 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-19 14:16:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								  ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-23 22:33:53 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								const  useOptions  =  ( metricDescriptor? : MetricDescriptor ) :  Array < SelectableValue < PreprocessorType > >  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-19 14:16:05 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								  const  metricKind  =  metricDescriptor ? . metricKind ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  const  valueType  =  metricDescriptor ? . valueType ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  return  useMemo ( ( )  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( ! metricKind  ||  metricKind  ===  MetricKind . GAUGE  ||  valueType  ===  ValueTypes . DISTRIBUTION )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      return  [ NONE_OPTION ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const  options  =  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      NONE_OPTION , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        label :  'Rate' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        value : PreprocessorType.Rate , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        description :  'Data points are aligned and converted to a rate per time series' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  metricKind  ===  MetricKind . CUMULATIVE 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      ?  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          . . . options , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            label :  'Delta' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            value : PreprocessorType.Delta , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            description :  'Data points are aligned by their delta (difference) per time series' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								          } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								      :  options ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  } ,  [ metricKind ,  valueType ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ;