From 1633bacba9cf4df6a6a237cf5a02303c70745ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 30 Mar 2020 13:50:18 +0200 Subject: [PATCH] NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179) --- public/app/features/alerting/AlertTab.tsx | 4 ++-- .../features/alerting/TestRuleResult.test.tsx | 4 ++-- public/app/features/alerting/TestRuleResult.tsx | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/public/app/features/alerting/AlertTab.tsx b/public/app/features/alerting/AlertTab.tsx index 538d9a88ebb..845a08f9c8f 100644 --- a/public/app/features/alerting/AlertTab.tsx +++ b/public/app/features/alerting/AlertTab.tsx @@ -145,8 +145,8 @@ class UnConnectedAlertTab extends PureComponent { }; renderTestRuleResult = () => { - const { panel, dashboard } = this.props; - return ; + const { dashboard, panel } = this.props; + return ; }; testRule = (): EditorToolbarView => ({ diff --git a/public/app/features/alerting/TestRuleResult.test.tsx b/public/app/features/alerting/TestRuleResult.test.tsx index acaff7f86af..984ea78c36e 100644 --- a/public/app/features/alerting/TestRuleResult.test.tsx +++ b/public/app/features/alerting/TestRuleResult.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { TestRuleResult, Props } from './TestRuleResult'; -import { DashboardModel } from '../dashboard/state'; +import { DashboardModel, PanelModel } from '../dashboard/state'; import { shallow } from 'enzyme'; jest.mock('@grafana/runtime', () => { @@ -16,7 +16,7 @@ jest.mock('@grafana/runtime', () => { const setup = (propOverrides?: object) => { const props: Props = { - panelId: 1, + panel: new PanelModel({ id: 1 }), dashboard: new DashboardModel({ panels: [{ id: 1 }] }), }; diff --git a/public/app/features/alerting/TestRuleResult.tsx b/public/app/features/alerting/TestRuleResult.tsx index db8390f0c6f..784331c6cda 100644 --- a/public/app/features/alerting/TestRuleResult.tsx +++ b/public/app/features/alerting/TestRuleResult.tsx @@ -3,13 +3,13 @@ import { LoadingPlaceholder, JSONFormatter } from '@grafana/ui'; import appEvents from 'app/core/app_events'; import { CopyToClipboard } from 'app/core/components/CopyToClipboard/CopyToClipboard'; -import { DashboardModel } from '../dashboard/state/DashboardModel'; +import { DashboardModel, PanelModel } from '../dashboard/state'; import { getBackendSrv } from '@grafana/runtime'; import { AppEvents } from '@grafana/data'; export interface Props { - panelId: number; dashboard: DashboardModel; + panel: PanelModel; } interface State { @@ -33,8 +33,17 @@ export class TestRuleResult extends PureComponent { } async testRule() { - const { panelId, dashboard } = this.props; - const payload = { dashboard: dashboard.getSaveModelClone(), panelId }; + const { dashboard, panel } = this.props; + + // dashboard save model + const model = dashboard.getSaveModelClone(); + + // now replace panel to get current edits + model.panels = model.panels.map(dashPanel => { + return dashPanel.id === panel.editSourceId ? panel.getSaveModel() : dashPanel; + }); + + const payload = { dashboard: model, panelId: panel.id }; this.setState({ isLoading: true }); const testRuleResponse = await getBackendSrv().post(`/api/alerts/test`, payload);