mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Show error message when error is thrown after clicking create alert f… (#84367)
Show error message when error is thrown after clicking create alert from panel
This commit is contained in:
parent
0acb400248
commit
39232a0776
@ -1,16 +1,20 @@
|
|||||||
import {
|
import {
|
||||||
getTimeZone,
|
|
||||||
PanelMenuItem,
|
PanelMenuItem,
|
||||||
PluginExtensionPoints,
|
PluginExtensionPoints,
|
||||||
|
getTimeZone,
|
||||||
urlUtil,
|
urlUtil,
|
||||||
type PluginExtensionPanelContext,
|
type PluginExtensionPanelContext,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { AngularComponent, getPluginLinkExtensions, locationService } from '@grafana/runtime';
|
import { AngularComponent, getPluginLinkExtensions, locationService } from '@grafana/runtime';
|
||||||
import { PanelCtrl } from 'app/angular/panel/panel_ctrl';
|
import { PanelCtrl } from 'app/angular/panel/panel_ctrl';
|
||||||
import config from 'app/core/config';
|
import config from 'app/core/config';
|
||||||
|
import { createErrorNotification } from 'app/core/copy/appNotification';
|
||||||
import { t } from 'app/core/internationalization';
|
import { t } from 'app/core/internationalization';
|
||||||
|
import { notifyApp } from 'app/core/reducers/appNotification';
|
||||||
import { contextSrv } from 'app/core/services/context_srv';
|
import { contextSrv } from 'app/core/services/context_srv';
|
||||||
|
import { getMessageFromError } from 'app/core/utils/errors';
|
||||||
import { getExploreUrl } from 'app/core/utils/explore';
|
import { getExploreUrl } from 'app/core/utils/explore';
|
||||||
|
import { RuleFormValues } from 'app/features/alerting/unified/types/rule-form';
|
||||||
import { panelToRuleFormValues } from 'app/features/alerting/unified/utils/rule-form';
|
import { panelToRuleFormValues } from 'app/features/alerting/unified/utils/rule-form';
|
||||||
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
|
import { DashboardModel } from 'app/features/dashboard/state/DashboardModel';
|
||||||
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
import { PanelModel } from 'app/features/dashboard/state/PanelModel';
|
||||||
@ -28,7 +32,7 @@ import { InspectTab } from 'app/features/inspector/types';
|
|||||||
import { isPanelModelLibraryPanel } from 'app/features/library-panels/guard';
|
import { isPanelModelLibraryPanel } from 'app/features/library-panels/guard';
|
||||||
import { createExtensionSubMenu } from 'app/features/plugins/extensions/utils';
|
import { createExtensionSubMenu } from 'app/features/plugins/extensions/utils';
|
||||||
import { SHARED_DASHBOARD_QUERY } from 'app/plugins/datasource/dashboard';
|
import { SHARED_DASHBOARD_QUERY } from 'app/plugins/datasource/dashboard';
|
||||||
import { store } from 'app/store/store';
|
import { dispatch, store } from 'app/store/store';
|
||||||
|
|
||||||
import { getCreateAlertInMenuAvailability } from '../../alerting/unified/utils/access-control';
|
import { getCreateAlertInMenuAvailability } from '../../alerting/unified/utils/access-control';
|
||||||
import { navigateToExplore } from '../../explore/state/main';
|
import { navigateToExplore } from '../../explore/state/main';
|
||||||
@ -206,8 +210,14 @@ export function getPanelMenu(
|
|||||||
});
|
});
|
||||||
|
|
||||||
const createAlert = async () => {
|
const createAlert = async () => {
|
||||||
const formValues = await panelToRuleFormValues(panel, dashboard);
|
let formValues: Partial<RuleFormValues> | undefined;
|
||||||
|
try {
|
||||||
|
formValues = await panelToRuleFormValues(panel, dashboard);
|
||||||
|
} catch (err) {
|
||||||
|
const message = `Error getting rule values from the panel: ${getMessageFromError(err)}`;
|
||||||
|
dispatch(notifyApp(createErrorNotification(message)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
const ruleFormUrl = urlUtil.renderUrl('/alerting/new', {
|
const ruleFormUrl = urlUtil.renderUrl('/alerting/new', {
|
||||||
defaults: JSON.stringify(formValues),
|
defaults: JSON.stringify(formValues),
|
||||||
returnTo: location.pathname + location.search,
|
returnTo: location.pathname + location.search,
|
||||||
|
Loading…
Reference in New Issue
Block a user