From 5f6fea33f293ac57625305afa74027654716f452 Mon Sep 17 00:00:00 2001 From: Joao Silva <100691367+JoaoSilvaGrafana@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:43:25 +0100 Subject: [PATCH] Chore: Improve typings in OptionsUI and Explore (#76245) --- .betterer.results | 37 +++++-------------- .../core/components/OptionsUI/registry.tsx | 10 ++--- .../explore/ExploreQueryInspector.tsx | 3 +- .../features/explore/TraceView/TraceView.tsx | 8 ++-- 4 files changed, 21 insertions(+), 37 deletions(-) diff --git a/.betterer.results b/.betterer.results index 6d5ba9d6a08..bb112843ee0 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1331,11 +1331,11 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "17"], [0, 0, 0, "Do not use any type assertions.", "18"], [0, 0, 0, "Unexpected any. Specify a different type.", "19"], - [0, 0, 0, "Do not use any type assertions.", "20"], - [0, 0, 0, "Unexpected any. Specify a different type.", "21"], - [0, 0, 0, "Do not use any type assertions.", "22"], - [0, 0, 0, "Unexpected any. Specify a different type.", "23"], - [0, 0, 0, "Do not use any type assertions.", "24"], + [0, 0, 0, "Unexpected any. Specify a different type.", "20"], + [0, 0, 0, "Do not use any type assertions.", "21"], + [0, 0, 0, "Unexpected any. Specify a different type.", "22"], + [0, 0, 0, "Do not use any type assertions.", "23"], + [0, 0, 0, "Unexpected any. Specify a different type.", "24"], [0, 0, 0, "Unexpected any. Specify a different type.", "25"], [0, 0, 0, "Do not use any type assertions.", "26"], [0, 0, 0, "Unexpected any. Specify a different type.", "27"], @@ -1386,20 +1386,10 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "72"], [0, 0, 0, "Do not use any type assertions.", "73"], [0, 0, 0, "Unexpected any. Specify a different type.", "74"], - [0, 0, 0, "Unexpected any. Specify a different type.", "75"], - [0, 0, 0, "Do not use any type assertions.", "76"], - [0, 0, 0, "Unexpected any. Specify a different type.", "77"], - [0, 0, 0, "Do not use any type assertions.", "78"], - [0, 0, 0, "Unexpected any. Specify a different type.", "79"], - [0, 0, 0, "Unexpected any. Specify a different type.", "80"], - [0, 0, 0, "Do not use any type assertions.", "81"], - [0, 0, 0, "Unexpected any. Specify a different type.", "82"], - [0, 0, 0, "Do not use any type assertions.", "83"], - [0, 0, 0, "Unexpected any. Specify a different type.", "84"], - [0, 0, 0, "Do not use any type assertions.", "85"], - [0, 0, 0, "Unexpected any. Specify a different type.", "86"], - [0, 0, 0, "Do not use any type assertions.", "87"], - [0, 0, 0, "Unexpected any. Specify a different type.", "88"] + [0, 0, 0, "Do not use any type assertions.", "75"], + [0, 0, 0, "Unexpected any. Specify a different type.", "76"], + [0, 0, 0, "Do not use any type assertions.", "77"], + [0, 0, 0, "Unexpected any. Specify a different type.", "78"] ], "public/app/core/components/OptionsUI/slider.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] @@ -3811,9 +3801,6 @@ exports[`better eslint`] = { "public/app/features/explore/ExplorePaneContainer.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] ], - "public/app/features/explore/ExploreQueryInspector.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/explore/FeatureTogglePage.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] ], @@ -3994,11 +3981,7 @@ exports[`better eslint`] = { "public/app/features/explore/TraceView/TraceView.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "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.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Do not use any type assertions.", "6"] + [0, 0, 0, "Do not use any type assertions.", "2"] ], "public/app/features/explore/TraceView/components/TracePageHeader/Actions/ActionButton.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] diff --git a/public/app/core/components/OptionsUI/registry.tsx b/public/app/core/components/OptionsUI/registry.tsx index 18c1816c8ac..2a3f6c65f4d 100644 --- a/public/app/core/components/OptionsUI/registry.tsx +++ b/public/app/core/components/OptionsUI/registry.tsx @@ -69,7 +69,7 @@ export const getAllOptionEditors = () => { id: 'text', name: 'Text', description: 'Allows string values input', - editor: StringValueEditor as any, + editor: StringValueEditor, }; const strings: StandardEditorsRegistryItem = { @@ -155,28 +155,28 @@ export const getAllOptionEditors = () => { id: 'timezone', name: 'Time zone', description: 'Time zone selection', - editor: TimeZonePicker as any, + editor: TimeZonePicker, }; const fieldName: StandardEditorsRegistryItem = { id: 'field-name', name: 'Field name', description: 'Allows selecting a field name from a data frame', - editor: FieldNamePicker as any, + editor: FieldNamePicker, }; const dashboardPicker: StandardEditorsRegistryItem = { id: 'dashboard-uid', name: 'Dashboard', description: 'Select dashboard', - editor: DashboardPicker as any, + editor: DashboardPicker, }; const mappings: StandardEditorsRegistryItem = { id: 'mappings', name: 'Mappings', description: 'Allows defining value mappings', - editor: ValueMappingsEditor as any, + editor: ValueMappingsEditor, }; const thresholds: StandardEditorsRegistryItem = { diff --git a/public/app/features/explore/ExploreQueryInspector.tsx b/public/app/features/explore/ExploreQueryInspector.tsx index 83e0a8f257f..1af76715975 100644 --- a/public/app/features/explore/ExploreQueryInspector.tsx +++ b/public/app/features/explore/ExploreQueryInspector.tsx @@ -3,6 +3,7 @@ import { connect, ConnectedProps } from 'react-redux'; import { CoreApp, LoadingState, TimeZone } from '@grafana/data'; import { reportInteraction } from '@grafana/runtime/src'; +import { defaultTimeZone } from '@grafana/schema'; import { TabbedContainer, TabConfig } from '@grafana/ui'; import { ExploreDrawer } from 'app/features/explore/ExploreDrawer'; import { InspectDataTab } from 'app/features/inspector/InspectDataTab'; @@ -39,7 +40,7 @@ export function ExploreQueryInspector(props: Props) { label: 'Stats', value: 'stats', icon: 'chart-line', - content: , + content: , }; const jsonTab: TabConfig = { diff --git a/public/app/features/explore/TraceView/TraceView.tsx b/public/app/features/explore/TraceView/TraceView.tsx index 80166258735..8f973234ef1 100644 --- a/public/app/features/explore/TraceView/TraceView.tsx +++ b/public/app/features/explore/TraceView/TraceView.tsx @@ -18,7 +18,7 @@ import { import { getTemplateSrv } from '@grafana/runtime'; import { DataQuery } from '@grafana/schema'; import { useStyles2 } from '@grafana/ui'; -import { getTraceToLogsOptions, TraceToLogsData } from 'app/core/components/TraceToLogs/TraceToLogsSettings'; +import { getTraceToLogsOptions } from 'app/core/components/TraceToLogs/TraceToLogsSettings'; import { TraceToMetricsData } from 'app/core/components/TraceToMetrics/TraceToMetricsSettings'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { getTimeZone } from 'app/features/profile/state/selectors'; @@ -112,8 +112,9 @@ export function TraceView(props: Props) { ); const instanceSettings = getDatasourceSrv().getInstanceSettings(datasource?.name); - const traceToLogsOptions = getTraceToLogsOptions(instanceSettings?.jsonData as TraceToLogsData); - const traceToMetricsOptions = (instanceSettings?.jsonData as TraceToMetricsData)?.tracesToMetrics; + const traceToLogsOptions = getTraceToLogsOptions(instanceSettings?.jsonData); + const traceToMetrics: TraceToMetricsData | undefined = instanceSettings?.jsonData; + const traceToMetricsOptions = traceToMetrics?.tracesToMetrics; const spanBarOptions: SpanBarOptionsData | undefined = instanceSettings?.jsonData; const createSpanLink = useMemo( @@ -261,7 +262,6 @@ function useFocusSpanLink(options: { link, internalLink: link.internal!, scopedVars: {}, - range: {} as any, field: {} as Field, onClickFn: sameTrace ? () => setFocusedSpanId(focusedSpanId === spanId ? undefined : spanId)