mirror of
https://github.com/grafana/grafana.git
synced 2026-09-05 04:40:13 -05:00
AppNotifications: Migrate usage of deprecated appEvents.emit method to redux actions (#45607)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Input, Field, Button, ValuePicker, HorizontalGroup } from '@grafana/ui';
|
||||
import { DataSourcePicker, getBackendSrv } from '@grafana/runtime';
|
||||
import { AppEvents, DataSourceRef, LiveChannelScope, SelectableValue } from '@grafana/data';
|
||||
import appEvents from 'app/core/app_events';
|
||||
import { DataSourceRef, LiveChannelScope, SelectableValue } from '@grafana/data';
|
||||
import { useAppNotification } from 'app/core/copy/appNotification';
|
||||
import { Rule } from './types';
|
||||
|
||||
interface Props {
|
||||
@@ -29,14 +29,15 @@ export function AddNewRule({ onRuleAdded }: Props) {
|
||||
const [pattern, setPattern] = useState<string>();
|
||||
const [patternPrefix, setPatternPrefix] = useState<string>('');
|
||||
const [datasource, setDatasource] = useState<DataSourceRef>();
|
||||
const notifyApp = useAppNotification();
|
||||
|
||||
const onSubmit = () => {
|
||||
if (!pattern) {
|
||||
appEvents.emit(AppEvents.alertError, ['Enter path']);
|
||||
notifyApp.error('Enter path');
|
||||
return;
|
||||
}
|
||||
if (patternType === 'ds' && !patternPrefix.length) {
|
||||
appEvents.emit(AppEvents.alertError, ['Select datasource']);
|
||||
notifyApp.error('Select datasource');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,7 +62,7 @@ export function AddNewRule({ onRuleAdded }: Props) {
|
||||
onRuleAdded(v.rule);
|
||||
})
|
||||
.catch((e) => {
|
||||
appEvents.emit(AppEvents.alertError, ['Error adding rule', e]);
|
||||
notifyApp.error('Error adding rule', e);
|
||||
e.isHandled = true;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user