mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: fix some anys pt.2 (#53928)
* correctly type some more any's * undo this change for now...
This commit is contained in:
@@ -70,7 +70,7 @@ export const DashNav = React.memo<Props>((props) => {
|
||||
const dashboardSrv = getDashboardSrv();
|
||||
const { dashboard, setStarred } = props;
|
||||
|
||||
dashboardSrv.starDashboard(dashboard.id, dashboard.meta.isStarred).then((newState: any) => {
|
||||
dashboardSrv.starDashboard(dashboard.id, dashboard.meta.isStarred).then((newState) => {
|
||||
setStarred({ id: dashboard.uid, title: dashboard.title, url: dashboard.meta.url ?? '', isStarred: newState });
|
||||
dashboard.meta.isStarred = newState;
|
||||
forceUpdate();
|
||||
|
||||
@@ -3,6 +3,7 @@ import React from 'react';
|
||||
|
||||
import { getDashboardModel } from '../../../../../test/helpers/getDashboardModel';
|
||||
import { DashboardModel } from '../../state/DashboardModel';
|
||||
import { PanelModel } from '../../state/PanelModel';
|
||||
|
||||
import { DashNavTimeControls } from './DashNavTimeControls';
|
||||
|
||||
@@ -47,7 +48,7 @@ describe('DashNavTimeControls', () => {
|
||||
});
|
||||
|
||||
it('should not render RefreshPicker interval button in panel edit', () => {
|
||||
const panel: any = { destroy: jest.fn(), isEditing: true };
|
||||
const panel: PanelModel = new PanelModel({ destroy: jest.fn(), isEditing: true });
|
||||
dashboardModel.startRefresh = jest.fn();
|
||||
dashboardModel.panelInEdit = panel;
|
||||
const container = render(
|
||||
@@ -57,7 +58,7 @@ describe('DashNavTimeControls', () => {
|
||||
});
|
||||
|
||||
it('should render RefreshPicker run button in panel edit', () => {
|
||||
const panel: any = { destroy: jest.fn(), isEditing: true };
|
||||
const panel: PanelModel = new PanelModel({ destroy: jest.fn(), isEditing: true });
|
||||
dashboardModel.startRefresh = jest.fn();
|
||||
dashboardModel.panelInEdit = panel;
|
||||
const container = render(
|
||||
|
||||
@@ -7,10 +7,12 @@ import { selectors } from '@grafana/e2e-selectors';
|
||||
import { setAngularLoader, setDataSourceSrv } from '@grafana/runtime';
|
||||
import { mockDataSource, MockDataSourceSrv } from 'app/features/alerting/unified/mocks';
|
||||
|
||||
import { DashboardModel } from '../../state/DashboardModel';
|
||||
|
||||
import { AnnotationsSettings } from './AnnotationsSettings';
|
||||
|
||||
describe('AnnotationsSettings', () => {
|
||||
let dashboard: any;
|
||||
let dashboard: DashboardModel;
|
||||
|
||||
const dataSources = {
|
||||
grafana: mockDataSource(
|
||||
@@ -57,7 +59,7 @@ describe('AnnotationsSettings', () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
dashboard = {
|
||||
dashboard = new DashboardModel({
|
||||
id: 74,
|
||||
version: 7,
|
||||
annotations: {
|
||||
@@ -74,7 +76,7 @@ describe('AnnotationsSettings', () => {
|
||||
],
|
||||
},
|
||||
links: [],
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
test('it renders a header and cta if no annotations or only builtIn annotation', async () => {
|
||||
@@ -143,12 +145,12 @@ describe('AnnotationsSettings', () => {
|
||||
type: 'dashboard',
|
||||
},
|
||||
];
|
||||
const dashboardWithAnnotations = {
|
||||
const dashboardWithAnnotations = new DashboardModel({
|
||||
...dashboard,
|
||||
annotations: {
|
||||
list: [...annotationsList],
|
||||
},
|
||||
};
|
||||
});
|
||||
render(<AnnotationsSettings dashboard={dashboardWithAnnotations} />);
|
||||
// Check that we have the correct annotations
|
||||
expect(screen.queryByText(/prometheus/i)).toBeInTheDocument();
|
||||
@@ -177,12 +179,12 @@ describe('AnnotationsSettings', () => {
|
||||
type: 'dashboard',
|
||||
},
|
||||
];
|
||||
const dashboardWithAnnotations = {
|
||||
const dashboardWithAnnotations = new DashboardModel({
|
||||
...dashboard,
|
||||
annotations: {
|
||||
list: [...annotationsList],
|
||||
},
|
||||
};
|
||||
});
|
||||
render(<AnnotationsSettings dashboard={dashboardWithAnnotations} />);
|
||||
// Check that we have sorting buttons
|
||||
expect(within(getTableBodyRows()[0]).queryByRole('button', { name: 'arrow-up' })).not.toBeInTheDocument();
|
||||
|
||||
@@ -99,7 +99,7 @@ describe('getValidIntervals', () => {
|
||||
const dependencies = {
|
||||
getTimeSrv: () =>
|
||||
({
|
||||
getValidIntervals: (intervals: any) => intervals,
|
||||
getValidIntervals: (intervals: string[]) => intervals,
|
||||
} as unknown as TimeSrv),
|
||||
};
|
||||
|
||||
@@ -115,7 +115,7 @@ describe('getValidIntervals', () => {
|
||||
const dependencies = {
|
||||
getTimeSrv: () =>
|
||||
({
|
||||
getValidIntervals: (intervals: any) => intervals,
|
||||
getValidIntervals: (intervals: string[]) => intervals,
|
||||
} as unknown as TimeSrv),
|
||||
};
|
||||
|
||||
@@ -131,7 +131,7 @@ describe('getValidIntervals', () => {
|
||||
const dependencies = {
|
||||
getTimeSrv: () =>
|
||||
({
|
||||
getValidIntervals: (intervals: any) => intervals,
|
||||
getValidIntervals: (intervals: string[]) => intervals,
|
||||
} as unknown as TimeSrv),
|
||||
};
|
||||
|
||||
@@ -148,7 +148,7 @@ describe('validateIntervals', () => {
|
||||
const dependencies = {
|
||||
getTimeSrv: () =>
|
||||
({
|
||||
getValidIntervals: (intervals: any) => intervals,
|
||||
getValidIntervals: (intervals: string[]) => intervals,
|
||||
} as unknown as TimeSrv),
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event';
|
||||
import { UserEvent } from '@testing-library/user-event/dist/types/setup';
|
||||
import React from 'react';
|
||||
|
||||
import { DashboardModel } from '../../state/DashboardModel';
|
||||
import { historySrv } from '../VersionHistory/HistorySrv';
|
||||
|
||||
import { VersionsSettings, VERSIONS_FETCH_LIMIT } from './VersionsSettings';
|
||||
@@ -23,12 +24,12 @@ const queryByFullText = (text: string) =>
|
||||
});
|
||||
|
||||
describe('VersionSettings', () => {
|
||||
const dashboard: any = {
|
||||
const dashboard = new DashboardModel({
|
||||
id: 74,
|
||||
version: 11,
|
||||
formatDate: jest.fn(() => 'date'),
|
||||
getRelativeTime: jest.fn(() => 'time ago'),
|
||||
};
|
||||
});
|
||||
|
||||
let user: UserEvent;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ export const LinkSettingsEdit: React.FC<LinkSettingsEditProps> = ({ editLinkIdx,
|
||||
setLinkSettings(link);
|
||||
};
|
||||
|
||||
const onTagsChange = (tags: any[]) => {
|
||||
const onTagsChange = (tags: string[]) => {
|
||||
onUpdate({ ...linkSettings, tags: tags });
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import { useAsync } from 'react-use';
|
||||
|
||||
import { config } from '@grafana/runtime';
|
||||
import { config, isFetchError } from '@grafana/runtime';
|
||||
import { Drawer, Spinner, Tab, TabsBar } from '@grafana/ui';
|
||||
import { backendSrv } from 'app/core/services/backend_srv';
|
||||
|
||||
@@ -126,7 +126,7 @@ export const SaveDashboardDrawer = ({ dashboard, onDismiss, onSaveSuccess, isCop
|
||||
);
|
||||
};
|
||||
|
||||
if (state.error) {
|
||||
if (state.error && isFetchError(state.error)) {
|
||||
return (
|
||||
<SaveDashboardErrorProxy
|
||||
error={state.error}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { css } from '@emotion/css';
|
||||
import React, { useEffect } from 'react';
|
||||
|
||||
import { GrafanaTheme } from '@grafana/data';
|
||||
import { FetchError } from '@grafana/runtime';
|
||||
import { Button, ConfirmModal, Modal, stylesFactory, useTheme } from '@grafana/ui';
|
||||
import { DashboardModel } from 'app/features/dashboard/state';
|
||||
|
||||
@@ -14,7 +15,7 @@ interface SaveDashboardErrorProxyProps {
|
||||
dashboard: DashboardModel;
|
||||
/** dashboard save model with applied modifications, i.e. title */
|
||||
dashboardSaveModel: any;
|
||||
error: any;
|
||||
error: FetchError;
|
||||
onDismiss: () => void;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ interface SaveDashboardAsFormDTO {
|
||||
}
|
||||
|
||||
const getSaveAsDashboardClone = (dashboard: DashboardModel) => {
|
||||
const clone: any = dashboard.getSaveModelClone();
|
||||
const clone = dashboard.getSaveModelClone();
|
||||
clone.id = null;
|
||||
clone.uid = '';
|
||||
clone.title += ' Copy';
|
||||
|
||||
@@ -15,7 +15,7 @@ export type SaveProps = {
|
||||
saveModel: SaveDashboardData; // already cloned
|
||||
onCancel: () => void;
|
||||
onSuccess: () => void;
|
||||
onSubmit?: (clone: any, options: SaveDashboardOptions, dashboard: DashboardModel) => Promise<any>;
|
||||
onSubmit?: (clone: DashboardModel, options: SaveDashboardOptions, dashboard: DashboardModel) => Promise<any>;
|
||||
options: SaveDashboardOptions;
|
||||
onOptionsChange: (opts: SaveDashboardOptions) => void;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
|
||||
import { BootData } from '@grafana/data';
|
||||
import { setEchoSrv } from '@grafana/runtime/src';
|
||||
import config from 'app/core/config';
|
||||
|
||||
@@ -48,7 +49,7 @@ function mockLocationHref(href: string) {
|
||||
}
|
||||
|
||||
describe('ShareEmbed', () => {
|
||||
let originalBootData: any;
|
||||
let originalBootData: BootData;
|
||||
|
||||
beforeAll(() => {
|
||||
setEchoSrv(new Echo());
|
||||
|
||||
@@ -54,11 +54,11 @@ export class ShareExport extends PureComponent<Props, State> {
|
||||
const { trimDefaults } = this.state;
|
||||
|
||||
if (shareExternally) {
|
||||
this.exporter.makeExportable(dashboard).then((dashboardJson: any) => {
|
||||
this.exporter.makeExportable(dashboard).then((dashboardJson) => {
|
||||
if (trimDefaults) {
|
||||
getBackendSrv()
|
||||
.post('/api/dashboards/trim', { dashboard: dashboardJson })
|
||||
.then((resp: any) => {
|
||||
.then((resp) => {
|
||||
this.openSaveAsDialog(resp.dashboard);
|
||||
});
|
||||
} else {
|
||||
@@ -69,7 +69,7 @@ export class ShareExport extends PureComponent<Props, State> {
|
||||
if (trimDefaults) {
|
||||
getBackendSrv()
|
||||
.post('/api/dashboards/trim', { dashboard: dashboard.getSaveModelClone() })
|
||||
.then((resp: any) => {
|
||||
.then((resp) => {
|
||||
this.openSaveAsDialog(resp.dashboard);
|
||||
});
|
||||
} else {
|
||||
@@ -84,11 +84,11 @@ export class ShareExport extends PureComponent<Props, State> {
|
||||
const { trimDefaults } = this.state;
|
||||
|
||||
if (shareExternally) {
|
||||
this.exporter.makeExportable(dashboard).then((dashboardJson: any) => {
|
||||
this.exporter.makeExportable(dashboard).then((dashboardJson) => {
|
||||
if (trimDefaults) {
|
||||
getBackendSrv()
|
||||
.post('/api/dashboards/trim', { dashboard: dashboardJson })
|
||||
.then((resp: any) => {
|
||||
.then((resp) => {
|
||||
this.openJsonModal(resp.dashboard);
|
||||
});
|
||||
} else {
|
||||
@@ -99,7 +99,7 @@ export class ShareExport extends PureComponent<Props, State> {
|
||||
if (trimDefaults) {
|
||||
getBackendSrv()
|
||||
.post('/api/dashboards/trim', { dashboard: dashboard.getSaveModelClone() })
|
||||
.then((resp: any) => {
|
||||
.then((resp) => {
|
||||
this.openJsonModal(resp.dashboard);
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
|
||||
import { BootData } from '@grafana/data';
|
||||
import { BackendSrv, setEchoSrv } from '@grafana/runtime';
|
||||
import config from 'app/core/config';
|
||||
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
|
||||
@@ -44,7 +45,7 @@ jest.mock('app/core/core', () => {
|
||||
});
|
||||
|
||||
describe('SharePublic', () => {
|
||||
let originalBootData: any;
|
||||
let originalBootData: BootData;
|
||||
|
||||
beforeAll(() => {
|
||||
setEchoSrv(new Echo());
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import React, { FunctionComponent, useEffect, useState } from 'react';
|
||||
|
||||
import { AnnotationQuery, EventBus } from '@grafana/data';
|
||||
import { AnnotationQuery, DataQuery, EventBus } from '@grafana/data';
|
||||
|
||||
import { AnnotationPicker } from './AnnotationPicker';
|
||||
|
||||
interface Props {
|
||||
events: EventBus;
|
||||
annotations: AnnotationQuery[];
|
||||
onAnnotationChanged: (annotation: any) => void;
|
||||
onAnnotationChanged: (annotation: AnnotationQuery<DataQuery>) => void;
|
||||
}
|
||||
|
||||
export const Annotations: FunctionComponent<Props> = ({ annotations, onAnnotationChanged, events }) => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { css } from '@emotion/css';
|
||||
import React, { PureComponent } from 'react';
|
||||
import { connect, MapStateToProps } from 'react-redux';
|
||||
|
||||
import { AnnotationQuery } from '@grafana/data';
|
||||
import { AnnotationQuery, DataQuery } from '@grafana/data';
|
||||
|
||||
import { StoreState } from '../../../../types';
|
||||
import { getSubMenuVariables, getVariablesState } from '../../../variables/state/selectors';
|
||||
@@ -29,7 +29,7 @@ interface DispatchProps {}
|
||||
type Props = OwnProps & ConnectedProps & DispatchProps;
|
||||
|
||||
class SubMenuUnConnected extends PureComponent<Props> {
|
||||
onAnnotationStateChanged = (updatedAnnotation: any) => {
|
||||
onAnnotationStateChanged = (updatedAnnotation: AnnotationQuery<DataQuery>) => {
|
||||
// we're mutating dashboard state directly here until annotations are in Redux.
|
||||
for (let index = 0; index < this.props.dashboard.annotations.list.length; index++) {
|
||||
const annotation = this.props.dashboard.annotations.list[index];
|
||||
|
||||
Reference in New Issue
Block a user