From 1b17b7893ffcb940918f06abbcc613d9fd92c59b Mon Sep 17 00:00:00 2001 From: Tobias Skarhed Date: Tue, 25 Jun 2019 09:49:31 +0200 Subject: [PATCH] noImplicitAny: time region manager etc. (#17729) * Fix errors * Wrong branch * minor type fix --- .../grafana-ui/src/utils/moment_wrapper.ts | 3 +++ .../plugins/panel/graph/threshold_manager.ts | 22 ++++++++++--------- .../panel/graph/time_region_manager.ts | 20 +++++++++++------ .../plugins/panel/graph/time_regions_form.ts | 12 +++++----- .../app/plugins/panel/heatmap/axes_editor.ts | 5 ++--- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/packages/grafana-ui/src/utils/moment_wrapper.ts b/packages/grafana-ui/src/utils/moment_wrapper.ts index 755f92a899a..014a6f06e61 100644 --- a/packages/grafana-ui/src/utils/moment_wrapper.ts +++ b/packages/grafana-ui/src/utils/moment_wrapper.ts @@ -50,6 +50,7 @@ export interface DateTimeDuration { export interface DateTime extends Object { add: (amount?: DateTimeInput, unit?: DurationUnit) => DateTime; + set: (unit: DurationUnit, amount: DateTimeInput) => void; diff: (amount: DateTimeInput, unit?: DurationUnit, truncate?: boolean) => number; endOf: (unitOfTime: DurationUnit) => DateTime; format: (formatInput?: FormatInput) => string; @@ -63,9 +64,11 @@ export interface DateTime extends Object { subtract: (amount?: DateTimeInput, unit?: DurationUnit) => DateTime; toDate: () => Date; toISOString: () => string; + isoWeekday: (day?: number | string) => number | string; valueOf: () => number; unix: () => number; utc: () => DateTime; + hour?: () => number; } export const setLocale = (language: string) => { diff --git a/public/app/plugins/panel/graph/threshold_manager.ts b/public/app/plugins/panel/graph/threshold_manager.ts index dcebc45c1e7..e66017aee9a 100644 --- a/public/app/plugins/panel/graph/threshold_manager.ts +++ b/public/app/plugins/panel/graph/threshold_manager.ts @@ -2,6 +2,7 @@ import 'vendor/flot/jquery.flot'; import $ from 'jquery'; import _ from 'lodash'; import { getColorFromHexRgbOrName } from '@grafana/ui'; +import { PanelCtrl } from 'app/features/panel/panel_ctrl'; export class ThresholdManager { plot: any; @@ -11,9 +12,9 @@ export class ThresholdManager { needsCleanup: boolean; hasSecondYAxis: any; - constructor(private panelCtrl) {} + constructor(private panelCtrl: PanelCtrl) {} - getHandleHtml(handleIndex, model, valueStr) { + getHandleHtml(handleIndex: any, model: { colorMode: string }, valueStr: any) { let stateClass = model.colorMode; if (model.colorMode === 'custom') { stateClass = 'critical'; @@ -30,17 +31,17 @@ export class ThresholdManager { `; } - initDragging(evt) { + initDragging(evt: any) { const handleElem = $(evt.currentTarget).parents('.alert-handle-wrapper'); const handleIndex = $(evt.currentTarget).data('handleIndex'); - let lastY = null; - let posTop; + let lastY: number = null; + let posTop: number; const plot = this.plot; const panelCtrl = this.panelCtrl; const model = this.thresholds[handleIndex]; - function dragging(evt) { + function dragging(evt: any) { if (lastY === null) { lastY = evt.clientY; } else { @@ -84,7 +85,7 @@ export class ThresholdManager { this.needsCleanup = false; } - renderHandle(handleIndex, defaultHandleTopPos) { + renderHandle(handleIndex: number, defaultHandleTopPos: number) { const model = this.thresholds[handleIndex]; const value = model.value; let valueStr = value; @@ -107,10 +108,11 @@ export class ThresholdManager { } shouldDrawHandles() { + // @ts-ignore return !this.hasSecondYAxis && this.panelCtrl.editingThresholds && this.panelCtrl.panel.thresholds.length > 0; } - prepare(elem, data) { + prepare(elem: JQuery, data: any[]) { this.hasSecondYAxis = false; for (let i = 0; i < data.length; i++) { if (data[i].yaxis > 1) { @@ -127,7 +129,7 @@ export class ThresholdManager { } } - draw(plot) { + draw(plot: any) { this.thresholds = this.panelCtrl.panel.thresholds; this.plot = plot; this.placeholder = plot.getPlaceholder(); @@ -154,7 +156,7 @@ export class ThresholdManager { this.needsCleanup = true; } - addFlotOptions(options, panel) { + addFlotOptions(options: any, panel: any) { if (!panel.thresholds || panel.thresholds.length === 0) { return; } diff --git a/public/app/plugins/panel/graph/time_region_manager.ts b/public/app/plugins/panel/graph/time_region_manager.ts index 2b65c396300..ca53ac7197a 100644 --- a/public/app/plugins/panel/graph/time_region_manager.ts +++ b/public/app/plugins/panel/graph/time_region_manager.ts @@ -1,14 +1,14 @@ import 'vendor/flot/jquery.flot'; import _ from 'lodash'; -import { GrafanaThemeType, getColorFromHexRgbOrName } from '@grafana/ui'; -import { dateTime } from '@grafana/ui/src/utils/moment_wrapper'; +import { GrafanaThemeType, getColorFromHexRgbOrName, AbsoluteTimeRange } from '@grafana/ui'; +import { dateTime, DateTime } from '@grafana/ui/src/utils/moment_wrapper'; type TimeRegionColorDefinition = { fill: string; line: string; }; -export const colorModes = { +export const colorModes: any = { gray: { themeDependent: true, title: 'Gray', @@ -88,9 +88,15 @@ export class TimeRegionManager { to: dateTime(this.panelCtrl.range.to).utc(), }; - let i, hRange, timeRegion, regions, fromStart, fromEnd, timeRegionColor: TimeRegionColorDefinition; + let i: number, + hRange: { from: any; to: any }, + timeRegion: any, + regions: AbsoluteTimeRange[], + fromStart: DateTime, + fromEnd: DateTime, + timeRegionColor: TimeRegionColorDefinition; - const timeRegionsCopy = panel.timeRegions.map(a => ({ ...a })); + const timeRegionsCopy = panel.timeRegions.map((a: any) => ({ ...a })); for (i = 0; i < timeRegionsCopy.length; i++) { timeRegion = timeRegionsCopy[i]; @@ -222,9 +228,9 @@ export class TimeRegionManager { } } - parseTimeRange(str) { + parseTimeRange(str: string) { const timeRegex = /^([\d]+):?(\d{2})?/; - const result = { h: null, m: null }; + const result: any = { h: null, m: null }; const match = timeRegex.exec(str); if (!match) { diff --git a/public/app/plugins/panel/graph/time_regions_form.ts b/public/app/plugins/panel/graph/time_regions_form.ts index ac5ac50f068..c7e3cdcea87 100644 --- a/public/app/plugins/panel/graph/time_regions_form.ts +++ b/public/app/plugins/panel/graph/time_regions_form.ts @@ -8,7 +8,7 @@ export class TimeRegionFormCtrl { colorModes: any; /** @ngInject */ - constructor($scope) { + constructor($scope: any) { this.panel = this.panelCtrl.panel; const unbindDestroy = $scope.$on('$destroy', () => { @@ -42,20 +42,20 @@ export class TimeRegionFormCtrl { this.panelCtrl.render(); } - removeTimeRegion(index) { + removeTimeRegion(index: number) { this.panel.timeRegions.splice(index, 1); this.panelCtrl.render(); } - onFillColorChange(index) { - return newColor => { + onFillColorChange(index: number) { + return (newColor: string) => { this.panel.timeRegions[index].fillColor = newColor; this.render(); }; } - onLineColorChange(index) { - return newColor => { + onLineColorChange(index: number) { + return (newColor: string) => { this.panel.timeRegions[index].lineColor = newColor; this.render(); }; diff --git a/public/app/plugins/panel/heatmap/axes_editor.ts b/public/app/plugins/panel/heatmap/axes_editor.ts index cec3df9f8c5..7a77ea718d9 100644 --- a/public/app/plugins/panel/heatmap/axes_editor.ts +++ b/public/app/plugins/panel/heatmap/axes_editor.ts @@ -1,5 +1,4 @@ import kbn from 'app/core/utils/kbn'; - export class AxesEditorCtrl { panel: any; panelCtrl: any; @@ -9,7 +8,7 @@ export class AxesEditorCtrl { yBucketBoundModes: any; /** @ngInject */ - constructor($scope, uiSegmentSrv) { + constructor($scope: any, uiSegmentSrv: any) { $scope.editor = this; this.panelCtrl = $scope.ctrl; this.panel = this.panelCtrl.panel; @@ -36,7 +35,7 @@ export class AxesEditorCtrl { }; } - setUnitFormat(subItem) { + setUnitFormat(subItem: any) { this.panel.yAxis.format = subItem.value; this.panelCtrl.render(); }