From 39232a07761f862bed150faa85d6169c95493a77 Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Fri, 15 Mar 2024 12:36:34 +0100 Subject: [PATCH] =?UTF-8?q?Alerting:=20Show=20error=20message=20when=20err?= =?UTF-8?q?or=20is=20thrown=20after=20clicking=20create=20alert=20f?= =?UTF-8?q?=E2=80=A6=20(#84367)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Show error message when error is thrown after clicking create alert from panel --- .../features/dashboard/utils/getPanelMenu.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/public/app/features/dashboard/utils/getPanelMenu.ts b/public/app/features/dashboard/utils/getPanelMenu.ts index e1b30e22b21..ddd8a149eb9 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.ts @@ -1,16 +1,20 @@ import { - getTimeZone, PanelMenuItem, PluginExtensionPoints, + getTimeZone, urlUtil, type PluginExtensionPanelContext, } from '@grafana/data'; import { AngularComponent, getPluginLinkExtensions, locationService } from '@grafana/runtime'; import { PanelCtrl } from 'app/angular/panel/panel_ctrl'; import config from 'app/core/config'; +import { createErrorNotification } from 'app/core/copy/appNotification'; import { t } from 'app/core/internationalization'; +import { notifyApp } from 'app/core/reducers/appNotification'; import { contextSrv } from 'app/core/services/context_srv'; +import { getMessageFromError } from 'app/core/utils/errors'; 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 { DashboardModel } from 'app/features/dashboard/state/DashboardModel'; 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 { createExtensionSubMenu } from 'app/features/plugins/extensions/utils'; 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 { navigateToExplore } from '../../explore/state/main'; @@ -206,8 +210,14 @@ export function getPanelMenu( }); const createAlert = async () => { - const formValues = await panelToRuleFormValues(panel, dashboard); - + let formValues: Partial | 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', { defaults: JSON.stringify(formValues), returnTo: location.pathname + location.search,