mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Typescript: A batch of implicit any fixes (#17590)
* Reduce noImplicitAny errors * Lower err count * Static version * Fix noImplicitAny * Table: moved type file
This commit is contained in:
parent
2f00087a08
commit
8ffef57178
@ -1,6 +1,9 @@
|
||||
import _ from 'lodash';
|
||||
import coreModule from 'app/core/core_module';
|
||||
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 {
|
||||
initialTitle: string;
|
||||
@ -24,7 +27,7 @@ export class FolderPickerCtrl {
|
||||
dashboardId?: number;
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private backendSrv, private validationSrv, private contextSrv) {
|
||||
constructor(private backendSrv: BackendSrv, private validationSrv: ValidationSrv, private contextSrv: ContextSrv) {
|
||||
this.isEditor = this.contextSrv.isEditor;
|
||||
|
||||
if (!this.labelClass) {
|
||||
@ -34,14 +37,14 @@ export class FolderPickerCtrl {
|
||||
this.loadInitialValue();
|
||||
}
|
||||
|
||||
getOptions(query) {
|
||||
getOptions(query: string) {
|
||||
const params = {
|
||||
query: query,
|
||||
query,
|
||||
type: 'dash-folder',
|
||||
permission: 'Edit',
|
||||
};
|
||||
|
||||
return this.backendSrv.get('api/search', params).then(result => {
|
||||
return this.backendSrv.get('api/search', params).then((result: any) => {
|
||||
if (
|
||||
this.isEditor &&
|
||||
(query === '' ||
|
||||
@ -70,7 +73,7 @@ export class FolderPickerCtrl {
|
||||
});
|
||||
}
|
||||
|
||||
onFolderChange(option) {
|
||||
onFolderChange(option: { value: number; text: string }) {
|
||||
if (!option) {
|
||||
option = { value: 0, text: this.rootName };
|
||||
} else if (option.value === -1) {
|
||||
@ -89,19 +92,19 @@ export class FolderPickerCtrl {
|
||||
.then(() => {
|
||||
this.hasValidationError = false;
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err: any) => {
|
||||
this.hasValidationError = true;
|
||||
this.validationError = err.message;
|
||||
});
|
||||
}
|
||||
|
||||
createFolder(evt) {
|
||||
createFolder(evt: any) {
|
||||
if (evt) {
|
||||
evt.stopPropagation();
|
||||
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']);
|
||||
|
||||
this.closeCreateFolder();
|
||||
@ -110,7 +113,7 @@ export class FolderPickerCtrl {
|
||||
});
|
||||
}
|
||||
|
||||
cancelCreateFolder(evt) {
|
||||
cancelCreateFolder(evt: any) {
|
||||
if (evt) {
|
||||
evt.stopPropagation();
|
||||
evt.preventDefault();
|
||||
@ -130,12 +133,13 @@ export class FolderPickerCtrl {
|
||||
}
|
||||
|
||||
private loadInitialValue() {
|
||||
const resetFolder = { text: this.initialTitle, value: null };
|
||||
const rootFolder = { text: this.rootName, value: 0 };
|
||||
const resetFolder: { text: string; value: any } = { text: this.initialTitle, value: null };
|
||||
const rootFolder: { text: string; value: any } = { text: this.rootName, value: 0 };
|
||||
|
||||
this.getOptions('').then(result => {
|
||||
let folder;
|
||||
this.getOptions('').then((result: any[]) => {
|
||||
let folder: { text: string; value: any };
|
||||
if (this.initialFolderId) {
|
||||
// @ts-ignore
|
||||
folder = _.find(result, { value: this.initialFolderId });
|
||||
} else if (this.enableReset && this.initialTitle && this.initialFolderId === null) {
|
||||
folder = resetFolder;
|
||||
|
@ -1,5 +1,7 @@
|
||||
import _ from 'lodash';
|
||||
import { transformers } from './transformers';
|
||||
import { IQService } from 'angular';
|
||||
import { Column } from 'react-virtualized';
|
||||
|
||||
export class TablePanelEditorCtrl {
|
||||
panel: any;
|
||||
@ -12,7 +14,7 @@ export class TablePanelEditorCtrl {
|
||||
columnsHelpMessage: string;
|
||||
|
||||
/** @ngInject */
|
||||
constructor($scope, private $q, private uiSegmentSrv) {
|
||||
constructor($scope: any, private $q: IQService, private uiSegmentSrv: any) {
|
||||
$scope.editor = this;
|
||||
this.panelCtrl = $scope.ctrl;
|
||||
this.panel = this.panelCtrl.panel;
|
||||
@ -78,14 +80,14 @@ export class TablePanelEditorCtrl {
|
||||
this.panelCtrl.render();
|
||||
}
|
||||
|
||||
removeColumn(column) {
|
||||
removeColumn(column: Column) {
|
||||
this.panel.columns = _.without(this.panel.columns, column);
|
||||
this.panelCtrl.render();
|
||||
}
|
||||
}
|
||||
|
||||
/** @ngInject */
|
||||
export function tablePanelEditor($q, uiSegmentSrv) {
|
||||
export function tablePanelEditor($q: IQService, uiSegmentSrv: any) {
|
||||
'use strict';
|
||||
return {
|
||||
restrict: 'E',
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { transformers, transformDataToTable } from '../transformers';
|
||||
import { TableData } from '@grafana/ui';
|
||||
|
||||
describe('when transforming time series table', () => {
|
||||
let table;
|
||||
let table: TableData;
|
||||
|
||||
describe('given 2 time series', () => {
|
||||
const time = new Date().getTime();
|
||||
|
@ -2,8 +2,10 @@ import _ from 'lodash';
|
||||
import flatten from 'app/core/utils/flatten';
|
||||
import TimeSeries from 'app/core/time_series2';
|
||||
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'] = {
|
||||
description: 'Time series to rows',
|
||||
@ -32,7 +34,7 @@ transformers['timeseries_to_columns'] = {
|
||||
model.columns.push({ text: 'Time', type: 'date' });
|
||||
|
||||
// group by time
|
||||
const points = {};
|
||||
const points: any = {};
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const series = data[i];
|
||||
@ -138,10 +140,10 @@ transformers['table'] = {
|
||||
}
|
||||
|
||||
// Track column indexes: name -> index
|
||||
const columnNames = {};
|
||||
const columnNames: any = {};
|
||||
|
||||
// Union of all columns
|
||||
const columns = data.reduce((acc, series) => {
|
||||
const columns = data.reduce((acc: Column[], series: TableData) => {
|
||||
series.columns.forEach(col => {
|
||||
const { text } = col;
|
||||
if (columnNames[text] === undefined) {
|
||||
@ -240,7 +242,7 @@ transformers['json'] = {
|
||||
},
|
||||
};
|
||||
|
||||
function transformDataToTable(data, panel) {
|
||||
function transformDataToTable(data: any, panel: any) {
|
||||
const model = new TableModel();
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
|
7
public/app/plugins/panel/table/types.ts
Normal file
7
public/app/plugins/panel/table/types.ts
Normal file
@ -0,0 +1,7 @@
|
||||
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';
|
||||
import Remarkable from 'remarkable';
|
||||
import { sanitize } from 'app/core/utils/text';
|
||||
import config from 'app/core/config';
|
||||
import { auto, ISCEService } from 'angular';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
|
||||
const defaultContent = `
|
||||
# Title
|
||||
@ -26,7 +28,12 @@ export class TextPanelCtrl extends PanelCtrl {
|
||||
};
|
||||
|
||||
/** @ngInject */
|
||||
constructor($scope, $injector, private templateSrv, private $sce) {
|
||||
constructor(
|
||||
$scope: any,
|
||||
$injector: auto.IInjectorService,
|
||||
private templateSrv: TemplateSrv,
|
||||
private $sce: ISCEService
|
||||
) {
|
||||
super($scope, $injector);
|
||||
|
||||
_.defaults(this.panel, this.panelDefaults);
|
||||
|
@ -1,13 +1,24 @@
|
||||
import coreModule from 'app/core/core_module';
|
||||
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 {
|
||||
/** @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');
|
||||
|
||||
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) {
|
||||
const newUrl = locationUtil.stripBaseFromUrl(homeDash.redirectUri);
|
||||
$location.path(newUrl);
|
||||
@ -22,6 +33,7 @@ export class LoadDashboardCtrl {
|
||||
|
||||
// if no uid, redirect to new route based on slug
|
||||
if (!($routeParams.type === 'script' || $routeParams.type === 'snapshot') && !$routeParams.uid) {
|
||||
// @ts-ignore
|
||||
backendSrv.getDashboardBySlug($routeParams.slug).then(res => {
|
||||
if (res) {
|
||||
$location.path(locationUtil.stripBaseFromUrl(res.meta.url)).replace();
|
||||
@ -30,7 +42,7 @@ export class LoadDashboardCtrl {
|
||||
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) {
|
||||
const url = locationUtil.stripBaseFromUrl(result.meta.url);
|
||||
|
||||
@ -51,7 +63,7 @@ export class LoadDashboardCtrl {
|
||||
|
||||
export class NewDashboardCtrl {
|
||||
/** @ngInject */
|
||||
constructor($scope, $routeParams) {
|
||||
constructor($scope: any, $routeParams: UrlQueryMap) {
|
||||
$scope.initDashboard(
|
||||
{
|
||||
meta: {
|
||||
|
@ -3,7 +3,7 @@
|
||||
echo -e "Collecting code stats (typescript errors & more)"
|
||||
|
||||
|
||||
ERROR_COUNT_LIMIT=5120
|
||||
ERROR_COUNT_LIMIT=5090
|
||||
DIRECTIVES_LIMIT=172
|
||||
CONTROLLERS_LIMIT=139
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user