Chore: improve typings (#87306)

* some fixes

* some more fixes

* some canvas fixes

* use removeProperty instead

* few more

* fixy fix

* undo changes to ticks for now
This commit is contained in:
Ashley Harrison
2024-05-03 17:21:37 +01:00
committed by GitHub
parent 43ed6a8218
commit 1d6d5cc2cd
21 changed files with 84 additions and 147 deletions

View File

@@ -696,9 +696,7 @@ exports[`better eslint`] = {
[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.", "12"]
[0, 0, 0, "Unexpected any. Specify a different type.", "10"]
],
"packages/grafana-runtime/src/services/pluginExtensions/getPluginExtensions.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
@@ -1063,12 +1061,7 @@ exports[`better eslint`] = {
],
"public/app/core/TableModel.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.", "6"]
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/core/actions/index.ts:5381": [
[0, 0, 0, "Do not re-export imported variable (\`updateNavIndex\`)", "0"],
@@ -1103,19 +1096,6 @@ exports[`better eslint`] = {
"public/app/core/components/NestedFolderPicker/Trigger.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"]
],
"public/app/core/components/OptionsUI/registry.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.", "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"]
],
"public/app/core/components/PageHeader/PageHeader.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"],
[0, 0, 0, "Styles should be written using objects.", "1"]
@@ -1157,14 +1137,12 @@ exports[`better eslint`] = {
[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, "Styles should be written using objects.", "5"],
[0, 0, 0, "Styles should be written using objects.", "6"]
[0, 0, 0, "Styles should be written using objects.", "4"],
[0, 0, 0, "Styles should be written using objects.", "5"]
],
"public/app/core/components/TagFilter/TagOption.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Styles should be written using objects.", "1"],
[0, 0, 0, "Styles should be written using objects.", "2"]
[0, 0, 0, "Styles should be written using objects.", "0"],
[0, 0, 0, "Styles should be written using objects.", "1"]
],
"public/app/core/components/TimeSeries/utils.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@@ -1210,23 +1188,16 @@ exports[`better eslint`] = {
"public/app/core/navigation/types.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/core/reducers/root.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/core/services/ResponseQueue.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/core/services/backend_srv.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, "Do not use any type assertions.", "2"],
[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.", "5"]
],
"public/app/core/services/context_srv.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
@@ -1266,10 +1237,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "17"],
[0, 0, 0, "Unexpected any. Specify a different type.", "18"]
],
"public/app/core/utils/ConfigProvider.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/core/utils/connectWithReduxStore.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
@@ -1293,9 +1260,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "4"],
[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"]
],
"public/app/core/utils/object.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"],
@@ -1394,8 +1358,7 @@ exports[`better eslint`] = {
[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.", "9"]
],
"public/app/features/alerting/state/reducers.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@@ -2234,19 +2197,11 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use export all (\`export * from ...\`)", "3"]
],
"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"],
[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.", "0"]
],
"public/app/features/canvas/runtime/frame.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/canvas/runtime/root.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/canvas/runtime/scene.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"],
@@ -2346,19 +2301,13 @@ exports[`better eslint`] = {
"public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.tsx:5381": [
[0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"]
],
"public/app/features/dashboard-scene/saving/DetectChangesWorker.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/features/dashboard-scene/saving/getDashboardChanges.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"]
],
"public/app/features/dashboard-scene/scene/PanelMenuBehavior.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, "Do not use any type assertions.", "2"]
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/dashboard-scene/serialization/angularMigration.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
@@ -2514,8 +2463,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "1"]
],
"public/app/features/dashboard/components/PanelEditor/OverrideCategoryTitle.tsx:5381": [
[0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
[0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"]
],
"public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx:5381": [
[0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"],
@@ -2528,9 +2476,6 @@ exports[`better eslint`] = {
"public/app/features/dashboard/components/PanelEditor/VisualizationSelectPane.tsx:5381": [
[0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"]
],
"public/app/features/dashboard/components/PanelEditor/getFieldOverrideElements.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"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"],
@@ -3484,9 +3429,6 @@ exports[`better eslint`] = {
"public/app/features/library-panels/components/LibraryPanelsSearch/LibraryPanelsSearch.tsx:5381": [
[0, 0, 0, "\'VerticalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"]
],
"public/app/features/library-panels/components/LibraryPanelsView/actions.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"]
],
@@ -3502,9 +3444,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Styles should be written using objects.", "4"],
[0, 0, 0, "Styles should be written using objects.", "5"]
],
"public/app/features/library-panels/utils.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/live/LiveConnectionWarning.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"],
[0, 0, 0, "Styles should be written using objects.", "1"]
@@ -3655,8 +3594,7 @@ exports[`better eslint`] = {
[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.", "12"],
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
[0, 0, 0, "Unexpected any. Specify a different type.", "14"]
[0, 0, 0, "Unexpected any. Specify a different type.", "13"]
],
"public/app/features/manage-dashboards/state/reducers.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
@@ -3792,9 +3730,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Styles should be written using objects.", "1"],
[0, 0, 0, "Styles should be written using objects.", "2"]
],
"public/app/features/plugins/admin/hooks/useHistory.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/plugins/admin/hooks/usePluginInfo.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"]
],

View File

@@ -157,7 +157,7 @@ export interface BackendSrv {
* wrap the Observable returned by fetch with the lastValueFrom function, or use the get|delete|post|patch|put methods.
* This method is going to be private from Grafana 10.
*/
request<T = any>(options: BackendSrvRequest): Promise<T>;
request<T = unknown>(options: BackendSrvRequest): Promise<T>;
/**
* Special function used to communicate with datasources that will emit core
@@ -167,7 +167,7 @@ export interface BackendSrv {
*
* @deprecated Use the fetch function instead
*/
datasourceRequest<T = any>(options: BackendSrvRequest): Promise<FetchResponse<T>>;
datasourceRequest<T = unknown>(options: BackendSrvRequest): Promise<FetchResponse<T>>;
/**
* Observable http request interface

View File

@@ -17,7 +17,7 @@ export default class TableModel implements TableData {
columns: MutableColumn[];
rows: any[];
type: string;
columnMap: any;
columnMap: Record<string, Column>;
refId?: string;
meta?: QueryResultMeta;
@@ -69,14 +69,14 @@ export default class TableModel implements TableData {
}
}
addRow(row: any[]) {
addRow(row: unknown[]) {
this.rows.push(row);
}
}
// Returns true if both rows have matching non-empty fields as well as matching
// indexes where one field is empty and the other is not
function areRowsMatching(columns: Column[], row: any[], otherRow: any[]) {
function areRowsMatching(columns: Column[], row: unknown[], otherRow: unknown[]) {
let foundFieldToMatch = false;
for (let columnIndex = 0; columnIndex < columns.length; columnIndex++) {
if (row[columnIndex] !== undefined && otherRow[columnIndex] !== undefined) {
@@ -141,7 +141,7 @@ export function mergeTablesIntoModel(dst?: TableModel, ...tables: TableModel[]):
}, []);
// Merge rows that have same values for columns
const mergedRows: { [key: string]: any } = {};
const mergedRows: Record<number, MutableColumn[]> = {};
const compactedRows = flattenedRows.reduce<MutableColumn[][]>((acc, row, rowIndex) => {
if (!mergedRows[rowIndex]) {

View File

@@ -213,7 +213,7 @@ export const getAllOptionEditors = () => {
*/
export const getAllStandardFieldConfigs = () => {
const category = ['Standard options'];
const displayName: FieldConfigPropertyItem<any, string, StringFieldConfigSettings> = {
const displayName: FieldConfigPropertyItem<FieldConfig, string, StringFieldConfigSettings> = {
id: 'displayName',
path: 'displayName',
name: 'Display name',
@@ -229,7 +229,7 @@ export const getAllStandardFieldConfigs = () => {
category,
};
const unit: FieldConfigPropertyItem<any, string, StringFieldConfigSettings> = {
const unit: FieldConfigPropertyItem<FieldConfig, string, StringFieldConfigSettings> = {
id: 'unit',
path: 'unit',
name: 'Unit',
@@ -247,7 +247,7 @@ export const getAllStandardFieldConfigs = () => {
category,
};
const fieldMinMax: FieldConfigPropertyItem<any, boolean, BooleanFieldSettings> = {
const fieldMinMax: FieldConfigPropertyItem<FieldConfig, boolean, BooleanFieldSettings> = {
id: 'fieldMinMax',
path: 'fieldMinMax',
name: 'Field min/max',
@@ -258,13 +258,13 @@ export const getAllStandardFieldConfigs = () => {
process: booleanOverrideProcessor,
shouldApply: (field) => field.type === FieldType.number,
showIf: (options: FieldConfig) => {
showIf: (options) => {
return options.min === undefined || options.max === undefined;
},
category,
};
const min: FieldConfigPropertyItem<any, number, NumberFieldConfigSettings> = {
const min: FieldConfigPropertyItem<FieldConfig, number, NumberFieldConfigSettings> = {
id: 'min',
path: 'min',
name: 'Min',
@@ -281,7 +281,7 @@ export const getAllStandardFieldConfigs = () => {
category,
};
const max: FieldConfigPropertyItem<any, number, NumberFieldConfigSettings> = {
const max: FieldConfigPropertyItem<FieldConfig, number, NumberFieldConfigSettings> = {
id: 'max',
path: 'max',
name: 'Max',
@@ -299,7 +299,7 @@ export const getAllStandardFieldConfigs = () => {
category,
};
const decimals: FieldConfigPropertyItem<any, number, NumberFieldConfigSettings> = {
const decimals: FieldConfigPropertyItem<FieldConfig, number, NumberFieldConfigSettings> = {
id: 'decimals',
path: 'decimals',
name: 'Decimals',
@@ -319,7 +319,7 @@ export const getAllStandardFieldConfigs = () => {
category,
};
const noValue: FieldConfigPropertyItem<any, string, StringFieldConfigSettings> = {
const noValue: FieldConfigPropertyItem<FieldConfig, string, StringFieldConfigSettings> = {
id: 'noValue',
path: 'noValue',
name: 'No value',
@@ -332,12 +332,12 @@ export const getAllStandardFieldConfigs = () => {
settings: {
placeholder: '-',
},
// ??? any optionsUi with no value
// ??? FieldConfig optionsUi with no value
shouldApply: () => true,
category,
};
const links: FieldConfigPropertyItem<any, DataLink[], StringFieldConfigSettings> = {
const links: FieldConfigPropertyItem<FieldConfig, DataLink[], StringFieldConfigSettings> = {
id: 'links',
path: 'links',
name: 'Data links',
@@ -352,7 +352,7 @@ export const getAllStandardFieldConfigs = () => {
getItemsCount: (value) => (value ? value.length : 0),
};
const color: FieldConfigPropertyItem<any, FieldColor | undefined, FieldColorConfigSettings> = {
const color: FieldConfigPropertyItem<FieldConfig, FieldColor | undefined, FieldColorConfigSettings> = {
id: 'color',
path: 'color',
name: 'Color scheme',
@@ -367,7 +367,7 @@ export const getAllStandardFieldConfigs = () => {
category,
};
const mappings: FieldConfigPropertyItem<any, ValueMapping[], ValueMappingFieldConfigSettings> = {
const mappings: FieldConfigPropertyItem<FieldConfig, ValueMapping[], ValueMappingFieldConfigSettings> = {
id: 'mappings',
path: 'mappings',
name: 'Value mappings',
@@ -383,7 +383,7 @@ export const getAllStandardFieldConfigs = () => {
getItemsCount: (value?) => (value ? value.length : 0),
};
const thresholds: FieldConfigPropertyItem<any, ThresholdsConfig, ThresholdsFieldConfigSettings> = {
const thresholds: FieldConfigPropertyItem<FieldConfig, ThresholdsConfig, ThresholdsFieldConfigSettings> = {
id: 'thresholds',
path: 'thresholds',
name: 'Thresholds',
@@ -403,7 +403,7 @@ export const getAllStandardFieldConfigs = () => {
getItemsCount: (value) => (value ? value.steps.length : 0),
};
const filterable: FieldConfigPropertyItem<{}, boolean | undefined, {}> = {
const filterable: FieldConfigPropertyItem<FieldConfig, boolean | undefined, {}> = {
id: 'filterable',
path: 'filterable',
name: 'Ad-hoc filterable',

View File

@@ -1,25 +1,19 @@
import { css } from '@emotion/css';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { components } from 'react-select';
import { components, MultiValueRemoveProps } from 'react-select';
import { escapeStringForRegex, GrafanaTheme2 } from '@grafana/data';
import { Icon, MultiSelect, useStyles2 } from '@grafana/ui';
import { t } from 'app/core/internationalization';
import { TagBadge } from './TagBadge';
import { TagOption } from './TagOption';
import { TagOption, TagSelectOption } from './TagOption';
export interface TermCount {
term: string;
count: number;
}
interface TagSelectOption {
value: string;
label: string;
count: number;
}
export interface Props {
allowCustomValue?: boolean;
formatCreateLabel?: (input: string) => string;
@@ -146,7 +140,7 @@ export const TagFilter = ({
MultiValueLabel: () => {
return null; // We want the whole tag to be clickable so we use MultiValueRemove instead
},
MultiValueRemove(props: any) {
MultiValueRemove(props: MultiValueRemoveProps<TagSelectOption>) {
const { data } = props;
return (

View File

@@ -7,7 +7,13 @@ import { useStyles2 } from '@grafana/ui';
import { TagBadge } from './TagBadge';
export const TagOption = ({ data, className, label, isFocused, innerProps }: OptionProps<any>) => {
export interface TagSelectOption {
value: string;
label: string;
count: number;
}
export const TagOption = ({ data, className, label, isFocused, innerProps }: OptionProps<TagSelectOption>) => {
const styles = useStyles2(getStyles);
return (

View File

@@ -71,7 +71,7 @@ export const createRootReducer = () => {
...addedReducers,
});
return (state: any, action: AnyAction) => {
return (state: Parameters<typeof appReducer>[0], action: AnyAction) => {
if (action.type !== cleanUpAction.type) {
return appReducer(state, action);
}

View File

@@ -107,7 +107,7 @@ export class BackendSrv implements BackendService {
}
}
async request<T = any>(options: BackendSrvRequest): Promise<T> {
async request<T = unknown>(options: BackendSrvRequest): Promise<T> {
return await lastValueFrom(this.fetch<T>(options).pipe(map((response: FetchResponse<T>) => response.data)));
}
@@ -181,8 +181,8 @@ export class BackendSrv implements BackendService {
this.inFlightRequests.next(CANCEL_ALL_REQUESTS_REQUEST_ID);
}
async datasourceRequest(options: BackendSrvRequest): Promise<any> {
return lastValueFrom(this.fetch(options));
async datasourceRequest<T = unknown>(options: BackendSrvRequest) {
return lastValueFrom(this.fetch<T>(options));
}
private parseRequestOptions(options: BackendSrvRequest): BackendSrvRequest {
@@ -371,7 +371,7 @@ export class BackendSrv implements BackendService {
return (inputStream) =>
inputStream.pipe(
retryWhen((attempts: Observable<any>) =>
retryWhen((attempts) =>
attempts.pipe(
mergeMap((error, i) => {
const firstAttempt = i === 0 && options.retry === 0;
@@ -508,7 +508,7 @@ export class BackendSrv implements BackendService {
}
/** @deprecated */
search(query: any): Promise<DashboardSearchItem[]> {
search(query: Parameters<typeof this.get>[1]): Promise<DashboardSearchItem[]> {
return this.get('/api/search', query);
}

View File

@@ -33,8 +33,8 @@ export const ThemeProvider = ({ children, value }: { children: React.ReactNode;
);
};
export const provideTheme = (component: React.ComponentType<any>, theme: GrafanaTheme2) => {
return function ThemeProviderWrapper(props: any) {
export const provideTheme = <P extends {}>(component: React.ComponentType<P>, theme: GrafanaTheme2) => {
return function ThemeProviderWrapper(props: P) {
return <ThemeProvider value={theme}>{React.createElement(component, { ...props })}</ThemeProvider>;
};
};

View File

@@ -12,9 +12,8 @@ export default function flatten(
let currentDepth = 1;
const output: Record<string, unknown> = {};
function step(object: any, prev: string | null) {
Object.keys(object).forEach((key) => {
const value = object[key];
function step(object: object, prev: string | null) {
Object.entries(object).forEach(([key, value]) => {
const isarray = opts?.safe && Array.isArray(value);
const type = Object.prototype.toString.call(value);
const isobject = type === '[object Object]';

View File

@@ -24,7 +24,7 @@ export class QueryPart {
params: any[];
text: string;
constructor(part: any, def: any) {
constructor(part: any, def: QueryPartDef) {
this.part = part;
this.def = def;
if (!this.def) {

View File

@@ -191,18 +191,16 @@ export class ElementState implements LayerElement {
this.sizeStyle = style;
if (this.div) {
for (const key in this.sizeStyle) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.div.style[key as any] = (this.sizeStyle as any)[key];
for (const [key, value] of Object.entries(this.sizeStyle)) {
this.div.style.setProperty(key, value);
}
// TODO: This is a hack, we should have a better way to handle this
const elementType = this.options.type;
if (!SVGElements.has(elementType)) {
// apply styles to div if it's not an SVG element
for (const key in this.dataStyle) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.div.style[key as any] = (this.dataStyle as any)[key];
for (const [key, value] of Object.entries(this.dataStyle)) {
this.div.style.setProperty(key, value);
}
} else {
// ELEMENT IS SVG
@@ -211,8 +209,7 @@ export class ElementState implements LayerElement {
// wrapper div element (this.div) doesn't re-render (has static `key` property),
// so we have to clean styles manually;
for (const key in this.dataStyle) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.div.style[key as any] = '';
this.div.style.removeProperty(key);
}
}
}

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { CanvasElementOptions, CanvasFrameOptions } from 'app/features/canvas';
import { CanvasFrameOptions } from 'app/features/canvas';
import { FrameState } from './frame';
import { Scene } from './scene';
@@ -24,9 +24,9 @@ export class RootElement extends FrameState {
}
// root type can not change
onChange(options: CanvasElementOptions) {
onChange(options: CanvasFrameOptions) {
this.revId++;
this.options = { ...options } as CanvasFrameOptions;
this.options = { ...options };
this.changeCallback();
}

View File

@@ -1,3 +1,5 @@
import { Dashboard } from '@grafana/schema';
import { getDashboardChanges } from './getDashboardChanges';
function _debounce<T>(f: (...args: T[]) => void, timeout: number) {
@@ -10,7 +12,7 @@ function _debounce<T>(f: (...args: T[]) => void, timeout: number) {
};
}
self.onmessage = _debounce((e: MessageEvent<{ initial: any; changed: any }>) => {
self.onmessage = _debounce((e: MessageEvent<{ initial: Dashboard; changed: Dashboard }>) => {
const result = getDashboardChanges(e.data.initial, e.data.changed, false, false, false);
self.postMessage(result);
}, 500);

View File

@@ -1,5 +1,6 @@
import {
InterpolateFunction,
LinkModel,
PanelMenuItem,
PanelPlugin,
PluginExtensionPanelContext,
@@ -331,13 +332,16 @@ export function getPanelLinks(panel: VizPanel) {
const panelLinks = linkSupplier.getLinks(interpolate);
return panelLinks.map((panelLink) => ({
...panelLink,
onClick: (e: any, origin: any) => {
DashboardInteractions.panelLinkClicked({ has_multiple_links: panelLinks.length > 1 });
panelLink.onClick?.(e, origin);
},
}));
return panelLinks.map((panelLink) => {
const updatedLink: LinkModel<VizPanel> = {
...panelLink,
onClick: (e, origin) => {
DashboardInteractions.panelLinkClicked({ has_multiple_links: panelLinks.length > 1 });
panelLink.onClick?.(e, origin);
},
};
return updatedLink;
});
}
function createExtensionContext(panel: VizPanel, dashboard: DashboardScene): PluginExtensionPanelContext {

View File

@@ -8,7 +8,7 @@ import { FieldMatcherUIRegistryItem } from '@grafana/ui/src/components/MatchersU
interface Props {
isExpanded: boolean;
registry: FieldConfigOptionsRegistry;
matcherUi: FieldMatcherUIRegistryItem<any>;
matcherUi: FieldMatcherUIRegistryItem<ConfigOverrideRule>;
override: ConfigOverrideRule;
overrideName: string;
onOverrideRemove: () => void;

View File

@@ -105,7 +105,7 @@ export function getFieldOverrideCategories(
},
});
const onMatcherConfigChange = (options: any) => {
const onMatcherConfigChange = (options: unknown) => {
override.matcher.options = options;
onOverrideChange(idx, override);
};

View File

@@ -100,7 +100,7 @@ export function deleteLibraryPanel(uid: string, args: SearchArgs): DispatchResul
}
export function asyncDispatcher(dispatch: Dispatch<AnyAction>) {
return function (action: any) {
return function (action: AnyAction | DispatchResult) {
if (action instanceof Function) {
return action(dispatch);
}

View File

@@ -1,7 +1,7 @@
import { PanelModel } from '../dashboard/state';
import { addLibraryPanel, updateLibraryPanel } from './state/api';
import { LibraryElementDTO } from './types';
import { LibraryElementDTO, PanelModelWithLibraryPanel } from './types';
export async function saveAndRefreshLibraryPanel(panel: PanelModel, folderUid: string): Promise<LibraryElementDTO> {
const panelSaveModel = toPanelSaveModel(panel);
@@ -34,7 +34,7 @@ function updatePanelModelWithUpdate(panel: PanelModel, updated: LibraryElementDT
panel.refresh();
}
function saveOrUpdateLibraryPanel(panel: any, folderUid: string): Promise<LibraryElementDTO> {
function saveOrUpdateLibraryPanel(panel: PanelModelWithLibraryPanel, folderUid: string): Promise<LibraryElementDTO> {
if (!panel.libraryPanel) {
return Promise.reject();
}

View File

@@ -212,7 +212,7 @@ export function importDashboard(importDashboardForm: ImportDashboardDTO): ThunkR
});
});
importDashboardForm.constants?.forEach((constant: any, index: number) => {
importDashboardForm.constants?.forEach((constant, index) => {
const input = inputs.constants[index];
inputsToPersist.push({

View File

@@ -2,7 +2,7 @@ import { locationService } from '@grafana/runtime';
export const useHistory = () => {
return {
push: ({ query }: any) => {
push: ({ query }: { query: Parameters<typeof locationService.partial>[0] }) => {
locationService.partial(query);
},
};