mirror of
				https://github.com/grafana/grafana.git
				synced 2025-02-25 18:55:37 -06:00 
			
		
		
		
	Tempo: Auto-clear results when changing query type (#44390)
* Auto-clear results when changing query type * Move clear results to function
This commit is contained in:
		@@ -86,6 +86,16 @@ class TempoQueryFieldComponent extends React.PureComponent<Props, State> {
 | 
			
		||||
    this.props.onRunQuery();
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  onClearResults = () => {
 | 
			
		||||
    // Run clear query to clear results
 | 
			
		||||
    const { onChange, query, onRunQuery } = this.props;
 | 
			
		||||
    onChange({
 | 
			
		||||
      ...query,
 | 
			
		||||
      queryType: 'clear',
 | 
			
		||||
    });
 | 
			
		||||
    onRunQuery();
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  render() {
 | 
			
		||||
    const { query, onChange, datasource } = this.props;
 | 
			
		||||
    // Find query field from linked datasource
 | 
			
		||||
@@ -123,12 +133,14 @@ class TempoQueryFieldComponent extends React.PureComponent<Props, State> {
 | 
			
		||||
            <RadioButtonGroup<TempoQueryType>
 | 
			
		||||
              options={queryTypeOptions}
 | 
			
		||||
              value={query.queryType}
 | 
			
		||||
              onChange={(v) =>
 | 
			
		||||
              onChange={(v) => {
 | 
			
		||||
                this.onClearResults();
 | 
			
		||||
 | 
			
		||||
                onChange({
 | 
			
		||||
                  ...query,
 | 
			
		||||
                  queryType: v,
 | 
			
		||||
                })
 | 
			
		||||
              }
 | 
			
		||||
                });
 | 
			
		||||
              }}
 | 
			
		||||
              size="md"
 | 
			
		||||
            />
 | 
			
		||||
          </InlineField>
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@ import {
 | 
			
		||||
import { NodeGraphOptions } from 'app/core/components/NodeGraphSettings';
 | 
			
		||||
 | 
			
		||||
// search = Loki search, nativeSearch = Tempo search for backwards compatibility
 | 
			
		||||
export type TempoQueryType = 'search' | 'traceId' | 'serviceMap' | 'upload' | 'nativeSearch';
 | 
			
		||||
export type TempoQueryType = 'search' | 'traceId' | 'serviceMap' | 'upload' | 'nativeSearch' | 'clear';
 | 
			
		||||
 | 
			
		||||
export interface TempoJsonData extends DataSourceJsonData {
 | 
			
		||||
  tracesToLogs?: TraceToLogsOptions;
 | 
			
		||||
@@ -90,6 +90,10 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
 | 
			
		||||
    const filteredTargets = options.targets.filter((target) => !target.hide);
 | 
			
		||||
    const targets: { [type: string]: TempoQuery[] } = groupBy(filteredTargets, (t) => t.queryType || 'traceId');
 | 
			
		||||
 | 
			
		||||
    if (targets.clear) {
 | 
			
		||||
      return of({ data: [], state: LoadingState.Done });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Run search queries on linked datasource
 | 
			
		||||
    if (this.tracesToLogs?.datasourceUid && targets.search?.length > 0) {
 | 
			
		||||
      const dsSrv = getDatasourceSrv();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user