From 13e3308959e84e7dd0ac5a091edfcc4e4b427d83 Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Tue, 20 Jun 2023 17:13:49 +0100 Subject: [PATCH] Chore: some type fixes (#69860) * some type fixes * restore empty object * undo 1 fix for now * commit betterer update * explicitly type slug and uid as string | undefined --- .betterer.results | 79 +++---------------- .../components/AnnotationResultMapper.tsx | 2 +- .../annotations/executeAnnotationQuery.ts | 4 +- .../annotations/standardAnnotationSupport.ts | 6 +- .../app/features/canvas/elements/notFound.tsx | 8 +- .../PanelEditor/getVisualizationOptions.tsx | 4 +- .../components/ShareModal/ShareSnapshot.tsx | 14 +++- .../dashboard/dashgrid/DashboardGrid.tsx | 15 +++- .../dashboard/services/DashboardLoaderSrv.ts | 14 ++-- .../app/features/dashboard/state/reducers.ts | 6 +- .../dashboard/utils/getPanelMenu.test.ts | 14 ++-- .../features/dashboard/utils/getPanelMenu.ts | 26 +++--- .../features/dashboard/utils/panelMerge.ts | 14 ++-- .../app/features/datasources/state/actions.ts | 14 +--- public/app/features/dimensions/utils.ts | 2 +- public/app/features/explore/ElapsedTime.tsx | 2 +- .../TraceTimelineViewer/ListView/index.tsx | 8 +- 17 files changed, 91 insertions(+), 141 deletions(-) diff --git a/.betterer.results b/.betterer.results index 47a02b7cd96..11f9acdc59b 100644 --- a/.betterer.results +++ b/.betterer.results @@ -2006,23 +2006,13 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "4"], [0, 0, 0, "Do not use any type assertions.", "5"] ], - "public/app/features/annotations/components/AnnotationResultMapper.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/annotations/events_processing.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/features/annotations/executeAnnotationQuery.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/annotations/standardAnnotationSupport.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Do not use any type assertions.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"] + [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], "public/app/features/canvas/element.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -2031,9 +2021,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "3"], [0, 0, 0, "Unexpected any. Specify a different type.", "4"] ], - "public/app/features/canvas/elements/notFound.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/canvas/runtime/element.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], @@ -2161,9 +2148,7 @@ exports[`better eslint`] = { "public/app/features/dashboard/components/PanelEditor/getVisualizationOptions.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"] + [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], "public/app/features/dashboard/components/PanelEditor/types.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -2198,9 +2183,6 @@ exports[`better eslint`] = { "public/app/features/dashboard/components/ShareModal/ShareExport.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/features/dashboard/components/ShareModal/ShareSnapshot.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/dashboard/components/TransformationsEditor/TransformationEditor.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"], @@ -2231,8 +2213,7 @@ exports[`better eslint`] = { [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "4"] ], "public/app/features/dashboard/dashgrid/DashboardGrid.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] + [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/features/dashboard/dashgrid/DashboardPanel.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -2255,9 +2236,7 @@ exports[`better eslint`] = { "public/app/features/dashboard/services/DashboardLoaderSrv.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"] + [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], "public/app/features/dashboard/services/PublicDashboardDataSource.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -2439,48 +2418,22 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/features/dashboard/state/reducers.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] + [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/features/dashboard/utils/getPanelMenu.test.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"] + [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/features/dashboard/utils/getPanelMenu.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], + [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"], - [0, 0, 0, "Unexpected any. Specify a different type.", "7"], - [0, 0, 0, "Unexpected any. Specify a different type.", "8"], - [0, 0, 0, "Unexpected any. Specify a different type.", "9"], - [0, 0, 0, "Do not use any type assertions.", "10"], - [0, 0, 0, "Unexpected any. Specify a different type.", "11"], - [0, 0, 0, "Unexpected any. Specify a different type.", "12"], - [0, 0, 0, "Unexpected any. Specify a different type.", "13"], - [0, 0, 0, "Unexpected any. Specify a different type.", "14"], - [0, 0, 0, "Do not use any type assertions.", "15"] + [0, 0, 0, "Do not use any type assertions.", "2"] ], "public/app/features/dashboard/utils/panelMerge.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], + [0, 0, 0, "Unexpected any. Specify a different type.", "2"], [0, 0, 0, "Do not use any type assertions.", "3"], - [0, 0, 0, "Do not use any type assertions.", "4"], - [0, 0, 0, "Do not use any type assertions.", "5"], - [0, 0, 0, "Do not use any type assertions.", "6"], - [0, 0, 0, "Unexpected any. Specify a different type.", "7"], - [0, 0, 0, "Do not use any type assertions.", "8"], - [0, 0, 0, "Unexpected any. Specify a different type.", "9"], - [0, 0, 0, "Unexpected any. Specify a different type.", "10"], - [0, 0, 0, "Unexpected any. Specify a different type.", "11"] + [0, 0, 0, "Unexpected any. Specify a different type.", "4"] ], "public/app/features/datasources/components/BasicSettings.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] @@ -2508,10 +2461,8 @@ exports[`better eslint`] = { ], "public/app/features/datasources/state/actions.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"] + [0, 0, 0, "Do not use any type assertions.", "1"], + [0, 0, 0, "Do not use any type assertions.", "2"] ], "public/app/features/datasources/state/navModel.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], @@ -2550,11 +2501,7 @@ exports[`better eslint`] = { ], "public/app/features/dimensions/utils.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"] - ], - "public/app/features/explore/ElapsedTime.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/app/features/explore/ExplorePage.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] diff --git a/public/app/features/annotations/components/AnnotationResultMapper.tsx b/public/app/features/annotations/components/AnnotationResultMapper.tsx index e59a758f094..bb8cdb39b52 100644 --- a/public/app/features/annotations/components/AnnotationResultMapper.tsx +++ b/public/app/features/annotations/components/AnnotationResultMapper.tsx @@ -130,7 +130,7 @@ export class AnnotationFieldMapper extends PureComponent { let value = first ? first[row.key] : ''; if (value && row.key.startsWith('time')) { const fmt = getValueFormat('dateTimeAsIso'); - value = formattedValueToString(fmt(value as number)); + value = formattedValueToString(fmt(value)); } if (value === null || value === undefined) { value = ''; // empty string diff --git a/public/app/features/annotations/executeAnnotationQuery.ts b/public/app/features/annotations/executeAnnotationQuery.ts index 171b713d383..eced30eb074 100644 --- a/public/app/features/annotations/executeAnnotationQuery.ts +++ b/public/app/features/annotations/executeAnnotationQuery.ts @@ -1,7 +1,7 @@ import { Observable, of } from 'rxjs'; import { map, mergeMap } from 'rxjs/operators'; -import { CoreApp, DataQueryRequest, DataSourceApi, rangeUtil, ScopedVars } from '@grafana/data'; +import { AnnotationQuery, CoreApp, DataQueryRequest, DataSourceApi, rangeUtil, ScopedVars } from '@grafana/data'; import { runRequest } from '../query/state/runRequest'; @@ -16,7 +16,7 @@ function getNextRequestId() { export function executeAnnotationQuery( options: AnnotationQueryOptions, datasource: DataSourceApi, - savedJsonAnno: any + savedJsonAnno: AnnotationQuery ): Observable { const processor = { ...standardAnnotationSupport, diff --git a/public/app/features/annotations/standardAnnotationSupport.ts b/public/app/features/annotations/standardAnnotationSupport.ts index 2eb298a04e4..c1782a691a3 100644 --- a/public/app/features/annotations/standardAnnotationSupport.ts +++ b/public/app/features/annotations/standardAnnotationSupport.ts @@ -35,7 +35,7 @@ export const standardAnnotationSupport: AnnotationSupport = { mappings: {}, }; } - return json as AnnotationQuery; + return json; }, /** @@ -218,7 +218,7 @@ export function getAnnotationsFromData( }; for (const f of fields) { - let v: any = undefined; + let v = undefined; if (f.text) { v = f.text; // TODO support templates! @@ -236,7 +236,7 @@ export function getAnnotationsFromData( if (f.split && typeof v === 'string') { v = v.split(','); } - (anno as any)[f.key] = v; + anno[f.key] = v; } } diff --git a/public/app/features/canvas/elements/notFound.tsx b/public/app/features/canvas/elements/notFound.tsx index 41dab2ebb24..a0502d28d58 100644 --- a/public/app/features/canvas/elements/notFound.tsx +++ b/public/app/features/canvas/elements/notFound.tsx @@ -2,11 +2,7 @@ import React, { PureComponent } from 'react'; import { CanvasElementItem, CanvasElementProps } from '../element'; -interface NotFoundConfig { - orig?: any; -} - -class NotFoundDisplay extends PureComponent> { +class NotFoundDisplay extends PureComponent { render() { const { config } = this.props; return ( @@ -18,7 +14,7 @@ class NotFoundDisplay extends PureComponent> } } -export const notFoundItem: CanvasElementItem = { +export const notFoundItem: CanvasElementItem = { id: 'not-found', name: 'Not found', description: 'Display when element type is not found in the registry', diff --git a/public/app/features/dashboard/components/PanelEditor/getVisualizationOptions.tsx b/public/app/features/dashboard/components/PanelEditor/getVisualizationOptions.tsx index 49a86abe58f..0c4264a63cd 100644 --- a/public/app/features/dashboard/components/PanelEditor/getVisualizationOptions.tsx +++ b/public/app/features/dashboard/components/PanelEditor/getVisualizationOptions.tsx @@ -152,10 +152,10 @@ export function fillOptionsPaneItems( supplier: PanelOptionsSupplier, access: NestedValueAccess, getOptionsPaneCategory: categoryGetter, - context: StandardEditorContext, + context: StandardEditorContext, parentCategory?: OptionsPaneCategoryDescriptor ) { - const builder = new PanelOptionsEditorBuilder(); + const builder = new PanelOptionsEditorBuilder(); supplier(builder, context); for (const pluginOption of builder.getItems()) { diff --git a/public/app/features/dashboard/components/ShareModal/ShareSnapshot.tsx b/public/app/features/dashboard/components/ShareModal/ShareSnapshot.tsx index a7bb549f9a4..efdb58c4a13 100644 --- a/public/app/features/dashboard/components/ShareModal/ShareSnapshot.tsx +++ b/public/app/features/dashboard/components/ShareModal/ShareSnapshot.tsx @@ -155,10 +155,16 @@ export class ShareSnapshot extends PureComponent { }); // remove template queries - dash.getVariables().forEach((variable: any) => { - variable.query = ''; - variable.options = variable.current ? [variable.current] : []; - variable.refresh = VariableRefresh.never; + dash.getVariables().forEach((variable) => { + if ('query' in variable) { + variable.query = ''; + } + if ('options' in variable) { + variable.options = variable.current ? [variable.current] : []; + } + if ('refresh' in variable) { + variable.refresh = VariableRefresh.never; + } }); // snapshot single panel diff --git a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx index e158a138188..6a77ad4eee4 100644 --- a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx @@ -272,10 +272,10 @@ export class DashboardGrid extends PureComponent { } } -interface GrafanaGridItemProps extends Record { +interface GrafanaGridItemProps extends React.HTMLAttributes { gridWidth?: number; gridPos?: GridPos; - isViewing: string; + isViewing: boolean; windowHeight: number; windowWidth: number; children: any; @@ -306,8 +306,15 @@ const GrafanaGridItem = React.forwardRef(( style.width = '100%'; } else { // Normal grid layout. The grid framework passes width and height directly to children as style props. - width = parseFloat(props.style.width); - height = parseFloat(props.style.height); + if (props.style) { + const { width: styleWidth, height: styleHeight } = props.style; + if (styleWidth != null) { + width = typeof styleWidth === 'number' ? styleWidth : parseFloat(styleWidth); + } + if (styleHeight != null) { + height = typeof styleHeight === 'number' ? styleHeight : parseFloat(styleHeight); + } + } } // props.children[0] is our main children. RGL adds the drag handle at props.children[1] diff --git a/public/app/features/dashboard/services/DashboardLoaderSrv.ts b/public/app/features/dashboard/services/DashboardLoaderSrv.ts index 9633c06020d..b11de1ddeda 100644 --- a/public/app/features/dashboard/services/DashboardLoaderSrv.ts +++ b/public/app/features/dashboard/services/DashboardLoaderSrv.ts @@ -34,18 +34,18 @@ export class DashboardLoaderSrv { }; } - loadDashboard(type: UrlQueryValue, slug: any, uid: any): Promise { + loadDashboard(type: UrlQueryValue, slug: string | undefined, uid: string | undefined): Promise { let promise; - if (type === 'script') { + if (type === 'script' && slug) { promise = this._loadScriptedDashboard(slug); - } else if (type === 'snapshot') { + } else if (type === 'snapshot' && slug) { promise = backendSrv.get('/api/snapshots/' + slug).catch(() => { return this._dashboardLoadFailed('Snapshot not found', true); }); - } else if (type === 'ds') { + } else if (type === 'ds' && slug) { promise = this._loadFromDatasource(slug); // explore dashboards as code - } else if (type === 'public') { + } else if (type === 'public' && uid) { promise = backendSrv .getPublicDashboardByUid(uid) .then((result) => { @@ -70,7 +70,7 @@ export class DashboardLoaderSrv { }, }; }); - } else { + } else if (uid) { promise = backendSrv .getDashboardByUid(uid) .then((result) => { @@ -83,6 +83,8 @@ export class DashboardLoaderSrv { .catch(() => { return this._dashboardLoadFailed('Not found', true); }); + } else { + throw new Error('Dashboard uid or slug required'); } promise.then((result: DashboardDTO) => { diff --git a/public/app/features/dashboard/state/reducers.ts b/public/app/features/dashboard/state/reducers.ts index c047aa9051f..71356ec6c24 100644 --- a/public/app/features/dashboard/state/reducers.ts +++ b/public/app/features/dashboard/state/reducers.ts @@ -2,7 +2,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import { PanelPlugin } from '@grafana/data'; import { AngularComponent } from '@grafana/runtime'; -import { Dashboard, defaultDashboard } from '@grafana/schema'; +import { defaultDashboard } from '@grafana/schema'; import { processAclItems } from 'app/core/utils/acl'; import { DashboardAclDTO, DashboardInitError, DashboardInitPhase, DashboardState } from 'app/types'; @@ -38,10 +38,8 @@ const dashboardSlice = createSlice({ state.initPhase = DashboardInitPhase.Failed; state.initError = action.payload; state.getModel = () => { - // TODO this is a type conflict, - // we need to fix the defaultDashboard init type when generated by cue return new DashboardModel( - { ...(defaultDashboard as Dashboard), title: 'Dashboard init failed' }, + { ...defaultDashboard, title: 'Dashboard init failed' }, { canSave: false, canEdit: false } ); }; diff --git a/public/app/features/dashboard/utils/getPanelMenu.test.ts b/public/app/features/dashboard/utils/getPanelMenu.test.ts index d4a16dcbfe2..b5bf987ae18 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.test.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.test.ts @@ -1,3 +1,5 @@ +import { Store } from 'redux'; + import { dateTime, FieldType, @@ -8,7 +10,7 @@ import { PluginExtensionTypes, toDataFrame, } from '@grafana/data'; -import { getPluginExtensions } from '@grafana/runtime'; +import { AngularComponent, getPluginExtensions } from '@grafana/runtime'; import config from 'app/core/config'; import * as actions from 'app/features/explore/state/main'; import { setStore } from 'app/store/store'; @@ -292,9 +294,9 @@ describe('getPanelMenu()', () => { describe('when panel is in view mode', () => { it('should return the correct panel menu items', () => { const getExtendedMenu = () => [{ text: 'Toggle legend', shortcut: 'p l', click: jest.fn() }]; - const ctrl: any = { getExtendedMenu }; - const scope: any = { $$childHead: { ctrl } }; - const angularComponent: any = { getScope: () => scope }; + const ctrl = { getExtendedMenu }; + const scope = { $$childHead: { ctrl } }; + const angularComponent = { getScope: () => scope } as AngularComponent; const panel = new PanelModel({ isViewing: true }); const dashboard = createDashboardModelFixture({}); @@ -363,7 +365,7 @@ describe('getPanelMenu()', () => { const windowOpen = jest.fn(); let event: any; let explore: PanelMenuItem; - let navigateSpy: any; + let navigateSpy: jest.SpyInstance; beforeAll(() => { const panel = new PanelModel({}); @@ -378,7 +380,7 @@ describe('getPanelMenu()', () => { preventDefault: jest.fn(), }; - setStore({ dispatch: jest.fn() } as any); + setStore({ dispatch: jest.fn() } as unknown as Store); }); it('should navigate to url without subUrl', () => { diff --git a/public/app/features/dashboard/utils/getPanelMenu.ts b/public/app/features/dashboard/utils/getPanelMenu.ts index 9396e9ea1af..344001f07ae 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.ts @@ -36,7 +36,7 @@ export function getPanelMenu( panel: PanelModel, angularComponent?: AngularComponent | null ): PanelMenuItem[] { - const onViewPanel = (event: React.MouseEvent) => { + const onViewPanel = (event: React.MouseEvent) => { event.preventDefault(); locationService.partial({ viewPanel: panel.id, @@ -44,7 +44,7 @@ export function getPanelMenu( reportInteraction('dashboards_panelheader_menu', { item: 'view' }); }; - const onEditPanel = (event: React.MouseEvent) => { + const onEditPanel = (event: React.MouseEvent) => { event.preventDefault(); locationService.partial({ editPanel: panel.id, @@ -53,19 +53,19 @@ export function getPanelMenu( reportInteraction('dashboards_panelheader_menu', { item: 'edit' }); }; - const onSharePanel = (event: React.MouseEvent) => { + const onSharePanel = (event: React.MouseEvent) => { event.preventDefault(); sharePanel(dashboard, panel); reportInteraction('dashboards_panelheader_menu', { item: 'share' }); }; - const onAddLibraryPanel = (event: React.MouseEvent) => { + const onAddLibraryPanel = (event: React.MouseEvent) => { event.preventDefault(); addLibraryPanel(dashboard, panel); reportInteraction('dashboards_panelheader_menu', { item: 'createLibraryPanel' }); }; - const onUnlinkLibraryPanel = (event: React.MouseEvent) => { + const onUnlinkLibraryPanel = (event: React.MouseEvent) => { event.preventDefault(); unlinkLibraryPanel(panel); reportInteraction('dashboards_panelheader_menu', { item: 'unlinkLibraryPanel' }); @@ -79,29 +79,29 @@ export function getPanelMenu( reportInteraction('dashboards_panelheader_menu', { item: 'inspect', tab: tab ?? InspectTab.Data }); }; - const onMore = (event: React.MouseEvent) => { + const onMore = (event: React.MouseEvent) => { event.preventDefault(); }; - const onDuplicatePanel = (event: React.MouseEvent) => { + const onDuplicatePanel = (event: React.MouseEvent) => { event.preventDefault(); duplicatePanel(dashboard, panel); reportInteraction('dashboards_panelheader_menu', { item: 'duplicate' }); }; - const onCopyPanel = (event: React.MouseEvent) => { + const onCopyPanel = (event: React.MouseEvent) => { event.preventDefault(); copyPanel(panel); reportInteraction('dashboards_panelheader_menu', { item: 'copy' }); }; - const onRemovePanel = (event: React.MouseEvent) => { + const onRemovePanel = (event: React.MouseEvent) => { event.preventDefault(); removePanel(dashboard, panel, true); reportInteraction('dashboards_panelheader_menu', { item: 'remove' }); }; - const onNavigateToExplore = (event: React.MouseEvent) => { + const onNavigateToExplore = (event: React.MouseEvent) => { event.preventDefault(); const openInNewWindow = event.ctrlKey || event.metaKey ? (url: string) => window.open(`${config.appSubUrl}${url}`) : undefined; @@ -161,20 +161,20 @@ export function getPanelMenu( if (panel.plugin && !panel.plugin.meta.skipDataQuery) { inspectMenu.push({ text: t('panel.header-menu.inspect-data', `Data`), - onClick: (e: React.MouseEvent) => onInspectPanel(InspectTab.Data), + onClick: (e: React.MouseEvent) => onInspectPanel(InspectTab.Data), }); if (dashboard.meta.canEdit) { inspectMenu.push({ text: t('panel.header-menu.query', `Query`), - onClick: (e: React.MouseEvent) => onInspectPanel(InspectTab.Query), + onClick: (e: React.MouseEvent) => onInspectPanel(InspectTab.Query), }); } } inspectMenu.push({ text: t('panel.header-menu.inspect-json', `Panel JSON`), - onClick: (e: React.MouseEvent) => onInspectPanel(InspectTab.JSON), + onClick: (e: React.MouseEvent) => onInspectPanel(InspectTab.JSON), }); menu.push({ diff --git a/public/app/features/dashboard/utils/panelMerge.ts b/public/app/features/dashboard/utils/panelMerge.ts index 946d3177cf0..3e777c73d26 100644 --- a/public/app/features/dashboard/utils/panelMerge.ts +++ b/public/app/features/dashboard/utils/panelMerge.ts @@ -16,14 +16,14 @@ const mutableKeys = new Set(['gridPos', 'title', 'description' export function mergePanels(current: PanelModel[], data: IPanelModel[]): PanelMergeInfo { const panels: PanelModel[] = []; - const info = { + const info: PanelMergeInfo = { changed: false, actions: { - add: [] as number[], - remove: [] as number[], - replace: [] as number[], - update: [] as number[], - noop: [] as number[], + add: [], + remove: [], + replace: [], + update: [], + noop: [], }, panels, }; @@ -110,7 +110,7 @@ export function mergePanels(current: PanelModel[], data: IPanelModel[]): PanelMe } // Since +- Infinity are saved as null in JSON, we need to make them equal here also -function infinityEqualsNull(a: any, b: any) { +function infinityEqualsNull(a: unknown, b: unknown) { if (a == null && (b === Infinity || b === -Infinity || b == null)) { return true; } diff --git a/public/app/features/datasources/state/actions.ts b/public/app/features/datasources/state/actions.ts index c3b27282f82..c7afe01ae7e 100644 --- a/public/app/features/datasources/state/actions.ts +++ b/public/app/features/datasources/state/actions.ts @@ -1,4 +1,4 @@ -import { DataSourcePluginMeta, DataSourceSettings, locationUtil } from '@grafana/data'; +import { DataSourcePluginMeta, DataSourceSettings, locationUtil, TestDataSourceResponse } from '@grafana/data'; import { config, DataSourceWithBackend, @@ -79,14 +79,8 @@ const parseHealthCheckError = (errorResponse: any): parseDataSourceSaveResponse return { message, details }; }; -const parseHealthCheckSuccess = (response: any): parseDataSourceSaveResponse => { - let message: string | undefined; - let status: string; - let details: { message?: string; verboseMessage?: string }; - - status = response.status; - message = response.message; - details = response.details; +const parseHealthCheckSuccess = (response: TestDataSourceResponse): parseDataSourceSaveResponse => { + const { details, message, status } = response; return { status, message, details }; }; @@ -282,7 +276,7 @@ export function updateDataSource(dataSource: DataSourceSettings) { ) => { try { await api.updateDataSource(dataSource); - } catch (err: any) { + } catch (err) { const formattedError = parseHealthCheckError(err); dispatch(testDataSourceFailed(formattedError)); diff --git a/public/app/features/dimensions/utils.ts b/public/app/features/dimensions/utils.ts index 31937dc7b3b..e8c0c053f32 100644 --- a/public/app/features/dimensions/utils.ts +++ b/public/app/features/dimensions/utils.ts @@ -120,7 +120,7 @@ export function getLastNotNullFieldValue(field: Field): T { if (calcs) { const v = calcs[ReducerID.lastNotNull]; if (v != null) { - return v as T; + return v; } } diff --git a/public/app/features/explore/ElapsedTime.tsx b/public/app/features/explore/ElapsedTime.tsx index cbe427b04af..9996100f93a 100644 --- a/public/app/features/explore/ElapsedTime.tsx +++ b/public/app/features/explore/ElapsedTime.tsx @@ -8,7 +8,7 @@ const INTERVAL = 150; export interface ElapsedTimeProps extends Omit { // Use this to reset the timer. Any value is allowed just need to be !== from the previous. // Keep in mind things like [] !== [] or {} !== {}. - resetKey?: any; + resetKey?: unknown; } export const ElapsedTime = ({ resetKey, humanize, className }: ElapsedTimeProps) => { diff --git a/public/app/features/explore/TraceView/components/TraceTimelineViewer/ListView/index.tsx b/public/app/features/explore/TraceView/components/TraceTimelineViewer/ListView/index.tsx index 5074163be6b..346f84469bc 100644 --- a/public/app/features/explore/TraceView/components/TraceTimelineViewer/ListView/index.tsx +++ b/public/app/features/explore/TraceView/components/TraceTimelineViewer/ListView/index.tsx @@ -195,8 +195,7 @@ export default class ListView extends React.Component { this._htmlTopOffset = -1; this._windowScrollListenerAdded = false; // _htmlElm is only relevant if props.windowScroller is true - // eslint-disable-next-line - this._htmlElm = document.documentElement as any; + this._htmlElm = document.documentElement; this._wrapperElm = undefined; this._itemHolderElm = undefined; } @@ -379,8 +378,7 @@ export default class ListView extends React.Component { const nodes = this._itemHolderElm.childNodes; const max = nodes.length; for (let i = 0; i < max; i++) { - // eslint-disable-next-line - const node: HTMLElement = nodes[i] as any; + const node = nodes[i] as HTMLElement; // use `.getAttribute(...)` instead of `.dataset` for jest / JSDOM const itemKey = node.getAttribute('data-item-key'); if (!itemKey) { @@ -492,7 +490,7 @@ export default class ListView extends React.Component { wrapperProps.style.overflowY = 'auto'; } const scrollerStyle = { - position: 'relative' as 'relative', + position: 'relative' as const, height: this._yPositions.getEstimatedHeight(), }; return (