Commit 1633bacb by Torkel Ödegaard Committed by GitHub

NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179)

parent 3cf82df8
...@@ -145,8 +145,8 @@ class UnConnectedAlertTab extends PureComponent<Props, State> { ...@@ -145,8 +145,8 @@ class UnConnectedAlertTab extends PureComponent<Props, State> {
}; };
renderTestRuleResult = () => { renderTestRuleResult = () => {
const { panel, dashboard } = this.props; const { dashboard, panel } = this.props;
return <TestRuleResult panelId={panel.id} dashboard={dashboard} />; return <TestRuleResult panel={panel} dashboard={dashboard} />;
}; };
testRule = (): EditorToolbarView => ({ testRule = (): EditorToolbarView => ({
......
import React from 'react'; import React from 'react';
import { TestRuleResult, Props } from './TestRuleResult'; import { TestRuleResult, Props } from './TestRuleResult';
import { DashboardModel } from '../dashboard/state'; import { DashboardModel, PanelModel } from '../dashboard/state';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
jest.mock('@grafana/runtime', () => { jest.mock('@grafana/runtime', () => {
...@@ -16,7 +16,7 @@ jest.mock('@grafana/runtime', () => { ...@@ -16,7 +16,7 @@ jest.mock('@grafana/runtime', () => {
const setup = (propOverrides?: object) => { const setup = (propOverrides?: object) => {
const props: Props = { const props: Props = {
panelId: 1, panel: new PanelModel({ id: 1 }),
dashboard: new DashboardModel({ panels: [{ id: 1 }] }), dashboard: new DashboardModel({ panels: [{ id: 1 }] }),
}; };
......
...@@ -3,13 +3,13 @@ import { LoadingPlaceholder, JSONFormatter } from '@grafana/ui'; ...@@ -3,13 +3,13 @@ import { LoadingPlaceholder, JSONFormatter } from '@grafana/ui';
import appEvents from 'app/core/app_events'; import appEvents from 'app/core/app_events';
import { CopyToClipboard } from 'app/core/components/CopyToClipboard/CopyToClipboard'; 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 { getBackendSrv } from '@grafana/runtime';
import { AppEvents } from '@grafana/data'; import { AppEvents } from '@grafana/data';
export interface Props { export interface Props {
panelId: number;
dashboard: DashboardModel; dashboard: DashboardModel;
panel: PanelModel;
} }
interface State { interface State {
...@@ -33,8 +33,17 @@ export class TestRuleResult extends PureComponent<Props, State> { ...@@ -33,8 +33,17 @@ export class TestRuleResult extends PureComponent<Props, State> {
} }
async testRule() { async testRule() {
const { panelId, dashboard } = this.props; const { dashboard, panel } = this.props;
const payload = { dashboard: dashboard.getSaveModelClone(), panelId };
// 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 }); this.setState({ isLoading: true });
const testRuleResponse = await getBackendSrv().post(`/api/alerts/test`, payload); const testRuleResponse = await getBackendSrv().post(`/api/alerts/test`, payload);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment