mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
NewPanelEditor: Fixed so that test alert rule works in new edit mode (#23179)
This commit is contained in:
parent
3cf82df8b3
commit
1633bacba9
@ -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 => ({
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
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', () => {
|
|||||||
|
|
||||||
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';
|
|||||||
|
|
||||||
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> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user