Commit 375dc333 by Tobias Skarhed Committed by Torkel Ödegaard

Typescript: Reduce implicit any errors (#17550)

* Fix types on linkSrv

* Lower err count, shoot down some errs, add type pkg

* Fix changes and add test

* Update public/app/features/panel/panel_ctrl.ts

Co-Authored-By: Hugo Häggmark <hugo.haggmark@gmail.com>

* Update public/app/features/panel/panel_ctrl.ts

Co-Authored-By: Hugo Häggmark <hugo.haggmark@gmail.com>

* Update public/app/features/panel/panellinks/link_srv.ts

Co-Authored-By: Hugo Häggmark <hugo.haggmark@gmail.com>

* Update public/app/features/panel/panel_ctrl.ts

Co-Authored-By: Hugo Häggmark <hugo.haggmark@gmail.com>

* Fix last types to compile

* Fix formatting issue

* Update public/app/features/panel/panel_ctrl.ts

Co-Authored-By: Hugo Häggmark <hugo.haggmark@gmail.com>
parent 74829f48
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
"@types/react-transition-group": "2.0.16", "@types/react-transition-group": "2.0.16",
"@types/react-virtualized": "9.18.12", "@types/react-virtualized": "9.18.12",
"@types/react-window": "1.7.0", "@types/react-window": "1.7.0",
"@types/remarkable": "1.7.4",
"angular-mocks": "1.6.6", "angular-mocks": "1.6.6",
"autoprefixer": "9.5.0", "autoprefixer": "9.5.0",
"axios": "0.19.0", "axios": "0.19.0",
......
import config from 'app/core/config'; import config from 'app/core/config';
import { LinkSrv } from 'app/features/panel/panellinks/link_srv'; import { LinkSrv } from 'app/features/panel/panellinks/link_srv';
import { ShareModalCtrl } from './ShareModalCtrl'; import { ShareModalCtrl } from './ShareModalCtrl';
import { TemplateSrv } from 'app/features/templating/template_srv';
describe('ShareModalCtrl', () => { describe('ShareModalCtrl', () => {
const ctx = { const ctx = {
...@@ -49,7 +50,7 @@ describe('ShareModalCtrl', () => { ...@@ -49,7 +50,7 @@ describe('ShareModalCtrl', () => {
{}, {},
ctx.timeSrv, ctx.timeSrv,
ctx.templateSrv, ctx.templateSrv,
new LinkSrv({}, ctx.stimeSrv) new LinkSrv({} as TemplateSrv, ctx.stimeSrv)
); );
}); });
......
...@@ -16,6 +16,9 @@ import { ...@@ -16,6 +16,9 @@ import {
import { GRID_COLUMN_COUNT } from 'app/core/constants'; import { GRID_COLUMN_COUNT } from 'app/core/constants';
import { auto } from 'angular';
import { TemplateSrv } from '../templating/template_srv';
import { LinkSrv } from './panellinks/link_srv';
export class PanelCtrl { export class PanelCtrl {
panel: any; panel: any;
error: any; error: any;
...@@ -24,7 +27,7 @@ export class PanelCtrl { ...@@ -24,7 +27,7 @@ export class PanelCtrl {
pluginId: string; pluginId: string;
editorTabs: any; editorTabs: any;
$scope: any; $scope: any;
$injector: any; $injector: auto.IInjectorService;
$location: any; $location: any;
$timeout: any; $timeout: any;
inspector: any; inspector: any;
...@@ -36,7 +39,7 @@ export class PanelCtrl { ...@@ -36,7 +39,7 @@ export class PanelCtrl {
timing: any; timing: any;
maxPanelsPerRowOptions: number[]; maxPanelsPerRowOptions: number[];
constructor($scope, $injector) { constructor($scope: any, $injector: auto.IInjectorService) {
this.$injector = $injector; this.$injector = $injector;
this.$location = $injector.get('$location'); this.$location = $injector.get('$location');
this.$scope = $scope; this.$scope = $scope;
...@@ -67,14 +70,14 @@ export class PanelCtrl { ...@@ -67,14 +70,14 @@ export class PanelCtrl {
this.panel.refresh(); this.panel.refresh();
} }
publishAppEvent(evtName, evt) { publishAppEvent(evtName: string, evt: any) {
this.$scope.$root.appEvent(evtName, evt); this.$scope.$root.appEvent(evtName, evt);
} }
changeView(fullscreen, edit) { changeView(fullscreen: boolean, edit: boolean) {
this.publishAppEvent('panel-change-view', { this.publishAppEvent('panel-change-view', {
fullscreen: fullscreen, fullscreen,
edit: edit, edit,
panelId: this.panel.id, panelId: this.panel.id,
}); });
} }
...@@ -99,7 +102,7 @@ export class PanelCtrl { ...@@ -99,7 +102,7 @@ export class PanelCtrl {
} }
} }
addEditorTab(title, directiveFn, index?, icon?) { addEditorTab(title: string, directiveFn: any, index?: number, icon?: any) {
const editorTab = { title, directiveFn, icon }; const editorTab = { title, directiveFn, icon };
if (_.isString(directiveFn)) { if (_.isString(directiveFn)) {
...@@ -193,7 +196,7 @@ export class PanelCtrl { ...@@ -193,7 +196,7 @@ export class PanelCtrl {
} }
// Override in sub-class to add items before extended menu // Override in sub-class to add items before extended menu
getAdditionalMenuItems() { getAdditionalMenuItems(): any[] {
return []; return [];
} }
...@@ -201,12 +204,12 @@ export class PanelCtrl { ...@@ -201,12 +204,12 @@ export class PanelCtrl {
return this.dashboard.meta.fullscreen && !this.panel.fullscreen; return this.dashboard.meta.fullscreen && !this.panel.fullscreen;
} }
calculatePanelHeight(containerHeight) { calculatePanelHeight(containerHeight: number) {
this.containerHeight = containerHeight; this.containerHeight = containerHeight;
this.height = calculateInnerPanelHeight(this.panel, containerHeight); this.height = calculateInnerPanelHeight(this.panel, containerHeight);
} }
render(payload?) { render(payload?: any) {
this.events.emit('render', payload); this.events.emit('render', payload);
} }
...@@ -243,16 +246,16 @@ export class PanelCtrl { ...@@ -243,16 +246,16 @@ export class PanelCtrl {
return ''; return '';
} }
getInfoContent(options) { getInfoContent(options: { mode: string }) {
let markdown = this.panel.description; let markdown = this.panel.description;
if (options.mode === 'tooltip') { if (options.mode === 'tooltip') {
markdown = this.error || this.panel.description; markdown = this.error || this.panel.description;
} }
const linkSrv = this.$injector.get('linkSrv'); const linkSrv: LinkSrv = this.$injector.get('linkSrv');
const sanitize = this.$injector.get('$sanitize'); const sanitize: any = this.$injector.get('$sanitize');
const templateSrv = this.$injector.get('templateSrv'); const templateSrv: TemplateSrv = this.$injector.get('templateSrv');
const interpolatedMarkdown = templateSrv.replace(markdown, this.panel.scopedVars); const interpolatedMarkdown = templateSrv.replace(markdown, this.panel.scopedVars);
let html = '<div class="markdown-html">'; let html = '<div class="markdown-html">';
......
import angular from 'angular'; import angular from 'angular';
import _ from 'lodash'; import _ from 'lodash';
import kbn from 'app/core/utils/kbn'; import kbn from 'app/core/utils/kbn';
import { TemplateSrv } from 'app/features/templating/template_srv';
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { ScopedVars } from '@grafana/ui/src/types/datasource';
export class LinkSrv { export class LinkSrv {
/** @ngInject */ /** @ngInject */
constructor(private templateSrv, private timeSrv) {} constructor(private templateSrv: TemplateSrv, private timeSrv: TimeSrv) {}
getLinkUrl(link) { getLinkUrl(link: any) {
const url = this.templateSrv.replace(link.url || ''); const url = this.templateSrv.replace(link.url || '');
const params = {}; const params: { [key: string]: any } = {};
if (link.keepTime) { if (link.keepTime) {
const range = this.timeSrv.timeRangeForUrl(); const range = this.timeSrv.timeRangeForUrl();
...@@ -23,8 +26,8 @@ export class LinkSrv { ...@@ -23,8 +26,8 @@ export class LinkSrv {
return this.addParamsToUrl(url, params); return this.addParamsToUrl(url, params);
} }
addParamsToUrl(url, params) { addParamsToUrl(url: string, params: any) {
const paramsArray = []; const paramsArray: Array<string | number> = [];
_.each(params, (value, key) => { _.each(params, (value, key) => {
if (value === null) { if (value === null) {
...@@ -48,7 +51,7 @@ export class LinkSrv { ...@@ -48,7 +51,7 @@ export class LinkSrv {
return this.appendToQueryString(url, paramsArray.join('&')); return this.appendToQueryString(url, paramsArray.join('&'));
} }
appendToQueryString(url, stringToAppend) { appendToQueryString(url: string, stringToAppend: string) {
if (!_.isUndefined(stringToAppend) && stringToAppend !== null && stringToAppend !== '') { if (!_.isUndefined(stringToAppend) && stringToAppend !== null && stringToAppend !== '') {
const pos = url.indexOf('?'); const pos = url.indexOf('?');
if (pos !== -1) { if (pos !== -1) {
...@@ -64,14 +67,14 @@ export class LinkSrv { ...@@ -64,14 +67,14 @@ export class LinkSrv {
return url; return url;
} }
getAnchorInfo(link) { getAnchorInfo(link: any) {
const info: any = {}; const info: any = {};
info.href = this.getLinkUrl(link); info.href = this.getLinkUrl(link);
info.title = this.templateSrv.replace(link.title || ''); info.title = this.templateSrv.replace(link.title || '');
return info; return info;
} }
getPanelLinkAnchorInfo(link, scopedVars) { getPanelLinkAnchorInfo(link: any, scopedVars: ScopedVars) {
const info: any = {}; const info: any = {};
info.target = link.targetBlank ? '_blank' : ''; info.target = link.targetBlank ? '_blank' : '';
if (link.type === 'absolute') { if (link.type === 'absolute') {
...@@ -90,7 +93,7 @@ export class LinkSrv { ...@@ -90,7 +93,7 @@ export class LinkSrv {
info.href = 'dashboard/db/' + slug + '?'; info.href = 'dashboard/db/' + slug + '?';
} }
const params = {}; const params: any = {};
if (link.keepTime) { if (link.keepTime) {
const range = this.timeSrv.timeRangeForUrl(); const range = this.timeSrv.timeRangeForUrl();
......
import { LinkSrv } from '../link_srv'; import { LinkSrv } from '../link_srv';
import _ from 'lodash'; import _ from 'lodash';
import { TemplateSrv } from 'app/features/templating/template_srv';
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
jest.mock('angular', () => { jest.mock('angular', () => {
const AngularJSMock = require('test/mocks/angular'); const AngularJSMock = require('test/mocks/angular');
...@@ -12,7 +14,7 @@ describe('linkSrv', () => { ...@@ -12,7 +14,7 @@ describe('linkSrv', () => {
const timeSrvMock = {}; const timeSrvMock = {};
beforeEach(() => { beforeEach(() => {
linkSrv = new LinkSrv(templateSrvMock, timeSrvMock); linkSrv = new LinkSrv(templateSrvMock as TemplateSrv, timeSrvMock as TimeSrv);
}); });
describe('when appending query strings', () => { describe('when appending query strings', () => {
......
...@@ -501,6 +501,11 @@ describe('templateSrv', () => { ...@@ -501,6 +501,11 @@ describe('templateSrv', () => {
initTemplateSrv([]); initTemplateSrv([]);
}); });
it('should be possible to fetch value with getBuilInIntervalValue', () => {
const val = _templateSrv.getBuiltInIntervalValue();
expect(val).toBe('1s');
});
it('should replace $__interval_ms with interval milliseconds', () => { it('should replace $__interval_ms with interval milliseconds', () => {
const target = _templateSrv.replace('10 * $__interval_ms', { const target = _templateSrv.replace('10 * $__interval_ms', {
__interval_ms: { text: '100', value: '100' }, __interval_ms: { text: '100', value: '100' },
......
...@@ -13,7 +13,7 @@ export class TemplateSrv { ...@@ -13,7 +13,7 @@ export class TemplateSrv {
private regex = variableRegex; private regex = variableRegex;
private index = {}; private index = {};
private grafanaVariables = {}; private grafanaVariables = {};
private builtIns = {}; private builtIns: any = {};
private timeRange: TimeRange = null; private timeRange: TimeRange = null;
constructor() { constructor() {
...@@ -28,6 +28,10 @@ export class TemplateSrv { ...@@ -28,6 +28,10 @@ export class TemplateSrv {
this.updateIndex(); this.updateIndex();
} }
getBuiltInIntervalValue() {
return this.builtIns.__interval.value;
}
updateIndex() { updateIndex() {
const existsOrEmpty = value => value || value === ''; const existsOrEmpty = value => value || value === '';
......
...@@ -5,6 +5,7 @@ jest.mock('./css/query_editor.css', () => { ...@@ -5,6 +5,7 @@ jest.mock('./css/query_editor.css', () => {
import { AzureMonitorQueryCtrl } from './query_ctrl'; import { AzureMonitorQueryCtrl } from './query_ctrl';
import Q from 'q'; import Q from 'q';
import { TemplateSrv } from 'app/features/templating/template_srv'; import { TemplateSrv } from 'app/features/templating/template_srv';
import { auto } from 'angular';
describe('AzureMonitorQueryCtrl', () => { describe('AzureMonitorQueryCtrl', () => {
let queryCtrl: any; let queryCtrl: any;
...@@ -21,7 +22,7 @@ describe('AzureMonitorQueryCtrl', () => { ...@@ -21,7 +22,7 @@ describe('AzureMonitorQueryCtrl', () => {
azureMonitorDatasource: { isConfigured: () => false }, azureMonitorDatasource: { isConfigured: () => false },
}; };
queryCtrl = new AzureMonitorQueryCtrl({}, {}, new TemplateSrv()); queryCtrl = new AzureMonitorQueryCtrl({}, {} as auto.IInjectorService, new TemplateSrv());
}); });
describe('init query_ctrl variables', () => { describe('init query_ctrl variables', () => {
......
...@@ -4,6 +4,9 @@ import { QueryCtrl } from 'app/plugins/sdk'; ...@@ -4,6 +4,9 @@ import { QueryCtrl } from 'app/plugins/sdk';
import TimegrainConverter from './time_grain_converter'; import TimegrainConverter from './time_grain_converter';
import './editor/editor_component'; import './editor/editor_component';
import { TemplateSrv } from 'app/features/templating/template_srv';
import { auto } from 'angular';
export interface ResultFormat { export interface ResultFormat {
text: string; text: string;
value: string; value: string;
...@@ -103,7 +106,7 @@ export class AzureMonitorQueryCtrl extends QueryCtrl { ...@@ -103,7 +106,7 @@ export class AzureMonitorQueryCtrl extends QueryCtrl {
subscriptions: Array<{ text: string; value: string }>; subscriptions: Array<{ text: string; value: string }>;
/** @ngInject */ /** @ngInject */
constructor($scope, $injector, private templateSrv) { constructor($scope: any, $injector: auto.IInjectorService, private templateSrv: TemplateSrv) {
super($scope, $injector); super($scope, $injector);
_.defaultsDeep(this.target, this.defaults); _.defaultsDeep(this.target, this.defaults);
...@@ -360,7 +363,7 @@ export class AzureMonitorQueryCtrl extends QueryCtrl { ...@@ -360,7 +363,7 @@ export class AzureMonitorQueryCtrl extends QueryCtrl {
getAutoInterval() { getAutoInterval() {
if (this.target.azureMonitor.timeGrain === 'auto') { if (this.target.azureMonitor.timeGrain === 'auto') {
return TimegrainConverter.findClosestTimeGrain( return TimegrainConverter.findClosestTimeGrain(
this.templateSrv.builtIns.__interval.value, this.templateSrv.getBuiltInIntervalValue(),
_.map(this.target.azureMonitor.timeGrains, o => _.map(this.target.azureMonitor.timeGrains, o =>
TimegrainConverter.createKbnUnitFromISO8601Duration(o.value) TimegrainConverter.createKbnUnitFromISO8601Duration(o.value)
) || ['1m', '5m', '15m', '30m', '1h', '6h', '12h', '1d'] ) || ['1m', '5m', '15m', '30m', '1h', '6h', '12h', '1d']
...@@ -407,7 +410,7 @@ export class AzureMonitorQueryCtrl extends QueryCtrl { ...@@ -407,7 +410,7 @@ export class AzureMonitorQueryCtrl extends QueryCtrl {
/* Application Insights Section */ /* Application Insights Section */
getAppInsightsAutoInterval() { getAppInsightsAutoInterval() {
const interval = this.templateSrv.builtIns.__interval.value; const interval = this.templateSrv.getBuiltInIntervalValue();
if (interval[interval.length - 1] === 's') { if (interval[interval.length - 1] === 's') {
return '1m'; return '1m';
} }
......
...@@ -21,16 +21,21 @@ import { updateLocation } from 'app/core/actions'; ...@@ -21,16 +21,21 @@ import { updateLocation } from 'app/core/actions';
// Types // Types
import { KioskUrlValue } from 'app/types'; import { KioskUrlValue } from 'app/types';
import { UtilSrv } from 'app/core/services/util_srv';
import { ContextSrv } from 'app/core/services/context_srv';
import { BridgeSrv } from 'app/core/services/bridge_srv';
import { PlaylistSrv } from 'app/features/playlist/playlist_srv';
import { ILocationService, ITimeoutService, IRootScopeService, IControllerService } from 'angular';
export class GrafanaCtrl { export class GrafanaCtrl {
/** @ngInject */ /** @ngInject */
constructor( constructor(
$scope, $scope: any,
utilSrv, utilSrv: UtilSrv,
$rootScope, $rootScope: any,
$controller, $controller: IControllerService,
contextSrv, contextSrv: ContextSrv,
bridgeSrv, bridgeSrv: BridgeSrv,
backendSrv: BackendSrv, backendSrv: BackendSrv,
timeSrv: TimeSrv, timeSrv: TimeSrv,
datasourceSrv: DatasourceSrv, datasourceSrv: DatasourceSrv,
...@@ -62,7 +67,7 @@ export class GrafanaCtrl { ...@@ -62,7 +67,7 @@ export class GrafanaCtrl {
$rootScope.colors = colors; $rootScope.colors = colors;
$rootScope.onAppEvent = function(name, callback, localScope) { $rootScope.onAppEvent = function(name: string, callback: () => void, localScope: any) {
const unbind = $rootScope.$on(name, callback); const unbind = $rootScope.$on(name, callback);
let callerScope = this; let callerScope = this;
if (callerScope.$id === 1 && !localScope) { if (callerScope.$id === 1 && !localScope) {
...@@ -74,7 +79,7 @@ export class GrafanaCtrl { ...@@ -74,7 +79,7 @@ export class GrafanaCtrl {
callerScope.$on('$destroy', unbind); callerScope.$on('$destroy', unbind);
}; };
$rootScope.appEvent = (name, payload) => { $rootScope.appEvent = (name: string, payload: any) => {
$rootScope.$emit(name, payload); $rootScope.$emit(name, payload);
appEvents.emit(name, payload); appEvents.emit(name, payload);
}; };
...@@ -103,11 +108,17 @@ function setViewModeBodyClass(body: JQuery, mode: KioskUrlValue) { ...@@ -103,11 +108,17 @@ function setViewModeBodyClass(body: JQuery, mode: KioskUrlValue) {
} }
/** @ngInject */ /** @ngInject */
export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScope, $location) { export function grafanaAppDirective(
playlistSrv: PlaylistSrv,
contextSrv: ContextSrv,
$timeout: ITimeoutService,
$rootScope: IRootScopeService,
$location: ILocationService
) {
return { return {
restrict: 'E', restrict: 'E',
controller: GrafanaCtrl, controller: GrafanaCtrl,
link: (scope, elem) => { link: (scope: any, elem: JQuery) => {
const body = $('body'); const body = $('body');
// see https://github.com/zenorocha/clipboard.js/issues/155 // see https://github.com/zenorocha/clipboard.js/issues/155
...@@ -138,8 +149,8 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop ...@@ -138,8 +149,8 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop
// tooltip removal fix // tooltip removal fix
// manage page classes // manage page classes
let pageClass; let pageClass: string;
scope.$on('$routeChangeSuccess', (evt, data) => { scope.$on('$routeChangeSuccess', (evt: any, data: any) => {
if (pageClass) { if (pageClass) {
body.removeClass(pageClass); body.removeClass(pageClass);
} }
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
echo -e "Collecting code stats (typescript errors & more)" echo -e "Collecting code stats (typescript errors & more)"
ERROR_COUNT_LIMIT=5131
ERROR_COUNT_LIMIT=5120
DIRECTIVES_LIMIT=172 DIRECTIVES_LIMIT=172
CONTROLLERS_LIMIT=139 CONTROLLERS_LIMIT=139
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment