Chore: noImplictAny no errors left (#18303)

* Add types and rewrite datasourceChanged to async/await
This commit is contained in:
Tobias Skarhed
2019-08-01 14:38:34 +02:00
committed by GitHub
parent bcf28cb7a2
commit 83da3660da
63 changed files with 285 additions and 211 deletions

View File

@@ -1,7 +1,9 @@
import _ from 'lodash';
import angular from 'angular';
import angular, { IQService } from 'angular';
import coreModule from 'app/core/core_module';
import { DashboardModel } from 'app/features/dashboard/state';
import DatasourceSrv from 'app/features/plugins/datasource_srv';
import { VariableSrv } from 'app/features/templating/all';
export class AdHocFiltersCtrl {
segments: any;
@@ -10,7 +12,13 @@ export class AdHocFiltersCtrl {
removeTagFilterSegment: any;
/** @ngInject */
constructor(private uiSegmentSrv, private datasourceSrv, private $q, private variableSrv, $scope) {
constructor(
private uiSegmentSrv: any,
private datasourceSrv: DatasourceSrv,
private $q: IQService,
private variableSrv: VariableSrv,
$scope: any
) {
this.removeTagFilterSegment = uiSegmentSrv.newSegment({
fake: true,
value: '-- remove filter --',
@@ -40,7 +48,7 @@ export class AdHocFiltersCtrl {
this.segments.push(this.uiSegmentSrv.newPlusButton());
}
getOptions(segment, index) {
getOptions(segment: { type: string }, index: number) {
if (segment.type === 'operator') {
return this.$q.when(this.uiSegmentSrv.newOperators(['=', '!=', '<', '>', '=~', '!~']));
}
@@ -60,7 +68,7 @@ export class AdHocFiltersCtrl {
promise = ds.getTagValues ? ds.getTagValues(options) : Promise.resolve([]);
}
return promise.then(results => {
return promise.then((results: any) => {
results = _.map(results, segment => {
return this.uiSegmentSrv.newSegment({ value: segment.text });
});
@@ -74,7 +82,7 @@ export class AdHocFiltersCtrl {
});
}
segmentChanged(segment, index) {
segmentChanged(segment: { value: any; type: string; cssClass: string }, index: number) {
this.segments[index] = segment;
// handle remove tag condition
@@ -108,11 +116,11 @@ export class AdHocFiltersCtrl {
}
updateVariableModel() {
const filters = [];
const filters: any[] = [];
let filterIndex = -1;
let hasFakes = false;
this.segments.forEach(segment => {
this.segments.forEach((segment: any) => {
if (segment.type === 'value' && segment.fake) {
hasFakes = true;
return;

View File

@@ -16,6 +16,8 @@ import { DashboardModel } from '../../state';
import { LS_PANEL_COPY_KEY } from 'app/core/constants';
import { LocationUpdate } from '@grafana/runtime';
export type PanelPluginInfo = { id: any; defaults: { gridPos: { w: any; h: any }; title: any } };
export interface Props {
panel: PanelModel;
dashboard: DashboardModel;
@@ -26,7 +28,7 @@ export interface State {
}
export class AddPanelWidget extends React.Component<Props, State> {
constructor(props) {
constructor(props: Props) {
super(props);
this.handleCloseAddPanel = this.handleCloseAddPanel.bind(this);
@@ -58,7 +60,7 @@ export class AddPanelWidget extends React.Component<Props, State> {
return _.sortBy(copiedPanels, 'sort');
}
handleCloseAddPanel(evt) {
handleCloseAddPanel(evt: any) {
evt.preventDefault();
this.props.dashboard.removePanel(this.props.panel);
}
@@ -93,7 +95,7 @@ export class AddPanelWidget extends React.Component<Props, State> {
reduxStore.dispatch(updateLocation(location));
};
onPasteCopiedPanel = panelPluginInfo => {
onPasteCopiedPanel = (panelPluginInfo: PanelPluginInfo) => {
const dashboard = this.props.dashboard;
const { gridPos } = this.props.panel;
@@ -132,7 +134,7 @@ export class AddPanelWidget extends React.Component<Props, State> {
dashboard.removePanel(this.props.panel);
};
renderOptionLink = (icon: string, text: string, onClick) => {
renderOptionLink = (icon: string, text: string, onClick: any) => {
return (
<div>
<a

View File

@@ -3,6 +3,8 @@ import { saveAs } from 'file-saver';
import coreModule from 'app/core/core_module';
import { DashboardExporter } from './DashboardExporter';
import { DashboardSrv } from '../../services/DashboardSrv';
import DatasourceSrv from 'app/features/plugins/datasource_srv';
export class DashExportCtrl {
dash: any;
@@ -11,7 +13,12 @@ export class DashExportCtrl {
shareExternally: boolean;
/** @ngInject */
constructor(private dashboardSrv, datasourceSrv, private $scope, private $rootScope) {
constructor(
private dashboardSrv: DashboardSrv,
datasourceSrv: DatasourceSrv,
private $scope: any,
private $rootScope: any
) {
this.exporter = new DashboardExporter(datasourceSrv);
this.dash = this.dashboardSrv.getCurrent();

View File

@@ -1,6 +1,11 @@
import angular from 'angular';
import angular, { IQService } from 'angular';
import _ from 'lodash';
import { iconMap } from './DashLinksEditorCtrl';
import { LinkSrv } from 'app/features/panel/panellinks/link_srv';
import { BackendSrv } from 'app/core/services/backend_srv';
import { DashboardSrv } from '../../services/DashboardSrv';
export type DashboardLink = { tags: any; target: string; keepTime: any; includeVars: any };
function dashLinksContainer() {
return {
@@ -16,10 +21,10 @@ function dashLinksContainer() {
}
/** @ngInject */
function dashLink($compile, $sanitize, linkSrv) {
function dashLink($compile: any, $sanitize: any, linkSrv: LinkSrv) {
return {
restrict: 'E',
link: (scope, elem) => {
link: (scope: any, elem: JQuery) => {
const link = scope.link;
const dashboard = scope.dashboard;
@@ -86,10 +91,17 @@ function dashLink($compile, $sanitize, linkSrv) {
export class DashLinksContainerCtrl {
/** @ngInject */
constructor($scope, $rootScope, $q, backendSrv, dashboardSrv, linkSrv) {
constructor(
$scope: any,
$rootScope: any,
$q: IQService,
backendSrv: BackendSrv,
dashboardSrv: DashboardSrv,
linkSrv: LinkSrv
) {
const currentDashId = dashboardSrv.getCurrent().id;
function buildLinks(linkDef) {
function buildLinks(linkDef: any) {
if (linkDef.type === 'dashboards') {
if (!linkDef.tags) {
console.log('Dashboard link missing tag');
@@ -118,6 +130,7 @@ export class DashLinksContainerCtrl {
{
url: linkDef.url,
title: linkDef.title,
// @ts-ignore
icon: iconMap[linkDef.icon],
tooltip: linkDef.tooltip,
target: linkDef.targetBlank ? '_blank' : '_self',
@@ -138,7 +151,7 @@ export class DashLinksContainerCtrl {
});
}
$scope.searchDashboards = (link, limit) => {
$scope.searchDashboards = (link: DashboardLink, limit: any) => {
return backendSrv.search({ tag: link.tags, limit: limit }).then(results => {
return _.reduce(
results,
@@ -161,8 +174,8 @@ export class DashLinksContainerCtrl {
});
};
$scope.fillDropdown = link => {
$scope.searchDashboards(link, 100).then(results => {
$scope.fillDropdown = (link: { searchHits: any }) => {
$scope.searchDashboards(link, 100).then((results: any) => {
_.each(results, hit => {
hit.url = linkSrv.getLinkUrl(hit);
});

View File

@@ -19,7 +19,7 @@ export class DashLinksEditorCtrl {
link: any;
/** @ngInject */
constructor($scope, $rootScope) {
constructor($scope: any, $rootScope: any) {
this.iconMap = iconMap;
this.dashboard.links = this.dashboard.links || [];
this.mode = 'list';
@@ -44,7 +44,7 @@ export class DashLinksEditorCtrl {
this.dashboard.updateSubmenuVisibility();
}
editLink(link) {
editLink(link: any) {
this.link = link;
this.mode = 'edit';
console.log(this.link);
@@ -54,12 +54,12 @@ export class DashLinksEditorCtrl {
this.backToList();
}
moveLink(index, dir) {
moveLink(index: string | number, dir: string | number) {
// @ts-ignore
_.move(this.dashboard.links, index, index + dir);
}
deleteLink(index) {
deleteLink(index: number) {
this.dashboard.links.splice(index, 1);
this.dashboard.updateSubmenuVisibility();
}

View File

@@ -87,7 +87,7 @@ export class DashNav extends PureComponent<Props> {
const { dashboard, $injector } = this.props;
const dashboardSrv = $injector.get('dashboardSrv');
dashboardSrv.starDashboard(dashboard.id, dashboard.meta.isStarred).then(newState => {
dashboardSrv.starDashboard(dashboard.id, dashboard.meta.isStarred).then((newState: any) => {
dashboard.meta.isStarred = newState;
this.forceUpdate();
});

View File

@@ -29,7 +29,7 @@ export interface State {
}
export class DashboardPermissions extends PureComponent<Props, State> {
constructor(props) {
constructor(props: Props) {
super(props);
this.state = {

View File

@@ -4,7 +4,7 @@ import { DashboardRow } from './DashboardRow';
import { PanelModel } from '../../state/PanelModel';
describe('DashboardRow', () => {
let wrapper, panel, dashboardMock;
let wrapper: any, panel: PanelModel, dashboardMock: any;
beforeEach(() => {
dashboardMock = {

View File

@@ -11,7 +11,7 @@ export interface DashboardRowProps {
}
export class DashboardRow extends React.Component<DashboardRowProps, any> {
constructor(props) {
constructor(props: DashboardRowProps) {
super(props);
this.state = {
@@ -32,7 +32,7 @@ export class DashboardRow extends React.Component<DashboardRowProps, any> {
onToggle = () => {
this.props.dashboard.toggleRow(this.props.panel);
this.setState(prevState => {
this.setState((prevState: any) => {
return { collapsed: !prevState.collapsed };
});
};

View File

@@ -4,7 +4,7 @@ import appEvents from 'app/core/app_events';
import { DashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
export class ExportDataModalCtrl {
private data: any[];
private data: any;
private panel: string;
asRows = true;
dateTimeFormat = 'YYYY-MM-DDTHH:mm:ssZ';