2019-01-09 04:34:22 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { JSONFormatter } from 'app/core/components/JSONFormatter/JSONFormatter';
|
2019-06-03 10:55:59 -05:00
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
2019-01-31 01:56:17 -06:00
|
|
|
import { DashboardModel } from '../dashboard/state/DashboardModel';
|
2019-01-10 16:15:37 -06:00
|
|
|
import { LoadingPlaceholder } from '@grafana/ui/src';
|
2019-01-09 04:34:22 -06:00
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
panelId: number;
|
|
|
|
dashboard: DashboardModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
isLoading: boolean;
|
|
|
|
testRuleResponse: {};
|
|
|
|
}
|
|
|
|
|
2019-01-10 15:47:09 -06:00
|
|
|
export class TestRuleResult extends PureComponent<Props, State> {
|
2019-01-09 06:20:50 -06:00
|
|
|
readonly state: State = {
|
|
|
|
isLoading: false,
|
|
|
|
testRuleResponse: {},
|
|
|
|
};
|
2019-01-09 04:34:22 -06:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.testRule();
|
|
|
|
}
|
|
|
|
|
|
|
|
async testRule() {
|
|
|
|
const { panelId, dashboard } = this.props;
|
|
|
|
const payload = { dashboard: dashboard.getSaveModelClone(), panelId };
|
2019-01-10 15:47:09 -06:00
|
|
|
|
|
|
|
this.setState({ isLoading: true });
|
2019-01-09 04:34:22 -06:00
|
|
|
const testRuleResponse = await getBackendSrv().post(`/api/alerts/test`, payload);
|
2019-01-10 15:47:09 -06:00
|
|
|
this.setState({ isLoading: false, testRuleResponse });
|
2019-01-09 04:34:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { testRuleResponse, isLoading } = this.state;
|
|
|
|
|
|
|
|
if (isLoading === true) {
|
|
|
|
return <LoadingPlaceholder text="Evaluating rule" />;
|
|
|
|
}
|
|
|
|
|
2019-01-09 06:20:50 -06:00
|
|
|
return <JSONFormatter json={testRuleResponse} />;
|
2019-01-09 04:34:22 -06:00
|
|
|
}
|
|
|
|
}
|