mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: improve some more types (#60476)
* improve some more types * fixes Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This commit is contained in:
parent
55b014974d
commit
ba6d2f2a82
@ -35,12 +35,6 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
||||
],
|
||||
"e2e/dashboards-suite/textbox-variables.spec.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"]
|
||||
],
|
||||
"e2e/panels-suite/panelEdit_queries.spec.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
||||
@ -974,19 +968,13 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
|
||||
],
|
||||
"packages/grafana-runtime/src/utils/DataSourceWithBackend.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.", "2"],
|
||||
[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, "Do not use any type assertions.", "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.", "7"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "9"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "10"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "12"]
|
||||
[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"]
|
||||
],
|
||||
"packages/grafana-runtime/src/utils/plugin.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
@ -994,21 +982,14 @@ exports[`better eslint`] = {
|
||||
"packages/grafana-runtime/src/utils/queryResponse.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.", "2"]
|
||||
],
|
||||
"packages/grafana-runtime/src/utils/queryResponse.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.", "4"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "5"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "6"]
|
||||
],
|
||||
"packages/grafana-runtime/src/utils/toDataQueryError.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.", "4"]
|
||||
],
|
||||
"packages/grafana-toolkit/src/cli/tasks/component.create.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
@ -1108,9 +1089,6 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"]
|
||||
],
|
||||
"packages/grafana-ui/src/components/ButtonCascader/ButtonCascader.tsx:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
"packages/grafana-ui/src/components/Card/Card.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
||||
@ -1127,10 +1105,6 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "3"]
|
||||
],
|
||||
"packages/grafana-ui/src/components/CustomScrollbar/CustomScrollbar.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
||||
],
|
||||
"packages/grafana-ui/src/components/DataLinks/DataLinkInput.tsx:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
|
@ -33,8 +33,8 @@ describe.skip('TextBox - change query scenarios', function () {
|
||||
saveDashboard(false);
|
||||
|
||||
e2e()
|
||||
.get('@dashuid')
|
||||
.then((dashuid: any) => {
|
||||
.get<string>('@dashuid')
|
||||
.then((dashuid) => {
|
||||
expect(dashuid).not.to.eq(PAGE_UNDER_TEST);
|
||||
|
||||
e2e.flows.openDashboard({ uid: dashuid });
|
||||
@ -59,8 +59,8 @@ describe.skip('TextBox - change query scenarios', function () {
|
||||
saveDashboard(true);
|
||||
|
||||
e2e()
|
||||
.get('@dashuid')
|
||||
.then((dashuid: any) => {
|
||||
.get<string>('@dashuid')
|
||||
.then((dashuid) => {
|
||||
expect(dashuid).not.to.eq(PAGE_UNDER_TEST);
|
||||
|
||||
e2e.flows.openDashboard({ uid: dashuid });
|
||||
@ -85,8 +85,8 @@ describe.skip('TextBox - change picker value scenarios', function () {
|
||||
saveDashboard(false);
|
||||
|
||||
e2e()
|
||||
.get('@dashuid')
|
||||
.then((dashuid: any) => {
|
||||
.get<string>('@dashuid')
|
||||
.then((dashuid) => {
|
||||
expect(dashuid).not.to.eq(PAGE_UNDER_TEST);
|
||||
|
||||
e2e.flows.openDashboard({ uid: dashuid });
|
||||
@ -108,8 +108,8 @@ describe.skip('TextBox - change picker value scenarios', function () {
|
||||
saveDashboard(true);
|
||||
|
||||
e2e()
|
||||
.get('@dashuid')
|
||||
.then((dashuid: any) => {
|
||||
.get<string>('@dashuid')
|
||||
.then((dashuid) => {
|
||||
expect(dashuid).not.to.eq(PAGE_UNDER_TEST);
|
||||
|
||||
e2e.flows.openDashboard({ uid: dashuid });
|
||||
|
@ -23,6 +23,7 @@ export {
|
||||
frameToMetricFindValue,
|
||||
type BackendDataSourceResponse,
|
||||
type DataResponse,
|
||||
type TestingStatus,
|
||||
} from './utils/queryResponse';
|
||||
export { PanelRenderer, type PanelRendererProps } from './components/PanelRenderer';
|
||||
export { PanelDataErrorView, type PanelDataErrorViewProps } from './components/PanelDataErrorView';
|
||||
|
@ -46,7 +46,7 @@ export function isExpressionReference(ref?: DataSourceRef | string | null): bool
|
||||
if (!ref) {
|
||||
return false;
|
||||
}
|
||||
const v = (ref as any).type ?? ref;
|
||||
const v = typeof ref === 'string' ? ref : ref.type;
|
||||
return v === ExpressionDatasourceRef.type || v === '-100'; // -100 was a legacy accident that should be removed
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ enum PluginRequestHeaders {
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type HealthCheckResultDetails = Record<string, any> | undefined;
|
||||
export type HealthCheckResultDetails = Record<string, unknown> | undefined;
|
||||
|
||||
/**
|
||||
* Describes the payload returned when checking the health of a data source
|
||||
@ -320,8 +320,8 @@ class DataSourceWithBackend<
|
||||
headers: this.getRequestHeaders(),
|
||||
})
|
||||
)
|
||||
.then((v: FetchResponse) => v.data as HealthCheckResult)
|
||||
.catch((err) => err.data as HealthCheckResult);
|
||||
.then((v: FetchResponse) => v.data)
|
||||
.catch((err) => err.data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -360,7 +360,7 @@ export function toStreamingDataResponse<TQuery extends DataQuery = DataQuery>(
|
||||
for (const f of rsp.data) {
|
||||
const addr = parseLiveChannelAddress(f.meta?.channel);
|
||||
if (addr) {
|
||||
const frame = f as DataFrame;
|
||||
const frame: DataFrame = f;
|
||||
streams.push(
|
||||
live.getDataStream({
|
||||
addr,
|
||||
|
@ -280,7 +280,7 @@ describe('Query Response parser', () => {
|
||||
});
|
||||
|
||||
describe('Cache notice', () => {
|
||||
let resp: any;
|
||||
let resp: FetchResponse<BackendDataSourceResponse>;
|
||||
|
||||
beforeEach(() => {
|
||||
resp = {
|
||||
@ -311,7 +311,7 @@ describe('Query Response parser', () => {
|
||||
test('does not remove existing notices', () => {
|
||||
const queries: DataQuery[] = [{ refId: 'A' }];
|
||||
resp.headers.set('X-Cache', 'HIT');
|
||||
resp.data.results.A.frames[0].schema.meta = { notices: [{ severity: 'info', text: 'Example' }] };
|
||||
resp.data.results.A.frames![0].schema!.meta = { notices: [{ severity: 'info', text: 'Example' }] };
|
||||
expect(toDataQueryResponse(resp, queries).data[0].meta.notices).toStrictEqual([
|
||||
{ severity: 'info', text: 'Example' },
|
||||
cachedResponseNotice,
|
||||
|
@ -17,6 +17,7 @@ import {
|
||||
|
||||
import { FetchError, FetchResponse } from '../services';
|
||||
|
||||
import { HealthCheckResultDetails } from './DataSourceWithBackend';
|
||||
import { toDataQueryError } from './toDataQueryError';
|
||||
|
||||
export const cachedResponseNotice: QueryResultMetaNotice = { severity: 'info', text: 'Cached response' };
|
||||
@ -130,7 +131,7 @@ export function toDataQueryResponse(
|
||||
rsp.state = LoadingState.Error;
|
||||
}
|
||||
if (!rsp.error) {
|
||||
rsp.error = toDataQueryError(res as DataQueryError);
|
||||
rsp.error = toDataQueryError(res);
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,6 +161,12 @@ function addCacheNotice(frame: DataFrameJSON): DataFrameJSON {
|
||||
};
|
||||
}
|
||||
|
||||
export interface TestingStatus {
|
||||
message?: string | null;
|
||||
status?: string | null;
|
||||
details?: HealthCheckResultDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data sources using api/ds/query to test data sources can use this function to
|
||||
* handle errors and convert them to TestingStatus object.
|
||||
@ -171,7 +178,7 @@ function addCacheNotice(frame: DataFrameJSON): DataFrameJSON {
|
||||
*
|
||||
* @returns {TestingStatus}
|
||||
*/
|
||||
export function toTestingStatus(err: FetchError): any {
|
||||
export function toTestingStatus(err: FetchError): TestingStatus {
|
||||
const queryResponse = toDataQueryResponse(err);
|
||||
// POST api/ds/query errors returned as { message: string, error: string } objects
|
||||
if (queryResponse.error?.data?.message) {
|
||||
|
@ -7,11 +7,11 @@ import { DataQueryError } from '@grafana/data';
|
||||
* @public
|
||||
*/
|
||||
export function toDataQueryError(err: DataQueryError | string | unknown): DataQueryError {
|
||||
const error = (err || {}) as DataQueryError;
|
||||
const error: DataQueryError = err || {};
|
||||
|
||||
if (!error.message) {
|
||||
if (typeof err === 'string' || err instanceof String) {
|
||||
return { message: err } as DataQueryError;
|
||||
if (typeof err === 'string') {
|
||||
return { message: err };
|
||||
}
|
||||
|
||||
let message = 'Query error';
|
||||
|
@ -51,7 +51,7 @@ export const ButtonCascader: React.FC<ButtonCascaderProps> = (props) => {
|
||||
|
||||
// Weird way to do this bit it goes around a styling issue in Button where even null/undefined child triggers
|
||||
// styling change which messes up the look if there is only single icon content.
|
||||
let content: any = props.children;
|
||||
let content: React.ReactNode = props.children;
|
||||
if (!hideDownIcon) {
|
||||
content = [props.children, <Icon key={'down-icon'} name="angle-down" className={styles.icons.right} />];
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ export const CustomScrollbar = ({
|
||||
onScroll,
|
||||
children,
|
||||
}: React.PropsWithChildren<Props>) => {
|
||||
const ref = useRef<Scrollbars & { view: HTMLDivElement }>(null);
|
||||
const ref = useRef<Scrollbars & { view: HTMLDivElement; update: () => void }>(null);
|
||||
const styles = useStyles2(getStyles);
|
||||
|
||||
useEffect(() => {
|
||||
@ -73,7 +73,7 @@ export const CustomScrollbar = ({
|
||||
return;
|
||||
}
|
||||
setTimeout(() => {
|
||||
const scrollbar = ref.current as any;
|
||||
const scrollbar = ref.current;
|
||||
if (scrollbar?.update) {
|
||||
scrollbar.update();
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import React from 'react';
|
||||
|
||||
import { selectors as e2eSelectors } from '@grafana/e2e-selectors';
|
||||
import { TestingStatus } from '@grafana/runtime';
|
||||
import { Alert } from '@grafana/ui';
|
||||
import { TestingStatus } from 'app/types';
|
||||
|
||||
export type Props = {
|
||||
testingStatus?: TestingStatus;
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { AnyAction, createAction } from '@reduxjs/toolkit';
|
||||
|
||||
import { DataSourcePluginMeta, DataSourceSettings, LayoutMode, LayoutModes } from '@grafana/data';
|
||||
import { DataSourcesState, DataSourceSettingsState, TestingStatus } from 'app/types';
|
||||
import { TestingStatus } from '@grafana/runtime';
|
||||
import { DataSourcesState, DataSourceSettingsState } from 'app/types';
|
||||
|
||||
import { GenericDataSourcePlugin } from '../types';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { DataSourcePluginMeta, DataSourceSettings, LayoutMode } from '@grafana/data';
|
||||
import { HealthCheckResultDetails } from '@grafana/runtime/src/utils/DataSourceWithBackend';
|
||||
import { TestingStatus } from '@grafana/runtime';
|
||||
import { GenericDataSourcePlugin } from 'app/features/datasources/types';
|
||||
|
||||
export interface DataSourcesState {
|
||||
@ -17,12 +17,6 @@ export interface DataSourcesState {
|
||||
isSortAscending: boolean;
|
||||
}
|
||||
|
||||
export interface TestingStatus {
|
||||
message?: string | null;
|
||||
status?: string | null;
|
||||
details?: HealthCheckResultDetails;
|
||||
}
|
||||
|
||||
export interface DataSourceSettingsState {
|
||||
plugin?: GenericDataSourcePlugin | null;
|
||||
testingStatus?: TestingStatus;
|
||||
|
Loading…
Reference in New Issue
Block a user