Commit 8ffef571 by Tobias Skarhed Committed by Torkel Ödegaard

Typescript: A batch of implicit any fixes (#17590)

* Reduce noImplicitAny errors

* Lower err count

* Static version

* Fix noImplicitAny

* Table: moved type file
parent 2f00087a
import _ from 'lodash'; import _ from 'lodash';
import coreModule from 'app/core/core_module'; import coreModule from 'app/core/core_module';
import appEvents from 'app/core/app_events'; import appEvents from 'app/core/app_events';
import { BackendSrv } from 'app/core/services/backend_srv';
import { ValidationSrv } from 'app/features/manage-dashboards';
import { ContextSrv } from 'app/core/services/context_srv';
export class FolderPickerCtrl { export class FolderPickerCtrl {
initialTitle: string; initialTitle: string;
...@@ -24,7 +27,7 @@ export class FolderPickerCtrl { ...@@ -24,7 +27,7 @@ export class FolderPickerCtrl {
dashboardId?: number; dashboardId?: number;
/** @ngInject */ /** @ngInject */
constructor(private backendSrv, private validationSrv, private contextSrv) { constructor(private backendSrv: BackendSrv, private validationSrv: ValidationSrv, private contextSrv: ContextSrv) {
this.isEditor = this.contextSrv.isEditor; this.isEditor = this.contextSrv.isEditor;
if (!this.labelClass) { if (!this.labelClass) {
...@@ -34,14 +37,14 @@ export class FolderPickerCtrl { ...@@ -34,14 +37,14 @@ export class FolderPickerCtrl {
this.loadInitialValue(); this.loadInitialValue();
} }
getOptions(query) { getOptions(query: string) {
const params = { const params = {
query: query, query,
type: 'dash-folder', type: 'dash-folder',
permission: 'Edit', permission: 'Edit',
}; };
return this.backendSrv.get('api/search', params).then(result => { return this.backendSrv.get('api/search', params).then((result: any) => {
if ( if (
this.isEditor && this.isEditor &&
(query === '' || (query === '' ||
...@@ -70,7 +73,7 @@ export class FolderPickerCtrl { ...@@ -70,7 +73,7 @@ export class FolderPickerCtrl {
}); });
} }
onFolderChange(option) { onFolderChange(option: { value: number; text: string }) {
if (!option) { if (!option) {
option = { value: 0, text: this.rootName }; option = { value: 0, text: this.rootName };
} else if (option.value === -1) { } else if (option.value === -1) {
...@@ -89,19 +92,19 @@ export class FolderPickerCtrl { ...@@ -89,19 +92,19 @@ export class FolderPickerCtrl {
.then(() => { .then(() => {
this.hasValidationError = false; this.hasValidationError = false;
}) })
.catch(err => { .catch((err: any) => {
this.hasValidationError = true; this.hasValidationError = true;
this.validationError = err.message; this.validationError = err.message;
}); });
} }
createFolder(evt) { createFolder(evt: any) {
if (evt) { if (evt) {
evt.stopPropagation(); evt.stopPropagation();
evt.preventDefault(); evt.preventDefault();
} }
return this.backendSrv.createFolder({ title: this.newFolderName }).then(result => { return this.backendSrv.createFolder({ title: this.newFolderName }).then((result: { title: string; id: number }) => {
appEvents.emit('alert-success', ['Folder Created', 'OK']); appEvents.emit('alert-success', ['Folder Created', 'OK']);
this.closeCreateFolder(); this.closeCreateFolder();
...@@ -110,7 +113,7 @@ export class FolderPickerCtrl { ...@@ -110,7 +113,7 @@ export class FolderPickerCtrl {
}); });
} }
cancelCreateFolder(evt) { cancelCreateFolder(evt: any) {
if (evt) { if (evt) {
evt.stopPropagation(); evt.stopPropagation();
evt.preventDefault(); evt.preventDefault();
...@@ -130,12 +133,13 @@ export class FolderPickerCtrl { ...@@ -130,12 +133,13 @@ export class FolderPickerCtrl {
} }
private loadInitialValue() { private loadInitialValue() {
const resetFolder = { text: this.initialTitle, value: null }; const resetFolder: { text: string; value: any } = { text: this.initialTitle, value: null };
const rootFolder = { text: this.rootName, value: 0 }; const rootFolder: { text: string; value: any } = { text: this.rootName, value: 0 };
this.getOptions('').then(result => { this.getOptions('').then((result: any[]) => {
let folder; let folder: { text: string; value: any };
if (this.initialFolderId) { if (this.initialFolderId) {
// @ts-ignore
folder = _.find(result, { value: this.initialFolderId }); folder = _.find(result, { value: this.initialFolderId });
} else if (this.enableReset && this.initialTitle && this.initialFolderId === null) { } else if (this.enableReset && this.initialTitle && this.initialFolderId === null) {
folder = resetFolder; folder = resetFolder;
......
import _ from 'lodash'; import _ from 'lodash';
import { transformers } from './transformers'; import { transformers } from './transformers';
import { IQService } from 'angular';
import { Column } from 'react-virtualized';
export class TablePanelEditorCtrl { export class TablePanelEditorCtrl {
panel: any; panel: any;
...@@ -12,7 +14,7 @@ export class TablePanelEditorCtrl { ...@@ -12,7 +14,7 @@ export class TablePanelEditorCtrl {
columnsHelpMessage: string; columnsHelpMessage: string;
/** @ngInject */ /** @ngInject */
constructor($scope, private $q, private uiSegmentSrv) { constructor($scope: any, private $q: IQService, private uiSegmentSrv: any) {
$scope.editor = this; $scope.editor = this;
this.panelCtrl = $scope.ctrl; this.panelCtrl = $scope.ctrl;
this.panel = this.panelCtrl.panel; this.panel = this.panelCtrl.panel;
...@@ -78,14 +80,14 @@ export class TablePanelEditorCtrl { ...@@ -78,14 +80,14 @@ export class TablePanelEditorCtrl {
this.panelCtrl.render(); this.panelCtrl.render();
} }
removeColumn(column) { removeColumn(column: Column) {
this.panel.columns = _.without(this.panel.columns, column); this.panel.columns = _.without(this.panel.columns, column);
this.panelCtrl.render(); this.panelCtrl.render();
} }
} }
/** @ngInject */ /** @ngInject */
export function tablePanelEditor($q, uiSegmentSrv) { export function tablePanelEditor($q: IQService, uiSegmentSrv: any) {
'use strict'; 'use strict';
return { return {
restrict: 'E', restrict: 'E',
......
import { transformers, transformDataToTable } from '../transformers'; import { transformers, transformDataToTable } from '../transformers';
import { TableData } from '@grafana/ui';
describe('when transforming time series table', () => { describe('when transforming time series table', () => {
let table; let table: TableData;
describe('given 2 time series', () => { describe('given 2 time series', () => {
const time = new Date().getTime(); const time = new Date().getTime();
......
...@@ -2,8 +2,10 @@ import _ from 'lodash'; ...@@ -2,8 +2,10 @@ import _ from 'lodash';
import flatten from 'app/core/utils/flatten'; import flatten from 'app/core/utils/flatten';
import TimeSeries from 'app/core/time_series2'; import TimeSeries from 'app/core/time_series2';
import TableModel, { mergeTablesIntoModel } from 'app/core/table_model'; import TableModel, { mergeTablesIntoModel } from 'app/core/table_model';
import { TableTransform } from './types';
import { Column, TableData } from '@grafana/ui';
const transformers = {}; const transformers: { [key: string]: TableTransform } = {};
transformers['timeseries_to_rows'] = { transformers['timeseries_to_rows'] = {
description: 'Time series to rows', description: 'Time series to rows',
...@@ -32,7 +34,7 @@ transformers['timeseries_to_columns'] = { ...@@ -32,7 +34,7 @@ transformers['timeseries_to_columns'] = {
model.columns.push({ text: 'Time', type: 'date' }); model.columns.push({ text: 'Time', type: 'date' });
// group by time // group by time
const points = {}; const points: any = {};
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
const series = data[i]; const series = data[i];
...@@ -138,10 +140,10 @@ transformers['table'] = { ...@@ -138,10 +140,10 @@ transformers['table'] = {
} }
// Track column indexes: name -> index // Track column indexes: name -> index
const columnNames = {}; const columnNames: any = {};
// Union of all columns // Union of all columns
const columns = data.reduce((acc, series) => { const columns = data.reduce((acc: Column[], series: TableData) => {
series.columns.forEach(col => { series.columns.forEach(col => {
const { text } = col; const { text } = col;
if (columnNames[text] === undefined) { if (columnNames[text] === undefined) {
...@@ -240,7 +242,7 @@ transformers['json'] = { ...@@ -240,7 +242,7 @@ transformers['json'] = {
}, },
}; };
function transformDataToTable(data, panel) { function transformDataToTable(data: any, panel: any) {
const model = new TableModel(); const model = new TableModel();
if (!data || data.length === 0) { if (!data || data.length === 0) {
......
import TableModel from 'app/core/table_model';
export interface TableTransform {
description: string;
getColumns(data?: any): any[];
transform(data: any, panel: any, model: TableModel): void;
}
...@@ -3,6 +3,8 @@ import { PanelCtrl } from 'app/plugins/sdk'; ...@@ -3,6 +3,8 @@ import { PanelCtrl } from 'app/plugins/sdk';
import Remarkable from 'remarkable'; import Remarkable from 'remarkable';
import { sanitize } from 'app/core/utils/text'; import { sanitize } from 'app/core/utils/text';
import config from 'app/core/config'; import config from 'app/core/config';
import { auto, ISCEService } from 'angular';
import { TemplateSrv } from 'app/features/templating/template_srv';
const defaultContent = ` const defaultContent = `
# Title # Title
...@@ -26,7 +28,12 @@ export class TextPanelCtrl extends PanelCtrl { ...@@ -26,7 +28,12 @@ export class TextPanelCtrl extends PanelCtrl {
}; };
/** @ngInject */ /** @ngInject */
constructor($scope, $injector, private templateSrv, private $sce) { constructor(
$scope: any,
$injector: auto.IInjectorService,
private templateSrv: TemplateSrv,
private $sce: ISCEService
) {
super($scope, $injector); super($scope, $injector);
_.defaults(this.panel, this.panelDefaults); _.defaults(this.panel, this.panelDefaults);
......
import coreModule from 'app/core/core_module'; import coreModule from 'app/core/core_module';
import locationUtil from 'app/core/utils/location_util'; import locationUtil from 'app/core/utils/location_util';
import { UrlQueryMap } from '@grafana/runtime';
import { DashboardLoaderSrv } from 'app/features/dashboard/services/DashboardLoaderSrv';
import { BackendSrv } from 'app/core/services/backend_srv';
import { ILocationService } from 'angular';
export class LoadDashboardCtrl { export class LoadDashboardCtrl {
/** @ngInject */ /** @ngInject */
constructor($scope, $routeParams, dashboardLoaderSrv, backendSrv, $location, $browser) { constructor(
$scope: any,
$routeParams: UrlQueryMap,
dashboardLoaderSrv: DashboardLoaderSrv,
backendSrv: BackendSrv,
$location: ILocationService,
$browser: any
) {
$scope.appEvent('dashboard-fetch-start'); $scope.appEvent('dashboard-fetch-start');
if (!$routeParams.uid && !$routeParams.slug) { if (!$routeParams.uid && !$routeParams.slug) {
backendSrv.get('/api/dashboards/home').then(homeDash => { backendSrv.get('/api/dashboards/home').then((homeDash: { redirectUri: string; meta: any }) => {
if (homeDash.redirectUri) { if (homeDash.redirectUri) {
const newUrl = locationUtil.stripBaseFromUrl(homeDash.redirectUri); const newUrl = locationUtil.stripBaseFromUrl(homeDash.redirectUri);
$location.path(newUrl); $location.path(newUrl);
...@@ -22,6 +33,7 @@ export class LoadDashboardCtrl { ...@@ -22,6 +33,7 @@ export class LoadDashboardCtrl {
// if no uid, redirect to new route based on slug // if no uid, redirect to new route based on slug
if (!($routeParams.type === 'script' || $routeParams.type === 'snapshot') && !$routeParams.uid) { if (!($routeParams.type === 'script' || $routeParams.type === 'snapshot') && !$routeParams.uid) {
// @ts-ignore
backendSrv.getDashboardBySlug($routeParams.slug).then(res => { backendSrv.getDashboardBySlug($routeParams.slug).then(res => {
if (res) { if (res) {
$location.path(locationUtil.stripBaseFromUrl(res.meta.url)).replace(); $location.path(locationUtil.stripBaseFromUrl(res.meta.url)).replace();
...@@ -30,7 +42,7 @@ export class LoadDashboardCtrl { ...@@ -30,7 +42,7 @@ export class LoadDashboardCtrl {
return; return;
} }
dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug, $routeParams.uid).then(result => { dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug, $routeParams.uid).then((result: any) => {
if (result.meta.url) { if (result.meta.url) {
const url = locationUtil.stripBaseFromUrl(result.meta.url); const url = locationUtil.stripBaseFromUrl(result.meta.url);
...@@ -51,7 +63,7 @@ export class LoadDashboardCtrl { ...@@ -51,7 +63,7 @@ export class LoadDashboardCtrl {
export class NewDashboardCtrl { export class NewDashboardCtrl {
/** @ngInject */ /** @ngInject */
constructor($scope, $routeParams) { constructor($scope: any, $routeParams: UrlQueryMap) {
$scope.initDashboard( $scope.initDashboard(
{ {
meta: { meta: {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
echo -e "Collecting code stats (typescript errors & more)" echo -e "Collecting code stats (typescript errors & more)"
ERROR_COUNT_LIMIT=5120 ERROR_COUNT_LIMIT=5090
DIRECTIVES_LIMIT=172 DIRECTIVES_LIMIT=172
CONTROLLERS_LIMIT=139 CONTROLLERS_LIMIT=139
......
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