Types: Adds type safety to appEvents (#19418)

* Types: Add type safety to appEvents
This commit is contained in:
kay delaney
2019-10-14 09:27:47 +01:00
committed by GitHub
parent e7c37cc316
commit 99411bf37a
138 changed files with 991 additions and 508 deletions

View File

@@ -6,6 +6,7 @@ import appEvents from '../../core/app_events';
import { mockActionCreator } from 'app/core/redux';
import { updateLocation } from 'app/core/actions';
import { NavModel } from '@grafana/data';
import { CoreEvents } from 'app/types';
jest.mock('../../core/app_events', () => ({
emit: jest.fn(),
@@ -139,7 +140,7 @@ describe('Functions', () => {
instance.onOpenHowTo();
expect(appEvents.emit).toHaveBeenCalledWith('show-modal', {
expect(appEvents.emit).toHaveBeenCalledWith(CoreEvents.showModal, {
src: 'public/app/features/alerting/partials/alert_howto.html',
modalClass: 'confirm-modal',
model: {},

View File

@@ -6,7 +6,7 @@ import AlertRuleItem from './AlertRuleItem';
import appEvents from 'app/core/app_events';
import { updateLocation } from 'app/core/actions';
import { getNavModel } from 'app/core/selectors/navModel';
import { StoreState, AlertRule } from 'app/types';
import { StoreState, AlertRule, CoreEvents } from 'app/types';
import { getAlertRulesAsync, setSearchQuery, togglePauseAlertRule } from './state/actions';
import { getAlertRuleItems, getSearchQuery } from './state/selectors';
import { FilterInput } from 'app/core/components/FilterInput/FilterInput';
@@ -64,7 +64,7 @@ export class AlertRuleList extends PureComponent<Props, any> {
};
onOpenHowTo = () => {
appEvents.emit('show-modal', {
appEvents.emit(CoreEvents.showModal, {
src: 'public/app/features/alerting/partials/alert_howto.html',
modalClass: 'confirm-modal',
model: {},

View File

@@ -19,6 +19,7 @@ import { TestRuleResult } from './TestRuleResult';
import { AppNotificationSeverity, StoreState } from 'app/types';
import { PanelEditorTabIds, getPanelEditorTab } from '../dashboard/panel_editor/state/reducers';
import { changePanelEditorTab } from '../dashboard/panel_editor/state/actions';
import { CoreEvents } from 'app/types';
interface Props {
angularPanel?: AngularComponent;
@@ -116,7 +117,7 @@ class UnConnectedAlertTab extends PureComponent<Props, State> {
title: 'Delete',
btnType: 'danger',
onClick: () => {
appEvents.emit('confirm-modal', {
appEvents.emit(CoreEvents.showConfirmModal, {
title: 'Delete Alert',
text: 'Are you sure you want to delete this alert rule?',
text2: 'You need to save dashboard for the delete to take effect',

View File

@@ -11,6 +11,7 @@ import DatasourceSrv from '../plugins/datasource_srv';
import { DataQuery } from '@grafana/ui/src/types/datasource';
import { PanelModel } from 'app/features/dashboard/state';
import { getDefaultCondition } from './getAlertingValidationMessage';
import { CoreEvents } from 'app/types';
export class AlertTabCtrl {
panel: PanelModel;
@@ -58,11 +59,11 @@ export class AlertTabCtrl {
// subscribe to graph threshold handle changes
const thresholdChangedEventHandler = this.graphThresholdChanged.bind(this);
this.panelCtrl.events.on('threshold-changed', thresholdChangedEventHandler);
this.panelCtrl.events.on(CoreEvents.thresholdChanged, thresholdChangedEventHandler);
// set panel alert edit mode
this.$scope.$on('$destroy', () => {
this.panelCtrl.events.off('threshold-changed', thresholdChangedEventHandler);
this.panelCtrl.events.off(CoreEvents.thresholdChanged, thresholdChangedEventHandler);
this.panelCtrl.editingThresholds = false;
this.panelCtrl.render();
});
@@ -352,7 +353,7 @@ export class AlertTabCtrl {
}
delete() {
appEvents.emit('confirm-modal', {
appEvents.emit(CoreEvents.showConfirmModal, {
title: 'Delete Alert',
text: 'Are you sure you want to delete this alert rule?',
text2: 'You need to save dashboard for the delete to take effect',
@@ -402,7 +403,7 @@ export class AlertTabCtrl {
}
clearHistory() {
appEvents.emit('confirm-modal', {
appEvents.emit(CoreEvents.showConfirmModal, {
title: 'Delete Alert History',
text: 'Are you sure you want to remove all history & annotations for this alert?',
icon: 'fa-trash',

View File

@@ -1,6 +1,7 @@
import _ from 'lodash';
import { appEvents, coreModule, NavModelSrv } from 'app/core/core';
import { BackendSrv } from 'app/core/services/backend_srv';
import { AppEvents } from '@grafana/data';
export class AlertNotificationEditCtrl {
theForm: any;
@@ -78,23 +79,23 @@ export class AlertNotificationEditCtrl {
.put(`/api/alert-notifications/${this.model.id}`, this.model)
.then((res: any) => {
this.model = res;
appEvents.emit('alert-success', ['Notification updated', '']);
appEvents.emit(AppEvents.alertSuccess, ['Notification updated']);
})
.catch((err: any) => {
if (err.data && err.data.error) {
appEvents.emit('alert-error', [err.data.error]);
appEvents.emit(AppEvents.alertError, [err.data.error]);
}
});
} else {
this.backendSrv
.post(`/api/alert-notifications`, this.model)
.then((res: any) => {
appEvents.emit('alert-success', ['Notification created', '']);
appEvents.emit(AppEvents.alertSuccess, ['Notification created']);
this.$location.path('alerting/notifications');
})
.catch((err: any) => {
if (err.data && err.data.error) {
appEvents.emit('alert-error', [err.data.error]);
appEvents.emit(AppEvents.alertError, [err.data.error]);
}
});
}

View File

@@ -3,6 +3,7 @@ import alertDef from './state/alertDef';
import { getBackendSrv } from '@grafana/runtime';
import { DashboardModel } from '../dashboard/state/DashboardModel';
import appEvents from '../../core/app_events';
import { CoreEvents } from 'app/types';
interface Props {
dashboard: DashboardModel;
@@ -42,7 +43,7 @@ class StateHistory extends PureComponent<Props, State> {
clearHistory = () => {
const { dashboard, onRefresh, panelId } = this.props;
appEvents.emit('confirm-modal', {
appEvents.emit(CoreEvents.showConfirmModal, {
title: 'Delete Alert History',
text: 'Are you sure you want to remove all history & annotations for this alert?',
icon: 'fa-trash',

View File

@@ -5,6 +5,7 @@ import appEvents from 'app/core/app_events';
import { CopyToClipboard } from 'app/core/components/CopyToClipboard/CopyToClipboard';
import { DashboardModel } from '../dashboard/state/DashboardModel';
import { getBackendSrv, BackendSrv } from '@grafana/runtime';
import { AppEvents } from '@grafana/data';
export interface Props {
panelId: number;
@@ -55,7 +56,7 @@ export class TestRuleResult extends PureComponent<Props, State> {
};
onClipboardSuccess = () => {
appEvents.emit('alert-success', ['Content copied to clipboard']);
appEvents.emit(AppEvents.alertSuccess, ['Content copied to clipboard']);
};
onToggleExpand = () => {