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