Chore: fix some types (#58662)

chore: fix some types
This commit is contained in:
Ashley Harrison
2022-11-11 16:29:49 +00:00
committed by GitHub
parent 860e25df3c
commit 500cf16142
26 changed files with 61 additions and 117 deletions

View File

@@ -87,7 +87,7 @@ export const DashNav = React.memo<Props>((props) => {
const dashboardSrv = getDashboardSrv();
const { dashboard, setStarred } = props;
dashboardSrv.starDashboard(dashboard.id, dashboard.meta.isStarred).then((newState) => {
dashboardSrv.starDashboard(dashboard.id, Boolean(dashboard.meta.isStarred)).then((newState) => {
setStarred({ id: dashboard.uid, title: dashboard.title, url: dashboard.meta.url ?? '', isStarred: newState });
dashboard.meta.isStarred = newState;
forceUpdate();

View File

@@ -201,8 +201,8 @@ export function hasChanges(current: DashboardModel, original: unknown) {
const currentClean = cleanDashboardFromIgnoredChanges(current.getSaveModelClone());
const originalClean = cleanDashboardFromIgnoredChanges(original);
const currentTimepicker: any = find((currentClean as any).nav, { type: 'timepicker' });
const originalTimepicker: any = find((originalClean as any).nav, { type: 'timepicker' });
const currentTimepicker = find((currentClean as any).nav, { type: 'timepicker' });
const originalTimepicker = find((originalClean as any).nav, { type: 'timepicker' });
if (currentTimepicker && originalTimepicker) {
currentTimepicker.now = originalTimepicker.now;

View File

@@ -17,7 +17,7 @@ export interface DashboardRowProps {
dashboard: DashboardModel;
}
export class DashboardRow extends React.Component<DashboardRowProps, any> {
export class DashboardRow extends React.Component<DashboardRowProps> {
sub?: Unsubscribable;
componentDidMount() {

View File

@@ -5,7 +5,7 @@ import { BrowserRouter } from 'react-router-dom';
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
import { NavModel, NavModelItem } from '@grafana/data';
import { setBackendSrv } from '@grafana/runtime';
import { BackendSrv, setBackendSrv } from '@grafana/runtime';
import { GrafanaContext } from 'app/core/context/GrafanaContext';
import { configureStore } from 'app/store/configureStore';
@@ -23,7 +23,7 @@ jest.mock('@grafana/runtime', () => ({
setBackendSrv({
get: jest.fn().mockResolvedValue([]),
} as any);
} as unknown as BackendSrv);
describe('DashboardSettings', () => {
it('pressing escape navigates away correctly', async () => {

View File

@@ -7,7 +7,7 @@ import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
import { byRole } from 'testing-library-selector';
import { selectors } from '@grafana/e2e-selectors';
import { setBackendSrv } from '@grafana/runtime';
import { BackendSrv, setBackendSrv } from '@grafana/runtime';
import { GrafanaContext } from 'app/core/context/GrafanaContext';
import { DashboardModel } from '../../state';
@@ -16,7 +16,7 @@ import { GeneralSettingsUnconnected as GeneralSettings, Props } from './GeneralS
setBackendSrv({
get: jest.fn().mockResolvedValue([]),
} as any);
} as unknown as BackendSrv);
const setupTestContext = (options: Partial<Props>) => {
const defaults: Props = {

View File

@@ -37,7 +37,9 @@ export function GeneralSettingsUnconnected({
};
const onBlur = (event: React.FocusEvent<HTMLInputElement>) => {
dashboard[event.currentTarget.name as 'title' | 'description'] = event.currentTarget.value;
if (event.currentTarget.name === 'title' || event.currentTarget.name === 'description') {
dashboard[event.currentTarget.name] = event.currentTarget.value;
}
};
const onTooltipChange = (graphTooltip: number) => {

View File

@@ -21,7 +21,7 @@ type State = {
isAppending: boolean;
versions: DecoratedRevisionModel[];
viewMode: 'list' | 'compare';
diffData: { lhs: any; rhs: any };
diffData: { lhs: unknown; rhs: unknown };
newInfo?: DecoratedRevisionModel;
baseInfo?: DecoratedRevisionModel;
isNewLatest: boolean;

View File

@@ -5,7 +5,7 @@ import { CollapsableSection, TagsInput, Select, Field, Input, Checkbox, Button,
import { DashboardLink, DashboardModel } from '../../state/DashboardModel';
export const newLink = {
export const newLink: DashboardLink = {
icon: 'external link',
title: 'New link',
tooltip: '',
@@ -16,7 +16,7 @@ export const newLink = {
targetBlank: false,
keepTime: false,
includeVars: false,
} as DashboardLink;
};
const linkTypeOptions = [
{ value: 'dashboards', label: 'Dashboards' },

View File

@@ -110,7 +110,7 @@ export class AngularPanelOptionsUnconnected extends PureComponent<Props> {
toggleOptionGroup: (index: number) => {
const tab = panelCtrl.editorTabs[index];
tab.isOpen = !tab.isOpen;
saveSectionOpenState(tab.title, tab.isOpen as boolean);
saveSectionOpenState(tab.title, Boolean(tab.isOpen));
},
};

View File

@@ -33,7 +33,7 @@ export function getFieldOverrideCategories(
return [];
}
const onOverrideChange = (index: number, override: any) => {
const onOverrideChange = (index: number, override: ConfigOverrideRule) => {
let overrides = cloneDeep(currentFieldConfig.overrides);
overrides[index] = override;
props.onFieldConfigsChange({ ...currentFieldConfig, overrides });

View File

@@ -196,7 +196,7 @@ export function fillOptionsPaneItems(
return (
<Editor
value={access.getValue(pluginOption.path)}
onChange={(value: any) => {
onChange={(value) => {
access.onChange(pluginOption.path, value);
}}
item={pluginOption}

View File

@@ -1,4 +1,10 @@
import { FieldConfig, FieldConfigSource, PanelPlugin, standardFieldConfigEditorRegistry } from '@grafana/data';
import {
FieldConfig,
FieldConfigSource,
PanelPlugin,
standardFieldConfigEditorRegistry,
ThresholdsMode,
} from '@grafana/data';
import { setOptionImmutably, supportsDataQuery, updateDefaultFieldConfigValue } from './utils';
@@ -8,10 +14,13 @@ describe('standardFieldConfigEditorRegistry', () => {
min: 10,
max: 10,
decimals: 10,
thresholds: {} as any,
thresholds: {
mode: ThresholdsMode.Absolute,
steps: [],
},
noValue: 'no value',
unit: 'km/s',
links: {} as any,
links: [],
};
it('make sure all fields have a valid name', () => {

View File

@@ -10,8 +10,8 @@ import { DiffViewer } from '../VersionHistory/DiffViewer';
import { Diffs } from '../VersionHistory/utils';
interface SaveDashboardDiffProps {
oldValue?: any;
newValue?: any;
oldValue?: unknown;
newValue?: unknown;
// calculated by parent so we can see summary in tabs
diff?: Diffs;

View File

@@ -62,7 +62,7 @@ beforeAll(() => {
],
},
],
} as any;
} as BootData;
server.listen({ onUnhandledRequest: 'bypass' });
});

View File

@@ -55,7 +55,7 @@ export const TransformationEditor = ({
React.createElement(uiConfig.editor, {
options: { ...uiConfig.transformation.defaultOptions, ...config.transformation.options },
input,
onChange: (opts: any) => {
onChange: (opts) => {
onChange(index, { id: config.transformation.id, options: opts });
},
}),

View File

@@ -38,19 +38,19 @@ describe('historySrv', () => {
getMock.mockImplementation(() => Promise.resolve(versionsResponse));
historySrv = new HistorySrv();
return historySrv.getHistoryList(dash, historyListOpts).then((versions: any) => {
return historySrv.getHistoryList(dash, historyListOpts).then((versions) => {
expect(versions).toEqual(versionsResponse);
});
});
it('should return an empty array when not given an id', () => {
return historySrv.getHistoryList(emptyDash, historyListOpts).then((versions: any) => {
return historySrv.getHistoryList(emptyDash, historyListOpts).then((versions) => {
expect(versions).toEqual([]);
});
});
it('should return an empty array when not given a dashboard', () => {
return historySrv.getHistoryList(null as unknown as DashboardModel, historyListOpts).then((versions: any) => {
return historySrv.getHistoryList(null as unknown as DashboardModel, historyListOpts).then((versions) => {
expect(versions).toEqual([]);
});
});
@@ -61,7 +61,7 @@ describe('historySrv', () => {
const version = 6;
postMock.mockImplementation(() => Promise.resolve(restoreResponse(version)));
historySrv = new HistorySrv();
return historySrv.restoreDashboard(dash, version).then((response: any) => {
return historySrv.restoreDashboard(dash, version).then((response) => {
expect(response).toEqual(restoreResponse(version));
});
});

View File

@@ -15,7 +15,7 @@ type DiffViewProps = {
isNewLatest: boolean;
newInfo: DecoratedRevisionModel;
baseInfo: DecoratedRevisionModel;
diffData: { lhs: any; rhs: any };
diffData: { lhs: unknown; rhs: unknown };
};
export const VersionHistoryComparison: React.FC<DiffViewProps> = ({ baseInfo, newInfo, diffData, isNewLatest }) => {