Commit 08ac2959 by Peter Holmberg

Moving to grafana ui, fix issue with TestRuleResult

parent 7e106b0f
import React, { SFC } from 'react';
interface LoadingPlaceholderProps {
text: string;
}
export const LoadingPlaceholder: SFC<LoadingPlaceholderProps> = ({ text }) => (
<div className="gf-form-group">
{text} <i className="fa fa-spinner fa-spin" />
</div>
);
......@@ -2,3 +2,4 @@ export { DeleteButton } from './DeleteButton/DeleteButton';
export { Tooltip } from './Tooltip/Tooltip';
export { Portal } from './Portal/Portal';
export { CustomScrollbar } from './CustomScrollbar/CustomScrollbar';
export { LoadingPlaceholder } from './LoadingPlaceholder/LoadingPlaceholder';
// Libraries
import React, { PureComponent, SFC } from 'react';
import React, { PureComponent } from 'react';
// Services & Utils
import { AngularComponent, getAngularLoader } from 'app/core/services/AngularLoader';
import appEvents from 'app/core/app_events';
// Components
import { LoadingPlaceholder } from '@grafana/ui';
import { EditorTabBody, EditorToolbarView } from '../dashboard/dashgrid/EditorTabBody';
import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA';
import StateHistory from './StateHistory';
......@@ -14,7 +15,7 @@ import 'app/features/alerting/AlertTabCtrl';
// Types
import { DashboardModel } from '../dashboard/dashboard_model';
import { PanelModel } from '../dashboard/panel_model';
import { TestRuleButton } from './TestRuleButton';
import { TestRuleResult } from './TestRuleResult';
interface Props {
angularPanel?: AngularComponent;
......@@ -22,16 +23,6 @@ interface Props {
panel: PanelModel;
}
interface LoadingPlaceholderProps {
text: string;
}
const LoadingPlaceholder: SFC<LoadingPlaceholderProps> = ({ text }) => (
<div className="gf-form-group">
{text} <i className="fa fa-spinner fa-spin" />
</div>
);
export class AlertTab extends PureComponent<Props> {
element: any;
component: AngularComponent;
......@@ -120,14 +111,14 @@ export class AlertTab extends PureComponent<Props> {
};
};
renderTestRuleButton = () => {
renderTestRuleResult = () => {
const { panel, dashboard } = this.props;
return <TestRuleButton panelId={panel.id} dashboard={dashboard} LoadingPlaceholder={LoadingPlaceholder} />;
return <TestRuleResult panelId={panel.id} dashboard={dashboard} LoadingPlaceholder={LoadingPlaceholder} />;
};
testRule = (): EditorToolbarView => ({
title: 'Test Rule',
render: () => this.renderTestRuleButton(),
render: () => this.renderTestRuleResult(),
});
onAddAlert = () => {
......
import React from 'react';
import { shallow } from 'enzyme';
import { DashboardModel } from '../dashboard/dashboard_model';
import { Props, TestRuleButton } from './TestRuleButton';
import { Props, TestRuleResult } from './TestRuleResult';
jest.mock('app/core/services/backend_srv', () => ({
getBackendSrv: () => ({
......@@ -18,9 +18,9 @@ const setup = (propOverrides?: object) => {
Object.assign(props, propOverrides);
const wrapper = shallow(<TestRuleButton {...props} />);
const wrapper = shallow(<TestRuleResult {...props} />);
return { wrapper, instance: wrapper.instance() as TestRuleButton };
return { wrapper, instance: wrapper.instance() as TestRuleResult };
};
describe('Render', () => {
......
......@@ -14,7 +14,7 @@ interface State {
testRuleResponse: {};
}
export class TestRuleButton extends PureComponent<Props, State> {
export class TestRuleResult extends PureComponent<Props, State> {
readonly state: State = {
isLoading: false,
testRuleResponse: {},
......@@ -27,8 +27,10 @@ export class TestRuleButton extends PureComponent<Props, State> {
async testRule() {
const { panelId, dashboard } = this.props;
const payload = { dashboard: dashboard.getSaveModelClone(), panelId };
this.setState({ isLoading: true });
const testRuleResponse = await getBackendSrv().post(`/api/alerts/test`, payload);
this.setState(prevState => ({ ...prevState, isLoading: false, testRuleResponse }));
this.setState({ isLoading: false, testRuleResponse });
}
render() {
......
// Libraries
import React, { PureComponent, SFC } from 'react';
import React, { PureComponent } from 'react';
import _ from 'lodash';
// Components
import 'app/features/panel/metrics_tab';
import { EditorTabBody, EditorToolbarView} from './EditorTabBody';
import { EditorTabBody, EditorToolbarView } from './EditorTabBody';
import { DataSourcePicker } from 'app/core/components/Select/DataSourcePicker';
import { QueryInspector } from './QueryInspector';
import { QueryOptions } from './QueryOptions';
import { AngularQueryComponentScope } from 'app/features/panel/metrics_tab';
import { PanelOptionSection } from './PanelOptionSection';
import { LoadingPlaceholder } from '@grafana/ui';
// Services
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
......@@ -36,12 +37,6 @@ interface State {
isAddingMixed: boolean;
}
interface LoadingPlaceholderProps {
text: string;
}
const LoadingPlaceholder: SFC<LoadingPlaceholderProps> = ({ text }) => <h2>{text}</h2>;
export class QueriesTab extends PureComponent<Props, State> {
element: HTMLElement;
component: AngularComponent;
......
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