mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Types: Adds type safety to appEvents (#19418)
* Types: Add type safety to appEvents
This commit is contained in:
@@ -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();
|
||||
},
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('ElasticDatasource', function(this: any) {
|
||||
datasourceRequest: jest.fn(),
|
||||
};
|
||||
|
||||
const $rootScope: any = {
|
||||
const $rootScope = {
|
||||
$on: jest.fn(),
|
||||
appEvent: jest.fn(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user