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:
Connor Lindsey 2022-01-28 07:49:43 -07:00 committed by GitHub
parent 919c451156
commit 45a435ad78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -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>

View File

@ -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();