Types: Adds type safety to appEvents (#19418)

* Types: Add type safety to appEvents
This commit is contained in:
kay delaney
2019-10-14 09:27:47 +01:00
committed by GitHub
parent e7c37cc316
commit 99411bf37a
138 changed files with 991 additions and 508 deletions

View File

@@ -2,10 +2,12 @@ import coreModule from 'app/core/core_module';
import _ from 'lodash';
import * as queryDef from './query_def';
import { IQService } from 'angular';
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
import { CoreEvents } from 'app/types';
export class ElasticBucketAggCtrl {
/** @ngInject */
constructor($scope: any, uiSegmentSrv: any, $q: IQService, $rootScope: any) {
constructor($scope: any, uiSegmentSrv: any, $q: IQService, $rootScope: GrafanaRootScope) {
const bucketAggs = $scope.target.bucketAggs;
$scope.orderByOptions = [];
@@ -23,7 +25,7 @@ export class ElasticBucketAggCtrl {
};
$rootScope.onAppEvent(
'elastic-query-updated',
CoreEvents.elasticQueryUpdated,
() => {
$scope.validateModel();
},

View File

@@ -3,10 +3,12 @@ import _ from 'lodash';
import * as queryDef from './query_def';
import { ElasticsearchAggregation } from './types';
import { IQService } from 'angular';
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
import { CoreEvents } from 'app/types';
export class ElasticMetricAggCtrl {
/** @ngInject */
constructor($scope: any, uiSegmentSrv: any, $q: IQService, $rootScope: any) {
constructor($scope: any, uiSegmentSrv: any, $q: IQService, $rootScope: GrafanaRootScope) {
const metricAggs: ElasticsearchAggregation[] = $scope.target.metrics;
$scope.metricAggTypes = queryDef.getMetricAggTypes($scope.esVersion);
$scope.extendedStats = queryDef.extendedStats;
@@ -24,7 +26,7 @@ export class ElasticMetricAggCtrl {
};
$rootScope.onAppEvent(
'elastic-query-updated',
CoreEvents.elasticQueryUpdated,
() => {
$scope.index = _.indexOf(metricAggs, $scope.agg);
$scope.updatePipelineAggOptions();

View File

@@ -7,6 +7,8 @@ import _ from 'lodash';
import * as queryDef from './query_def';
import { QueryCtrl } from 'app/plugins/sdk';
import { ElasticsearchAggregation } from './types';
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
import { CoreEvents } from 'app/types';
export class ElasticQueryCtrl extends QueryCtrl {
static templateUrl = 'partials/query.editor.html';
@@ -15,7 +17,12 @@ export class ElasticQueryCtrl extends QueryCtrl {
rawQueryOld: string;
/** @ngInject */
constructor($scope: any, $injector: auto.IInjectorService, private $rootScope: any, private uiSegmentSrv: any) {
constructor(
$scope: any,
$injector: auto.IInjectorService,
private $rootScope: GrafanaRootScope,
private uiSegmentSrv: any
) {
super($scope, $injector);
this.esVersion = this.datasource.esVersion;
@@ -50,7 +57,7 @@ export class ElasticQueryCtrl extends QueryCtrl {
}
this.rawQueryOld = newJson;
this.$rootScope.appEvent('elastic-query-updated');
this.$rootScope.appEvent(CoreEvents.elasticQueryUpdated);
}
getCollapsedText() {

View File

@@ -14,7 +14,7 @@ describe('ElasticDatasource', function(this: any) {
datasourceRequest: jest.fn(),
};
const $rootScope: any = {
const $rootScope = {
$on: jest.fn(),
appEvent: jest.fn(),
};