Migrate dataSourceSrv to getDataSourceSrv
This commit is contained in:
@@ -4,15 +4,20 @@ import {TriggerPanelCtrl} from '../triggers_panel_ctrl';
|
||||
import {DEFAULT_TARGET, DEFAULT_SEVERITY, PANEL_DEFAULTS} from '../triggers_panel_ctrl';
|
||||
import {CURRENT_SCHEMA_VERSION} from '../migrations';
|
||||
|
||||
jest.mock('@grafana/runtime', () => {
|
||||
return {
|
||||
getDataSourceSrv: () => ({
|
||||
getMetricSources: () => {
|
||||
return [{ meta: {id: 'alexanderzobnin-zabbix-datasource'}, value: {}, name: 'zabbix_default' }];
|
||||
},
|
||||
get: () => Promise.resolve({})
|
||||
}),
|
||||
};
|
||||
}, {virtual: true});
|
||||
|
||||
describe('Triggers Panel schema migration', () => {
|
||||
let ctx: any = {};
|
||||
let updatePanelCtrl;
|
||||
const datasourceSrvMock = {
|
||||
getMetricSources: () => {
|
||||
return [{ meta: {id: 'alexanderzobnin-zabbix-datasource'}, value: {}, name: 'zabbix_default' }];
|
||||
},
|
||||
get: () => Promise.resolve({})
|
||||
};
|
||||
|
||||
const timeoutMock = () => {};
|
||||
|
||||
@@ -43,7 +48,7 @@ describe('Triggers Panel schema migration', () => {
|
||||
}
|
||||
};
|
||||
|
||||
updatePanelCtrl = (scope) => new TriggerPanelCtrl(scope, {}, timeoutMock, datasourceSrvMock, {}, {}, {}, mocks.timeSrvMock);
|
||||
updatePanelCtrl = (scope) => new TriggerPanelCtrl(scope, {}, timeoutMock, {}, {}, {}, mocks.timeSrvMock);
|
||||
});
|
||||
|
||||
it('should update old panel schema', () => {
|
||||
|
||||
@@ -4,9 +4,16 @@ import {TriggerPanelCtrl} from '../triggers_panel_ctrl';
|
||||
import {PANEL_DEFAULTS, DEFAULT_TARGET} from '../triggers_panel_ctrl';
|
||||
// import { create } from 'domain';
|
||||
|
||||
let datasourceSrvMock, zabbixDSMock;
|
||||
|
||||
jest.mock('@grafana/runtime', () => {
|
||||
return {
|
||||
getDataSourceSrv: () => datasourceSrvMock,
|
||||
};
|
||||
}, {virtual: true});
|
||||
|
||||
describe('TriggerPanelCtrl', () => {
|
||||
let ctx: any = {};
|
||||
let datasourceSrvMock, zabbixDSMock;
|
||||
const timeoutMock = () => {};
|
||||
let createPanelCtrl;
|
||||
|
||||
@@ -31,7 +38,8 @@ describe('TriggerPanelCtrl', () => {
|
||||
},
|
||||
get: () => Promise.resolve(zabbixDSMock)
|
||||
};
|
||||
createPanelCtrl = () => new TriggerPanelCtrl(ctx.scope, {}, timeoutMock, datasourceSrvMock, {}, {}, {}, mocks.timeSrvMock);
|
||||
|
||||
createPanelCtrl = () => new TriggerPanelCtrl(ctx.scope, {}, timeoutMock, {}, {}, {}, mocks.timeSrvMock);
|
||||
|
||||
const getTriggersResp = [
|
||||
[
|
||||
|
||||
@@ -2,6 +2,7 @@ import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import _ from 'lodash';
|
||||
import moment from 'moment';
|
||||
import { getDataSourceSrv } from '@grafana/runtime';
|
||||
import * as dateMath from 'grafana/app/core/utils/datemath';
|
||||
import * as utils from '../datasource-zabbix/utils';
|
||||
import { PanelCtrl } from 'grafana/app/plugins/sdk';
|
||||
@@ -96,9 +97,8 @@ const triggerStatusMap = {
|
||||
export class TriggerPanelCtrl extends PanelCtrl {
|
||||
|
||||
/** @ngInject */
|
||||
constructor($scope, $injector, $timeout, datasourceSrv, templateSrv, contextSrv, dashboardSrv, timeSrv) {
|
||||
constructor($scope, $injector, $timeout, templateSrv, contextSrv, dashboardSrv, timeSrv) {
|
||||
super($scope, $injector);
|
||||
this.datasourceSrv = datasourceSrv;
|
||||
this.templateSrv = templateSrv;
|
||||
this.contextSrv = contextSrv;
|
||||
this.dashboardSrv = dashboardSrv;
|
||||
@@ -151,7 +151,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
|
||||
const targetDatasources = _.compact(this.panel.targets.map(target => target.datasource));
|
||||
let promises = targetDatasources.map(ds => {
|
||||
// Load datasource
|
||||
return this.datasourceSrv.get(ds)
|
||||
return getDataSourceSrv().get(ds)
|
||||
.then(datasource => {
|
||||
this.datasources[ds] = datasource;
|
||||
return datasource;
|
||||
@@ -161,7 +161,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
|
||||
}
|
||||
|
||||
getZabbixDataSources() {
|
||||
return _.filter(this.datasourceSrv.getMetricSources(), datasource => {
|
||||
return _.filter(getDataSourceSrv().getMetricSources(), datasource => {
|
||||
return datasource.meta.id === ZABBIX_DS_ID && datasource.value;
|
||||
});
|
||||
}
|
||||
@@ -251,7 +251,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
|
||||
const ds = target.datasource;
|
||||
let proxies;
|
||||
let showAckButton = true;
|
||||
return this.datasourceSrv.get(ds)
|
||||
return getDataSourceSrv().get(ds)
|
||||
.then(datasource => {
|
||||
const zabbix = datasource.zabbix;
|
||||
const showEvents = this.panel.showEvents.value;
|
||||
@@ -524,7 +524,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
|
||||
const triggerids = [problem.triggerid];
|
||||
const timeFrom = Math.ceil(dateMath.parse(this.range.from) / 1000);
|
||||
const timeTo = Math.ceil(dateMath.parse(this.range.to) / 1000);
|
||||
return this.datasourceSrv.get(problem.datasource)
|
||||
return getDataSourceSrv().get(problem.datasource)
|
||||
.then(datasource => {
|
||||
return datasource.zabbix.getEvents(triggerids, timeFrom, timeTo, [0, 1], PROBLEM_EVENTS_LIMIT);
|
||||
});
|
||||
@@ -535,7 +535,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
const eventids = [problem.lastEvent.eventid];
|
||||
return this.datasourceSrv.get(problem.datasource)
|
||||
return getDataSourceSrv().get(problem.datasource)
|
||||
.then(datasource => {
|
||||
return datasource.zabbix.getEventAlerts(eventids);
|
||||
});
|
||||
@@ -622,7 +622,7 @@ export class TriggerPanelCtrl extends PanelCtrl {
|
||||
let eventid = trigger.lastEvent ? trigger.lastEvent.eventid : null;
|
||||
let grafana_user = this.contextSrv.user.name;
|
||||
let ack_message = grafana_user + ' (Grafana): ' + message;
|
||||
return this.datasourceSrv.get(trigger.datasource)
|
||||
return getDataSourceSrv().get(trigger.datasource)
|
||||
.then(datasource => {
|
||||
const userIsEditor = this.contextSrv.isEditor || this.contextSrv.isGrafanaAdmin;
|
||||
if (datasource.disableReadOnlyUsersAck && !userIsEditor) {
|
||||
|
||||
Reference in New Issue
Block a user