diff --git a/.betterer.results b/.betterer.results index 16780915d45..2730e52414c 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1,5 +1,5 @@ // BETTERER RESULTS V2. -// +// // If this file contains merge conflicts, use `betterer merge` to automatically resolve them: // https://phenomnomnominal.github.io/betterer/docs/results-file/#merge // @@ -293,17 +293,14 @@ exports[`better eslint`] = { ], "packages/grafana-data/src/types/fieldOverrides.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.", "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, "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.", "8"] ], "packages/grafana-data/src/types/flot.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -435,8 +432,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "packages/grafana-data/src/utils/location.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, "Do not use any type assertions.", "0"] ], "packages/grafana-data/src/utils/url.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -578,10 +574,7 @@ exports[`better eslint`] = { ], "packages/grafana-runtime/src/utils/DataSourceWithBackend.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"], - [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.", "1"] ], "packages/grafana-runtime/src/utils/queryResponse.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -1184,21 +1177,13 @@ exports[`better eslint`] = { "public/app/core/utils/deferred.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/core/utils/explore.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/core/utils/fetch.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, "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, "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.", "5"] ], "public/app/core/utils/flatten.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -1214,12 +1199,8 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/core/utils/ticks.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, "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.", "0"], + [0, 0, 0, "Do not use any type assertions.", "1"] ], "public/app/core/utils/tracing.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -2461,9 +2442,7 @@ exports[`better eslint`] = { ], "public/app/features/dashboard-scene/utils/DashboardModelCompatibilityWrapper.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, "Do not use any type assertions.", "3"] + [0, 0, 0, "Do not use any type assertions.", "1"] ], "public/app/features/dashboard-scene/utils/test-utils.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], @@ -4184,8 +4163,7 @@ exports[`better eslint`] = { ], "public/app/features/query/state/PanelQueryRunner.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, "Do not use any type assertions.", "1"] ], "public/app/features/query/state/runRequest.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -4204,9 +4182,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "10"], [0, 0, 0, "Unexpected any. Specify a different type.", "11"] ], - "public/app/features/sandbox/TestStuffPage.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/search/page/components/ActionRow.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], [0, 0, 0, "Styles should be written using objects.", "1"] @@ -4308,9 +4283,7 @@ exports[`better eslint`] = { ], "public/app/features/storage/storage.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, "Unexpected any. Specify a different type.", "3"] + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/app/features/teams/TeamGroupSync.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -4385,8 +4358,7 @@ exports[`better eslint`] = { ], "public/app/features/transformers/calculateHeatmap/heatmap.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"] + [0, 0, 0, "Do not use any type assertions.", "1"] ], "public/app/features/transformers/configFromQuery/ConfigFromQueryTransformerEditor.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] @@ -4398,9 +4370,7 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "0"] ], "public/app/features/transformers/editors/CalculateFieldTransformerEditor/WindowOptionsEditor.tsx: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, "Do not use any type assertions.", "0"] ], "public/app/features/transformers/editors/ConvertFieldTypeTransformerEditor.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -4495,9 +4465,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], - "public/app/features/variables/adhoc/actions.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/variables/adhoc/picker/AdHocFilterRenderer.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], diff --git a/packages/grafana-data/src/types/fieldOverrides.ts b/packages/grafana-data/src/types/fieldOverrides.ts index dad3547523c..1ca74a3be06 100644 --- a/packages/grafana-data/src/types/fieldOverrides.ts +++ b/packages/grafana-data/src/types/fieldOverrides.ts @@ -46,8 +46,7 @@ export interface SystemConfigOverrideRule extends ConfigOverrideRule { */ export function isSystemOverrideWithRef(ref: string) { return (override: ConfigOverrideRule): override is T => { - const overrideAs = override as T; - return overrideAs.__systemRef === ref; + return '__systemRef' in override && override.__systemRef === ref; }; } @@ -58,7 +57,7 @@ export function isSystemOverrideWithRef(ref: * @internal */ export const isSystemOverride = (override: ConfigOverrideRule): override is SystemConfigOverrideRule => { - return typeof (override as SystemConfigOverrideRule)?.__systemRef === 'string'; + return '__systemRef' in override && typeof override.__systemRef === 'string'; }; export interface FieldConfigSource { @@ -69,7 +68,7 @@ export interface FieldConfigSource { overrides: ConfigOverrideRule[]; } -export interface FieldOverrideContext extends StandardEditorContext { +export interface FieldOverrideContext extends StandardEditorContext { field?: Field; dataFrameIndex?: number; // The index for the selected field frame } diff --git a/packages/grafana-data/src/utils/location.ts b/packages/grafana-data/src/utils/location.ts index 44d42f247a5..5c0a2167025 100644 --- a/packages/grafana-data/src/utils/location.ts +++ b/packages/grafana-data/src/utils/location.ts @@ -69,7 +69,7 @@ const assureBaseUrl = (url: string): string => { * @param searchParamsToUpdate * @returns */ -const getUrlForPartial = (location: Location, searchParamsToUpdate: UrlQueryMap) => { +const getUrlForPartial = (location: Location, searchParamsToUpdate: UrlQueryMap) => { const searchParams = urlUtil.parseKeyValue( location.search.startsWith('?') ? location.search.substring(1) : location.search ); diff --git a/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts b/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts index 7085f0dc47a..4f236a28744 100644 --- a/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts +++ b/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts @@ -268,7 +268,7 @@ class DataSourceWithBackend< * Apply template variables for explore */ interpolateVariablesInQueries(queries: TQuery[], scopedVars: ScopedVars, filters?: AdHocVariableFilter[]): TQuery[] { - return queries.map((q) => this.applyTemplateVariables(q, scopedVars, filters) as TQuery); + return queries.map((q) => this.applyTemplateVariables(q, scopedVars, filters)); } /** @@ -290,7 +290,7 @@ class DataSourceWithBackend< * * @virtual */ - applyTemplateVariables(query: TQuery, scopedVars: ScopedVars, filters?: AdHocVariableFilter[]): Record { + applyTemplateVariables(query: TQuery, scopedVars: ScopedVars, filters?: AdHocVariableFilter[]) { return query; } @@ -323,7 +323,7 @@ class DataSourceWithBackend< /** * Send a POST request to the datasource resource path */ - async postResource( + async postResource( path: string, data?: BackendSrvRequest['data'], options?: Partial diff --git a/public/app/core/specs/ticks.test.ts b/public/app/core/specs/ticks.test.ts index 81ea8601e4f..727be9f7a8f 100644 --- a/public/app/core/specs/ticks.test.ts +++ b/public/app/core/specs/ticks.test.ts @@ -1,27 +1,6 @@ import * as ticks from '../utils/ticks'; describe('ticks', () => { - describe('getFlotTickDecimals()', () => { - const axis = { - min: null, - max: null, - }; - - it('should calculate decimals precision based on graph height', () => { - let dec = ticks.getFlotTickDecimals(0, 10, axis, 200); - expect(dec.tickDecimals).toBe(1); - expect(dec.scaledDecimals).toBe(1); - - dec = ticks.getFlotTickDecimals(0, 100, axis, 200); - expect(dec.tickDecimals).toBe(0); - expect(dec.scaledDecimals).toBe(-1); - - dec = ticks.getFlotTickDecimals(0, 1, axis, 200); - expect(dec.tickDecimals).toBe(2); - expect(dec.scaledDecimals).toBe(3); - }); - }); - describe('getStringPrecision()', () => { it('"3.12" should return 2', () => { expect(ticks.getStringPrecision('3.12')).toBe(2); diff --git a/public/app/core/utils/explore.ts b/public/app/core/utils/explore.ts index 912189120e7..49fff84b18b 100644 --- a/public/app/core/utils/explore.ts +++ b/public/app/core/utils/explore.ts @@ -263,12 +263,11 @@ const validKeys = ['refId', 'key', 'context', 'datasource']; export function hasNonEmptyQuery(queries: TQuery[]): boolean { return ( queries && - queries.some((query: any) => { - const keys = Object.keys(query) - .filter((key) => validKeys.indexOf(key) === -1) - .map((k) => query[k]) - .filter((v) => v); - return keys.length > 0; + queries.some((query) => { + const entries = Object.entries(query) + .filter(([key, _]) => validKeys.indexOf(key) === -1) + .filter(([_, value]) => value); + return entries.length > 0; }) ); } diff --git a/public/app/core/utils/fetch.ts b/public/app/core/utils/fetch.ts index f011ae348b9..49253f74a31 100644 --- a/public/app/core/utils/fetch.ts +++ b/public/app/core/utils/fetch.ts @@ -103,23 +103,29 @@ export async function parseResponseBody( if (responseType) { switch (responseType) { case 'arraybuffer': - return response.arrayBuffer() as any; + // this specifically returns a Promise + // TODO refactor this function to remove the type assertions + return response.arrayBuffer() as Promise; case 'blob': - return response.blob() as any; + // this specifically returns a Promise + // TODO refactor this function to remove the type assertions + return response.blob() as Promise; case 'json': // An empty string is not a valid JSON. // Sometimes (unfortunately) our APIs declare their Content-Type as JSON, however they return an empty body. if (response.headers.get('Content-Length') === '0') { console.warn(`${response.url} returned an invalid JSON`); - return {} as unknown as T; + return {} as T; } return await response.json(); case 'text': - return response.text() as any; + // this specifically returns a Promise + // TODO refactor this function to remove the type assertions + return response.text() as Promise; } } @@ -127,7 +133,7 @@ export async function parseResponseBody( try { return JSON.parse(textData); // majority of the requests this will be something that can be parsed } catch {} - return textData as any; + return textData as T; } function serializeParams(data: Record): string { diff --git a/public/app/core/utils/ticks.ts b/public/app/core/utils/ticks.ts index 5f2239a4d9d..5b65bb22a0f 100644 --- a/public/app/core/utils/ticks.ts +++ b/public/app/core/utils/ticks.ts @@ -30,127 +30,6 @@ export function getScaledDecimals(decimals: number, tickSize: number) { return decimals - Math.floor(Math.log(tickSize) / Math.LN10); } -/** - * Calculate tick size based on min and max values, number of ticks and precision. - * Implementation from Flot. - * @param min Axis minimum - * @param max Axis maximum - * @param noTicks Number of ticks - * @param tickDecimals Tick decimal precision - */ -export function getFlotTickSize(min: number, max: number, noTicks: number, tickDecimals: number) { - const delta = (max - min) / noTicks; - let dec = -Math.floor(Math.log(delta) / Math.LN10); - const maxDec = tickDecimals; - - const magn = Math.pow(10, -dec); - const norm = delta / magn; // norm is between 1.0 and 10.0 - let size; - - if (norm < 1.5) { - size = 1; - } else if (norm < 3) { - size = 2; - // special case for 2.5, requires an extra decimal - if (norm > 2.25 && (maxDec == null || dec + 1 <= maxDec)) { - size = 2.5; - ++dec; - } - } else if (norm < 7.5) { - size = 5; - } else { - size = 10; - } - - size *= magn; - - return size; -} - -/** - * Calculate axis range (min and max). - * Implementation from Flot. - */ -export function getFlotRange(panelMin: any, panelMax: any, datamin: number, datamax: number) { - const autoscaleMargin = 0.02; - - let min = +(panelMin != null ? panelMin : datamin); - let max = +(panelMax != null ? panelMax : datamax); - const delta = max - min; - - if (delta === 0.0) { - // Grafana fix: wide Y min and max using increased wideFactor - // when all series values are the same - const wideFactor = 0.25; - const widen = Math.abs(max === 0 ? 1 : max * wideFactor); - - if (panelMin === null) { - min -= widen; - } - // always widen max if we couldn't widen min to ensure we - // don't fall into min == max which doesn't work - if (panelMax == null || panelMin != null) { - max += widen; - } - } else { - // consider autoscaling - const margin = autoscaleMargin; - if (margin != null) { - if (panelMin == null) { - min -= delta * margin; - // make sure we don't go below zero if all values - // are positive - if (min < 0 && datamin != null && datamin >= 0) { - min = 0; - } - } - if (panelMax == null) { - max += delta * margin; - if (max > 0 && datamax != null && datamax <= 0) { - max = 0; - } - } - } - } - return { min, max }; -} - -/** - * Calculate tick decimals. - * Implementation from Flot. - */ -export function getFlotTickDecimals(datamin: number, datamax: number, axis: { min: any; max: any }, height: number) { - const { min, max } = getFlotRange(axis.min, axis.max, datamin, datamax); - const noTicks = 0.3 * Math.sqrt(height); - const delta = (max - min) / noTicks; - const dec = -Math.floor(Math.log(delta) / Math.LN10); - - const magn = Math.pow(10, -dec); - // norm is between 1.0 and 10.0 - const norm = delta / magn; - let size; - - if (norm < 1.5) { - size = 1; - } else if (norm < 3) { - size = 2; - // special case for 2.5, requires an extra decimal - if (norm > 2.25) { - size = 2.5; - } - } else if (norm < 7.5) { - size = 5; - } else { - size = 10; - } - size *= magn; - - const tickDecimals = Math.max(0, -Math.floor(Math.log(delta) / Math.LN10) + 1); - // grafana addition - const scaledDecimals = tickDecimals - Math.floor(Math.log(size) / Math.LN10); - return { tickDecimals, scaledDecimals }; -} - /** * Format timestamp similar to Grafana graph panel. * @param ticks Number of ticks diff --git a/public/app/features/dashboard-scene/utils/DashboardModelCompatibilityWrapper.ts b/public/app/features/dashboard-scene/utils/DashboardModelCompatibilityWrapper.ts index 5a5d96d57ef..e8dde484099 100644 --- a/public/app/features/dashboard-scene/utils/DashboardModelCompatibilityWrapper.ts +++ b/public/app/features/dashboard-scene/utils/DashboardModelCompatibilityWrapper.ts @@ -272,12 +272,12 @@ class PanelCompatibilityWrapper { uid: SHARED_DASHBOARD_QUERY, type: 'datasource', }, - ...(this._vizPanel.state.$data.state.$data as ShareQueryDataProvider).state.query, + ...this._vizPanel.state.$data.state.$data.state.query, }, ]; } if (this._vizPanel.state.$data.state.$data instanceof SceneQueryRunner) { - return (this._vizPanel.state.$data.state.$data as SceneQueryRunner).state.queries; + return this._vizPanel.state.$data.state.$data.state.queries; } } diff --git a/public/app/features/plugins/sql/datasource/SqlDatasource.ts b/public/app/features/plugins/sql/datasource/SqlDatasource.ts index 0d4540e91ce..0788326341f 100644 --- a/public/app/features/plugins/sql/datasource/SqlDatasource.ts +++ b/public/app/features/plugins/sql/datasource/SqlDatasource.ts @@ -9,7 +9,6 @@ import { DataQueryRequest, DataQueryResponse, DataSourceInstanceSettings, - DataSourceRef, MetricFindValue, ScopedVars, CoreApp, @@ -117,10 +116,7 @@ export abstract class SqlDatasource extends DataSourceWithBackend { + applyTemplateVariables(target: SQLQuery, scopedVars: ScopedVars) { return { refId: target.refId, datasource: this.getRef(), diff --git a/public/app/features/query/state/PanelQueryRunner.ts b/public/app/features/query/state/PanelQueryRunner.ts index a2911d12f16..ed1f6fcb1e3 100644 --- a/public/app/features/query/state/PanelQueryRunner.ts +++ b/public/app/features/query/state/PanelQueryRunner.ts @@ -139,9 +139,14 @@ export class PanelQueryRunner { if (withFieldConfig && data.series?.length) { if (lastConfigRev === this.dataConfigSource.configRev) { - const streamingDataFrame = data.series.find((data) => isStreamingDataFrame(data)) as - | StreamingDataFrame - | undefined; + let streamingDataFrame: StreamingDataFrame | undefined; + + for (const frame of data.series) { + if (isStreamingDataFrame(frame)) { + streamingDataFrame = frame; + break; + } + } if ( streamingDataFrame && diff --git a/public/app/features/sandbox/TestStuffPage.tsx b/public/app/features/sandbox/TestStuffPage.tsx index 4cdb3a5b7ec..c1e20ed8c87 100644 --- a/public/app/features/sandbox/TestStuffPage.tsx +++ b/public/app/features/sandbox/TestStuffPage.tsx @@ -2,9 +2,15 @@ import React, { useMemo, useState } from 'react'; import { useObservable } from 'react-use'; import AutoSizer from 'react-virtualized-auto-sizer'; -import { ApplyFieldOverrideOptions, dateMath, FieldColorModeId, NavModelItem, PanelData } from '@grafana/data'; +import { + ApplyFieldOverrideOptions, + DataConfigSource, + dateMath, + FieldColorModeId, + NavModelItem, + PanelData, +} from '@grafana/data'; import { getPluginExtensions, isPluginExtensionLink } from '@grafana/runtime'; -import { DataTransformerConfig } from '@grafana/schema'; import { Button, HorizontalGroup, LinkButton, Table } from '@grafana/ui'; import { Page } from 'app/core/components/Page/Page'; import { config } from 'app/core/config'; @@ -129,8 +135,8 @@ export function getDefaultState(): State { theme: config.theme2, }; - const dataConfig = { - getTransformations: () => [] as DataTransformerConfig[], + const dataConfig: DataConfigSource = { + getTransformations: () => [], getFieldOverrideOptions: () => options, getDataSupport: () => ({ annotations: false, alertStates: false }), }; diff --git a/public/app/features/storage/storage.ts b/public/app/features/storage/storage.ts index 41b0527d71f..38c05e9ec38 100644 --- a/public/app/features/storage/storage.ts +++ b/public/app/features/storage/storage.ts @@ -102,9 +102,9 @@ class SimpleStorage implements GrafanaStorage { body: formData, }); - let body: UploadResponse = await res.json(); + let body = await res.json(); if (!body) { - body = {} as any; + body = {}; } body.status = res.status; body.statusText = res.statusText; diff --git a/public/app/features/transformers/calculateHeatmap/heatmap.ts b/public/app/features/transformers/calculateHeatmap/heatmap.ts index a5c770fe9e8..3a57e5845b7 100644 --- a/public/app/features/transformers/calculateHeatmap/heatmap.ts +++ b/public/app/features/transformers/calculateHeatmap/heatmap.ts @@ -327,7 +327,8 @@ export function calculateHeatmapFromData(frames: DataFrame[], options: HeatmapCa : undefined, yMode: yBucketsCfg.mode, ySize: yBucketsCfg.value ? +yBucketsCfg.value : undefined, - yLog: scaleDistribution?.type === ScaleDistribution.Log ? (scaleDistribution?.log as any) : undefined, + yLog: + scaleDistribution?.type === ScaleDistribution.Log ? (scaleDistribution?.log as 2 | 10 | undefined) : undefined, }); const frame = { diff --git a/public/app/features/transformers/editors/CalculateFieldTransformerEditor/WindowOptionsEditor.tsx b/public/app/features/transformers/editors/CalculateFieldTransformerEditor/WindowOptionsEditor.tsx index ff5090d3e4b..05b10b6e36c 100644 --- a/public/app/features/transformers/editors/CalculateFieldTransformerEditor/WindowOptionsEditor.tsx +++ b/public/app/features/transformers/editors/CalculateFieldTransformerEditor/WindowOptionsEditor.tsx @@ -52,16 +52,15 @@ export const WindowOptionsEditor = (props: { }); }; - const onWindowSizeModeChange = (val: string) => { - const mode = val as WindowSizeMode; + const onWindowSizeModeChange = (val: WindowSizeMode) => { updateWindowOptions({ ...window!, windowSize: window?.windowSize - ? mode === WindowSizeMode.Percentage + ? val === WindowSizeMode.Percentage ? window!.windowSize! / 100 : window!.windowSize! * 100 : undefined, - windowSizeMode: mode, + windowSizeMode: val, }); }; @@ -71,10 +70,10 @@ export const WindowOptionsEditor = (props: { updateWindowOptions({ ...window, reducer }); }; - const onTypeChange = (val: string) => { + const onTypeChange = (val: WindowAlignment) => { updateWindowOptions({ ...window!, - windowAlignment: val as WindowAlignment, + windowAlignment: val, }); }; diff --git a/public/app/features/variables/adhoc/actions.ts b/public/app/features/variables/adhoc/actions.ts index d0dfd6b631d..91d1ed8ef9c 100644 --- a/public/app/features/variables/adhoc/actions.ts +++ b/public/app/features/variables/adhoc/actions.ts @@ -149,7 +149,12 @@ const createAdHocVariable = (options: AdHocTableOptions): ThunkResult => { const getVariableByOptions = (options: AdHocTableOptions, state: StoreState): AdHocVariableModel | undefined => { const key = getLastKey(state); const templatingState = getVariablesState(key, state); - return Object.values(templatingState.variables).find( - (v) => isAdHoc(v) && v.datasource?.uid === options.datasource.uid - ) as AdHocVariableModel; + let result: AdHocVariableModel | undefined; + for (const v of Object.values(templatingState.variables)) { + if (isAdHoc(v) && v.datasource?.uid === options.datasource.uid) { + result = v; + break; + } + } + return result; }; diff --git a/public/app/plugins/datasource/grafana-testdata-datasource/components/SimulationQueryEditor.tsx b/public/app/plugins/datasource/grafana-testdata-datasource/components/SimulationQueryEditor.tsx index 225f3fba094..58af6c6b2a4 100644 --- a/public/app/plugins/datasource/grafana-testdata-datasource/components/SimulationQueryEditor.tsx +++ b/public/app/plugins/datasource/grafana-testdata-datasource/components/SimulationQueryEditor.tsx @@ -90,7 +90,7 @@ export const SimulationQueryEditor = ({ onChange, query, ds }: EditorProps) => { if (simKey.uid) { path += '/' + simKey.uid; } - ds.postResource('sim/' + path, config).then((res) => { + ds.postResource('sim/' + path, config).then((res) => { setCfgValue(res.config); }); };