mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Moving to grafana ui, fix issue with TestRuleResult
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
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 { 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';
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
// 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';
|
|||||||
// 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 {
|
|||||||
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> {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
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 = () => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
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) => {
|
|||||||
|
|
||||||
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 {
|
|||||||
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> {
|
|||||||
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() {
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
// 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 {
|
|||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user