Fix default query type for new queries if data source is not default

This commit is contained in:
Alexander Zobnin
2021-08-05 18:17:27 +03:00
parent 62f38df28a
commit c3ce8824af

View File

@@ -4,7 +4,7 @@ import * as c from './constants';
import * as utils from './utils';
import * as metricFunctions from './metricFunctions';
import * as migrations from './migrations';
import { ShowProblemTypes, ZabbixMetricsQuery } from './types';
import { ShowProblemTypes } from './types';
import { CURRENT_SCHEMA_VERSION } from '../panel-triggers/migrations';
import { getTemplateSrv, TemplateSrv } from '@grafana/runtime';
@@ -218,6 +218,7 @@ export class ZabbixQueryController extends QueryCtrl {
// Load default values
const targetDefaults = getTargetDefaults();
_.defaultsDeep(target, targetDefaults);
this.initDefaultQueryMode(target);
if (this.panel.type === c.ZABBIX_PROBLEMS_PANEL_ID) {
target.queryType = c.MODE_PROBLEMS;
@@ -276,6 +277,17 @@ export class ZabbixQueryController extends QueryCtrl {
return Promise.all(promises);
}
initDefaultQueryMode(target) {
if (!(target.queryType === c.MODE_METRICS ||
target.queryType === c.MODE_TEXT ||
target.queryType === c.MODE_ITSERVICE ||
target.queryType === c.MODE_ITEMID ||
target.queryType === c.MODE_TRIGGERS ||
target.queryType === c.MODE_PROBLEMS)) {
target.queryType = c.MODE_METRICS;
}
}
// Get list of metric names for bs-typeahead directive
getMetricNames(metricList, addAllValue) {
const metrics = _.uniq(_.map(this.metric[metricList], 'name'));