mirror of
https://github.com/grafana/grafana.git
synced 2025-09-22 00:02:53 +08:00
Chore/Tech debt: Remove (most) instances of $q angular service use (#20668)
* Chore/Tech debt: Remove (most) instances of $q angular service use Removes instances where the angular $q service is used and replaces it with native Promises.
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import ResponseParser from './response_parser';
|
||||
import PostgresQuery from 'app/plugins/datasource/postgres/postgres_query';
|
||||
import { IQService } from 'angular';
|
||||
import { BackendSrv } from 'app/core/services/backend_srv';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
@ -21,14 +20,13 @@ export class PostgresDatasource {
|
||||
constructor(
|
||||
instanceSettings: { name: any; id?: any; jsonData?: any },
|
||||
private backendSrv: BackendSrv,
|
||||
private $q: IQService,
|
||||
private templateSrv: TemplateSrv,
|
||||
private timeSrv: TimeSrv
|
||||
) {
|
||||
this.name = instanceSettings.name;
|
||||
this.id = instanceSettings.id;
|
||||
this.jsonData = instanceSettings.jsonData;
|
||||
this.responseParser = new ResponseParser(this.$q);
|
||||
this.responseParser = new ResponseParser();
|
||||
this.queryModel = new PostgresQuery({});
|
||||
this.interval = (instanceSettings.jsonData || {}).timeInterval || '1m';
|
||||
}
|
||||
@ -84,7 +82,7 @@ export class PostgresDatasource {
|
||||
});
|
||||
|
||||
if (queries.length === 0) {
|
||||
return this.$q.when({ data: [] });
|
||||
return Promise.resolve({ data: [] });
|
||||
}
|
||||
|
||||
return this.backendSrv
|
||||
@ -102,7 +100,7 @@ export class PostgresDatasource {
|
||||
|
||||
annotationQuery(options: any) {
|
||||
if (!options.annotation.rawQuery) {
|
||||
return this.$q.reject({
|
||||
return Promise.reject({
|
||||
message: 'Query missing in annotation definition',
|
||||
});
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import { QueryCtrl } from 'app/plugins/sdk';
|
||||
import { SqlPart } from 'app/core/components/sql_part/sql_part';
|
||||
import PostgresQuery from './postgres_query';
|
||||
import sqlPart from './sql_part';
|
||||
import { auto, IQService } from 'angular';
|
||||
import { auto } from 'angular';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { CoreEvents } from 'app/types';
|
||||
import { PanelEvents } from '@grafana/data';
|
||||
@ -48,7 +48,6 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
$scope: any,
|
||||
$injector: auto.IInjectorService,
|
||||
private templateSrv: TemplateSrv,
|
||||
private $q: IQService,
|
||||
private uiSegmentSrv: any
|
||||
) {
|
||||
super($scope, $injector);
|
||||
@ -248,7 +247,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
});
|
||||
|
||||
this.$q.all([task1, task2]).then(() => {
|
||||
Promise.all([task1, task2]).then(() => {
|
||||
this.updateRawSqlAndRefresh();
|
||||
});
|
||||
}
|
||||
@ -481,7 +480,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
break;
|
||||
}
|
||||
case 'get-part-actions': {
|
||||
return this.$q.when([{ text: 'Remove', value: 'remove-part' }]);
|
||||
return Promise.resolve([{ text: 'Remove', value: 'remove-part' }]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -505,7 +504,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
break;
|
||||
}
|
||||
case 'get-part-actions': {
|
||||
return this.$q.when([{ text: 'Remove', value: 'remove-part' }]);
|
||||
return Promise.resolve([{ text: 'Remove', value: 'remove-part' }]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -568,7 +567,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
case 'right':
|
||||
if (['int4', 'int8', 'float4', 'float8', 'timestamp', 'timestamptz'].indexOf(part.datatype) > -1) {
|
||||
// don't do value lookups for numerical fields
|
||||
return this.$q.when([]);
|
||||
return Promise.resolve([]);
|
||||
} else {
|
||||
return this.datasource
|
||||
.metricFindQuery(this.metaBuilder.buildValueQuery(part.params[0]))
|
||||
@ -583,9 +582,9 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
.catch(this.handleQueryError.bind(this));
|
||||
}
|
||||
case 'op':
|
||||
return this.$q.when(this.uiSegmentSrv.newOperators(this.metaBuilder.getOperators(part.datatype)));
|
||||
return Promise.resolve(this.uiSegmentSrv.newOperators(this.metaBuilder.getOperators(part.datatype)));
|
||||
default:
|
||||
return this.$q.when([]);
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
}
|
||||
case 'part-param-changed': {
|
||||
@ -606,7 +605,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
break;
|
||||
}
|
||||
case 'get-part-actions': {
|
||||
return this.$q.when([{ text: 'Remove', value: 'remove-part' }]);
|
||||
return Promise.resolve([{ text: 'Remove', value: 'remove-part' }]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -619,7 +618,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__timeFilter' }));
|
||||
}
|
||||
options.push(this.uiSegmentSrv.newSegment({ type: 'expression', value: 'Expression' }));
|
||||
return this.$q.when(options);
|
||||
return Promise.resolve(options);
|
||||
}
|
||||
|
||||
addWhereAction(part: any, index: any) {
|
||||
|
@ -1,9 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import { IQService } from 'angular';
|
||||
|
||||
export default class ResponseParser {
|
||||
constructor(private $q: IQService) {}
|
||||
|
||||
processQueryResult(res: any) {
|
||||
const data: any[] = [];
|
||||
|
||||
@ -125,7 +122,7 @@ export default class ResponseParser {
|
||||
}
|
||||
|
||||
if (timeColumnIndex === -1) {
|
||||
return this.$q.reject({
|
||||
return Promise.reject({
|
||||
message: 'Missing mandatory time column in annotation query.',
|
||||
});
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ import { PostgresDatasource } from '../datasource';
|
||||
import { CustomVariable } from 'app/features/templating/custom_variable';
|
||||
import { dateTime, toUtc } from '@grafana/data';
|
||||
import { BackendSrv } from 'app/core/services/backend_srv';
|
||||
import { IQService } from 'angular';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
|
||||
describe('PostgreSQLDatasource', () => {
|
||||
@ -26,13 +25,7 @@ describe('PostgreSQLDatasource', () => {
|
||||
} as any;
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.ds = new PostgresDatasource(
|
||||
instanceSettings,
|
||||
backendSrv as BackendSrv,
|
||||
{} as IQService,
|
||||
templateSrv,
|
||||
ctx.timeSrvMock
|
||||
);
|
||||
ctx.ds = new PostgresDatasource(instanceSettings, backendSrv as BackendSrv, templateSrv, ctx.timeSrvMock);
|
||||
});
|
||||
|
||||
describe('When performing annotationQuery', () => {
|
||||
|
Reference in New Issue
Block a user