Chore: some type fixes (#69860)

* some type fixes

* restore empty object

* undo 1 fix for now

* commit betterer update

* explicitly type slug and uid as string | undefined
This commit is contained in:
Ashley Harrison
2023-06-20 17:13:49 +01:00
committed by GitHub
parent c07d3c7bdd
commit 13e3308959
17 changed files with 91 additions and 141 deletions

View File

@@ -1,3 +1,5 @@
import { Store } from 'redux';
import {
dateTime,
FieldType,
@@ -8,7 +10,7 @@ import {
PluginExtensionTypes,
toDataFrame,
} from '@grafana/data';
import { getPluginExtensions } from '@grafana/runtime';
import { AngularComponent, getPluginExtensions } from '@grafana/runtime';
import config from 'app/core/config';
import * as actions from 'app/features/explore/state/main';
import { setStore } from 'app/store/store';
@@ -292,9 +294,9 @@ describe('getPanelMenu()', () => {
describe('when panel is in view mode', () => {
it('should return the correct panel menu items', () => {
const getExtendedMenu = () => [{ text: 'Toggle legend', shortcut: 'p l', click: jest.fn() }];
const ctrl: any = { getExtendedMenu };
const scope: any = { $$childHead: { ctrl } };
const angularComponent: any = { getScope: () => scope };
const ctrl = { getExtendedMenu };
const scope = { $$childHead: { ctrl } };
const angularComponent = { getScope: () => scope } as AngularComponent;
const panel = new PanelModel({ isViewing: true });
const dashboard = createDashboardModelFixture({});
@@ -363,7 +365,7 @@ describe('getPanelMenu()', () => {
const windowOpen = jest.fn();
let event: any;
let explore: PanelMenuItem;
let navigateSpy: any;
let navigateSpy: jest.SpyInstance;
beforeAll(() => {
const panel = new PanelModel({});
@@ -378,7 +380,7 @@ describe('getPanelMenu()', () => {
preventDefault: jest.fn(),
};
setStore({ dispatch: jest.fn() } as any);
setStore({ dispatch: jest.fn() } as unknown as Store);
});
it('should navigate to url without subUrl', () => {

View File

@@ -36,7 +36,7 @@ export function getPanelMenu(
panel: PanelModel,
angularComponent?: AngularComponent | null
): PanelMenuItem[] {
const onViewPanel = (event: React.MouseEvent<any>) => {
const onViewPanel = (event: React.MouseEvent) => {
event.preventDefault();
locationService.partial({
viewPanel: panel.id,
@@ -44,7 +44,7 @@ export function getPanelMenu(
reportInteraction('dashboards_panelheader_menu', { item: 'view' });
};
const onEditPanel = (event: React.MouseEvent<any>) => {
const onEditPanel = (event: React.MouseEvent) => {
event.preventDefault();
locationService.partial({
editPanel: panel.id,
@@ -53,19 +53,19 @@ export function getPanelMenu(
reportInteraction('dashboards_panelheader_menu', { item: 'edit' });
};
const onSharePanel = (event: React.MouseEvent<any>) => {
const onSharePanel = (event: React.MouseEvent) => {
event.preventDefault();
sharePanel(dashboard, panel);
reportInteraction('dashboards_panelheader_menu', { item: 'share' });
};
const onAddLibraryPanel = (event: React.MouseEvent<any>) => {
const onAddLibraryPanel = (event: React.MouseEvent) => {
event.preventDefault();
addLibraryPanel(dashboard, panel);
reportInteraction('dashboards_panelheader_menu', { item: 'createLibraryPanel' });
};
const onUnlinkLibraryPanel = (event: React.MouseEvent<any>) => {
const onUnlinkLibraryPanel = (event: React.MouseEvent) => {
event.preventDefault();
unlinkLibraryPanel(panel);
reportInteraction('dashboards_panelheader_menu', { item: 'unlinkLibraryPanel' });
@@ -79,29 +79,29 @@ export function getPanelMenu(
reportInteraction('dashboards_panelheader_menu', { item: 'inspect', tab: tab ?? InspectTab.Data });
};
const onMore = (event: React.MouseEvent<any>) => {
const onMore = (event: React.MouseEvent) => {
event.preventDefault();
};
const onDuplicatePanel = (event: React.MouseEvent<any>) => {
const onDuplicatePanel = (event: React.MouseEvent) => {
event.preventDefault();
duplicatePanel(dashboard, panel);
reportInteraction('dashboards_panelheader_menu', { item: 'duplicate' });
};
const onCopyPanel = (event: React.MouseEvent<any>) => {
const onCopyPanel = (event: React.MouseEvent) => {
event.preventDefault();
copyPanel(panel);
reportInteraction('dashboards_panelheader_menu', { item: 'copy' });
};
const onRemovePanel = (event: React.MouseEvent<any>) => {
const onRemovePanel = (event: React.MouseEvent) => {
event.preventDefault();
removePanel(dashboard, panel, true);
reportInteraction('dashboards_panelheader_menu', { item: 'remove' });
};
const onNavigateToExplore = (event: React.MouseEvent<any>) => {
const onNavigateToExplore = (event: React.MouseEvent) => {
event.preventDefault();
const openInNewWindow =
event.ctrlKey || event.metaKey ? (url: string) => window.open(`${config.appSubUrl}${url}`) : undefined;
@@ -161,20 +161,20 @@ export function getPanelMenu(
if (panel.plugin && !panel.plugin.meta.skipDataQuery) {
inspectMenu.push({
text: t('panel.header-menu.inspect-data', `Data`),
onClick: (e: React.MouseEvent<any>) => onInspectPanel(InspectTab.Data),
onClick: (e: React.MouseEvent) => onInspectPanel(InspectTab.Data),
});
if (dashboard.meta.canEdit) {
inspectMenu.push({
text: t('panel.header-menu.query', `Query`),
onClick: (e: React.MouseEvent<any>) => onInspectPanel(InspectTab.Query),
onClick: (e: React.MouseEvent) => onInspectPanel(InspectTab.Query),
});
}
}
inspectMenu.push({
text: t('panel.header-menu.inspect-json', `Panel JSON`),
onClick: (e: React.MouseEvent<any>) => onInspectPanel(InspectTab.JSON),
onClick: (e: React.MouseEvent) => onInspectPanel(InspectTab.JSON),
});
menu.push({

View File

@@ -16,14 +16,14 @@ const mutableKeys = new Set<keyof PanelModel>(['gridPos', 'title', 'description'
export function mergePanels(current: PanelModel[], data: IPanelModel[]): PanelMergeInfo {
const panels: PanelModel[] = [];
const info = {
const info: PanelMergeInfo = {
changed: false,
actions: {
add: [] as number[],
remove: [] as number[],
replace: [] as number[],
update: [] as number[],
noop: [] as number[],
add: [],
remove: [],
replace: [],
update: [],
noop: [],
},
panels,
};
@@ -110,7 +110,7 @@ export function mergePanels(current: PanelModel[], data: IPanelModel[]): PanelMe
}
// Since +- Infinity are saved as null in JSON, we need to make them equal here also
function infinityEqualsNull(a: any, b: any) {
function infinityEqualsNull(a: unknown, b: unknown) {
if (a == null && (b === Infinity || b === -Infinity || b == null)) {
return true;
}