Merge pull request #14707 from grafana/14388/alert-tab-ux-update

Alert tab ux update
pull/14737/head
Torkel Ödegaard 7 years ago committed by GitHub
commit 2de57f095c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      public/app/core/components/EmptyListCTA/EmptyListCTA.tsx
  2. 8
      public/app/features/alerting/AlertTabCtrl.ts
  3. 341
      public/app/features/alerting/partials/alert_tab.html
  4. 91
      public/app/features/dashboard/dashgrid/AlertTab.tsx
  5. 22
      public/app/features/dashboard/dashgrid/EditorTabBody.tsx
  6. 2
      public/app/features/dashboard/dashgrid/PanelEditor.tsx
  7. 16
      public/app/features/dashboard/dashgrid/QueriesTab.tsx
  8. 110
      public/app/features/dashboard/dashgrid/StateHistory.tsx
  9. 6
      public/app/features/dashboard/dashgrid/VisualizationTab.tsx
  10. 1
      public/sass/pages/_alerting.scss

@ -24,12 +24,14 @@ class EmptyListCTA extends Component<Props, any> {
<i className={buttonIcon} /> <i className={buttonIcon} />
{buttonTitle} {buttonTitle}
</a> </a>
<div className="empty-list-cta__pro-tip"> {proTip && (
<i className="fa fa-rocket" /> ProTip: {proTip} <div className="empty-list-cta__pro-tip">
<a className="text-link empty-list-cta__pro-tip-link" href={proTipLink} target={proTipTarget}> <i className="fa fa-rocket" /> ProTip: {proTip}
{proTipLinkTitle} <a className="text-link empty-list-cta__pro-tip-link" href={proTipLink} target={proTipTarget}>
</a> {proTipLinkTitle}
</div> </a>
</div>
)}
</div> </div>
); );
} }

@ -45,6 +45,7 @@ export class AlertTabCtrl {
this.noDataModes = alertDef.noDataModes; this.noDataModes = alertDef.noDataModes;
this.executionErrorModes = alertDef.executionErrorModes; this.executionErrorModes = alertDef.executionErrorModes;
this.appSubUrl = config.appSubUrl; this.appSubUrl = config.appSubUrl;
this.panelCtrl._enableAlert = this.enable;
} }
$onInit() { $onInit() {
@ -114,7 +115,7 @@ export class AlertTabCtrl {
} }
getNotifications() { getNotifications() {
return Promise.resolve( return this.$q.when(
this.notifications.map(item => { this.notifications.map(item => {
return this.uiSegmentSrv.newSegment(item.name); return this.uiSegmentSrv.newSegment(item.name);
}) })
@ -147,6 +148,7 @@ export class AlertTabCtrl {
// reset plus button // reset plus button
this.addNotificationSegment.value = this.uiSegmentSrv.newPlusButton().value; this.addNotificationSegment.value = this.uiSegmentSrv.newPlusButton().value;
this.addNotificationSegment.html = this.uiSegmentSrv.newPlusButton().html; this.addNotificationSegment.html = this.uiSegmentSrv.newPlusButton().html;
this.addNotificationSegment.fake = true;
} }
removeNotification(index) { removeNotification(index) {
@ -353,11 +355,11 @@ export class AlertTabCtrl {
}); });
} }
enable() { enable = () => {
this.panel.alert = {}; this.panel.alert = {};
this.initModel(); this.initModel();
this.panel.alert.for = '5m'; //default value for new alerts. for existing alerts we use 0m to avoid breaking changes this.panel.alert.for = '5m'; //default value for new alerts. for existing alerts we use 0m to avoid breaking changes
} };
evaluatorParamsChanged() { evaluatorParamsChanged() {
ThresholdMapper.alertToGraphThresholds(this.panel); ThresholdMapper.alertToGraphThresholds(this.panel);

@ -1,191 +1,168 @@
<div class="panel-option-section__body" ng-if="ctrl.alert"> <div ng-if="ctrl.panel.alert">
<div class="edit-tab-with-sidemenu"> <div class="alert alert-error m-b-2" ng-show="ctrl.error">
<aside class="edit-sidemenu-aside"> <i class="fa fa-warning"></i> {{ctrl.error}}
<ul class="edit-sidemenu"> </div>
<li ng-class="{active: ctrl.subTabIndex === 0}"> <div class="panel-option-section">
<a ng-click="ctrl.changeTabIndex(0)">Alert Config</a> <div class="panel-option-section__body">
</li> <div class="gf-form-group">
<li ng-class="{active: ctrl.subTabIndex === 1}"> <h4 class="section-heading">Rule</h4>
<a ng-click="ctrl.changeTabIndex(1)"> <div class="gf-form-inline">
Notifications <span class="muted">({{ctrl.alertNotifications.length}})</span> <div class="gf-form">
</a> <span class="gf-form-label width-6">Name</span>
</li> <input type="text" class="gf-form-input width-20" ng-model="ctrl.alert.name">
<li ng-class="{active: ctrl.subTabIndex === 2}"> </div>
<a ng-click="ctrl.changeTabIndex(2)">State history</a> <div class="gf-form">
</li> <span class="gf-form-label width-9">Evaluate every</span>
<li> <input class="gf-form-input max-width-6" type="text" ng-model="ctrl.alert.frequency">
<a ng-click="ctrl.delete()">Delete</a> </div>
</li> <div class="gf-form max-width-11">
</ul> <label class="gf-form-label width-5">For</label>
</aside> <input type="text" class="gf-form-input max-width-6" ng-model="ctrl.alert.for"
spellcheck='false' placeholder="5m">
<info-popover mode="right-absolute">
If an alert rule has a configured For and the query violates the configured
threshold it
will first go from OK to Pending.
Going from OK to Pending Grafana will not send any notifications. Once the alert
rule
has
been firing for more than For duration, it will change to Alerting and send alert
notifications.
</info-popover>
</div>
</div>
</div>
<div class="edit-tab-content"> <div class="gf-form-group">
<div ng-if="ctrl.subTabIndex === 0"> <h4 class="section-heading">Conditions</h4>
<div class="alert alert-error m-b-2" ng-show="ctrl.error"> <div class="gf-form-inline" ng-repeat="conditionModel in ctrl.conditionModels">
<i class="fa fa-warning"></i> {{ctrl.error}} <div class="gf-form">
</div> <metric-segment-model css-class="query-keyword width-5" ng-if="$index"
property="conditionModel.operator.type" options="ctrl.evalOperators"
custom="false"></metric-segment-model>
<span class="gf-form-label query-keyword width-5" ng-if="$index===0">WHEN</span>
</div>
<div class="gf-form">
<query-part-editor class="gf-form-label query-part width-9"
part="conditionModel.reducerPart"
handle-event="ctrl.handleReducerPartEvent(conditionModel, $event)">
</query-part-editor>
<span class="gf-form-label query-keyword">OF</span>
</div>
<div class="gf-form">
<query-part-editor class="gf-form-label query-part" part="conditionModel.queryPart"
handle-event="ctrl.handleQueryPartEvent(conditionModel, $event)">
</query-part-editor>
</div>
<div class="gf-form">
<metric-segment-model property="conditionModel.evaluator.type" options="ctrl.evalFunctions"
custom="false" css-class="query-keyword"
on-change="ctrl.evaluatorTypeChanged(conditionModel.evaluator)"></metric-segment-model>
<input class="gf-form-input max-width-9" type="number" step="any"
ng-hide="conditionModel.evaluator.params.length === 0"
ng-model="conditionModel.evaluator.params[0]"
ng-change="ctrl.evaluatorParamsChanged()" />
<label class="gf-form-label query-keyword"
ng-show="conditionModel.evaluator.params.length === 2">TO</label>
<input class="gf-form-input max-width-9" type="number" step="any"
ng-if="conditionModel.evaluator.params.length === 2"
ng-model="conditionModel.evaluator.params[1]"
ng-change="ctrl.evaluatorParamsChanged()" />
</div>
<div class="gf-form">
<label class="gf-form-label">
<a class="pointer" tabindex="1" ng-click="ctrl.removeCondition($index)">
<i class="fa fa-trash"></i>
</a>
</label>
</div>
</div>
<div class="gf-form-group"> <div class="gf-form">
<h5 class="section-heading">Alert Config</h5> <label class="gf-form-label dropdown">
<div class="gf-form"> <a class="pointer dropdown-toggle" data-toggle="dropdown">
<span class="gf-form-label width-6">Name</span> <i class="fa fa-plus"></i>
<input type="text" class="gf-form-input width-20" ng-model="ctrl.alert.name"> </a>
</div> <ul class="dropdown-menu" role="menu">
<div class="gf-form-inline"> <li ng-repeat="ct in ctrl.conditionTypes" role="menuitem">
<div class="gf-form"> <a ng-click="ctrl.addCondition(ct.value);">{{ct.text}}</a>
<span class="gf-form-label width-9">Evaluate every</span> </li>
<input class="gf-form-input max-width-6" type="text" ng-model="ctrl.alert.frequency"> </ul>
</div> </label>
<div class="gf-form max-width-11"> </div>
<label class="gf-form-label width-5">For</label> </div>
<input type="text" class="gf-form-input max-width-6" ng-model="ctrl.alert.for" spellcheck='false' placeholder="5m">
<info-popover mode="right-absolute">
If an alert rule has a configured For and the query violates the configured threshold it will first go from OK to Pending.
Going from OK to Pending Grafana will not send any notifications. Once the alert rule has been firing for more than For duration, it will change to Alerting and send alert notifications.
</info-popover>
</div>
</div>
</div>
<div class="gf-form-group"> <div class="gf-form-group">
<h5 class="section-heading">Conditions</h5> <h4 class="section-heading">No Data & Error Handling</h4>
<div class="gf-form-inline" ng-repeat="conditionModel in ctrl.conditionModels"> <div class="gf-form-inline">
<div class="gf-form"> <div class="gf-form">
<metric-segment-model css-class="query-keyword width-5" ng-if="$index" property="conditionModel.operator.type" options="ctrl.evalOperators" custom="false"></metric-segment-model> <span class="gf-form-label width-15">If no data or all values are null</span>
<span class="gf-form-label query-keyword width-5" ng-if="$index===0">WHEN</span> </div>
</div> <div class="gf-form">
<div class="gf-form"> <span class="gf-form-label query-keyword">SET STATE TO</span>
<query-part-editor class="gf-form-label query-part width-9" part="conditionModel.reducerPart" handle-event="ctrl.handleReducerPartEvent(conditionModel, $event)"> <div class="gf-form-select-wrapper">
</query-part-editor> <select class="gf-form-input" ng-model="ctrl.alert.noDataState"
<span class="gf-form-label query-keyword">OF</span> ng-options="f.value as f.text for f in ctrl.noDataModes">
</div> </select>
<div class="gf-form"> </div>
<query-part-editor class="gf-form-label query-part" part="conditionModel.queryPart" handle-event="ctrl.handleQueryPartEvent(conditionModel, $event)"> </div>
</query-part-editor> </div>
</div>
<div class="gf-form">
<metric-segment-model property="conditionModel.evaluator.type" options="ctrl.evalFunctions" custom="false" css-class="query-keyword" on-change="ctrl.evaluatorTypeChanged(conditionModel.evaluator)"></metric-segment-model>
<input class="gf-form-input max-width-9" type="number" step="any" ng-hide="conditionModel.evaluator.params.length === 0" ng-model="conditionModel.evaluator.params[0]" ng-change="ctrl.evaluatorParamsChanged()">
<label class="gf-form-label query-keyword" ng-show="conditionModel.evaluator.params.length === 2">TO</label>
<input class="gf-form-input max-width-9" type="number" step="any" ng-if="conditionModel.evaluator.params.length === 2" ng-model="conditionModel.evaluator.params[1]" ng-change="ctrl.evaluatorParamsChanged()">
</div>
<div class="gf-form">
<label class="gf-form-label">
<a class="pointer" tabindex="1" ng-click="ctrl.removeCondition($index)">
<i class="fa fa-trash"></i>
</a>
</label>
</div>
</div>
<div class="gf-form"> <div class="gf-form-inline">
<label class="gf-form-label dropdown"> <div class="gf-form">
<a class="pointer dropdown-toggle" data-toggle="dropdown"> <span class="gf-form-label width-15">If execution error or timeout</span>
<i class="fa fa-plus"></i> </div>
</a> <div class="gf-form">
<ul class="dropdown-menu" role="menu"> <span class="gf-form-label query-keyword">SET STATE TO</span>
<li ng-repeat="ct in ctrl.conditionTypes" role="menuitem"> <div class="gf-form-select-wrapper">
<a ng-click="ctrl.addCondition(ct.value);">{{ct.text}}</a> <select class="gf-form-input" ng-model="ctrl.alert.executionErrorState"
</li> ng-options="f.value as f.text for f in ctrl.executionErrorModes">
</ul> </select>
</label> </div>
</div> </div>
</div> </div>
<div class="gf-form-group"> <div class="gf-form-button-row">
<div class="gf-form"> <button class="btn btn-inverse" ng-click="ctrl.test()">
<span class="gf-form-label width-18">If no data or all values are null</span> Test Rule
<span class="gf-form-label query-keyword">SET STATE TO</span> </button>
<div class="gf-form-select-wrapper"> </div>
<select class="gf-form-input" ng-model="ctrl.alert.noDataState" ng-options="f.value as f.text for f in ctrl.noDataModes"> </div>
</select>
</div>
</div>
<div class="gf-form"> <div class="gf-form-group" ng-if="ctrl.testing">
<span class="gf-form-label width-18">If execution error or timeout</span> Evaluating rule <i class="fa fa-spinner fa-spin"></i>
<span class="gf-form-label query-keyword">SET STATE TO</span> </div>
<div class="gf-form-select-wrapper">
<select class="gf-form-input" ng-model="ctrl.alert.executionErrorState" ng-options="f.value as f.text for f in ctrl.executionErrorModes">
</select>
</div>
</div>
<div class="gf-form-button-row"> <div class="gf-form-group" ng-if="ctrl.testResult">
<button class="btn btn-inverse" ng-click="ctrl.test()"> <json-tree root-name="result" object="ctrl.testResult" start-expanded="true"></json-tree>
Test Rule </div>
</button> </div>
</div> </div>
</div>
<div class="gf-form-group" ng-if="ctrl.testing"> <div class="panel-option-section">
Evaluating rule <i class="fa fa-spinner fa-spin"></i> <div class="panel-option-section__header">Notifications</div>
</div> <div class="panel-option-section__body">
<div class="gf-form-inline">
<div class="gf-form-group" ng-if="ctrl.testResult"> <div class="gf-form">
<json-tree root-name="result" object="ctrl.testResult" start-expanded="true"></json-tree> <span class="gf-form-label width-8">Send to</span>
</div> </div>
</div> <div class="gf-form" ng-repeat="nc in ctrl.alertNotifications">
<span class="gf-form-label" ng-style="{'background-color': nc.bgColor }">
<div class="gf-form-group" ng-if="ctrl.subTabIndex === 1"> <i class="{{nc.iconClass}}"></i>&nbsp;{{nc.name}}&nbsp;
<h5 class="section-heading">Notifications</h5> <i class="fa fa-remove pointer muted" ng-click="ctrl.removeNotification($index)" ng-if="nc.isDefault === false"></i>
<div class="gf-form-inline"> </span>
<div class="gf-form max-width-30"> </div>
<span class="gf-form-label width-8">Send to</span> <div class="gf-form">
<span class="gf-form-label" ng-repeat="nc in ctrl.alertNotifications" ng-style="{'background-color': nc.bgColor }"> <metric-segment segment="ctrl.addNotificationSegment"
<i class="{{nc.iconClass}}"></i>&nbsp;{{nc.name}}&nbsp; get-options="ctrl.getNotifications()"
<i class="fa fa-remove pointer muted" ng-click="ctrl.removeNotification($index)" ng-if="nc.isDefault === false"></i> on-change="ctrl.notificationAdded()"></metric-segment>
</span> </div>
<metric-segment segment="ctrl.addNotificationSegment" get-options="ctrl.getNotifications()" on-change="ctrl.notificationAdded()"></metric-segment> </div>
</div> <div class="gf-form gf-form--v-stretch">
</div> <span class="gf-form-label width-8">Message</span>
<div class="gf-form gf-form--v-stretch"> <textarea class="gf-form-input" rows="10" ng-model="ctrl.alert.message"
<span class="gf-form-label width-8">Message</span> placeholder="Notification message details..."></textarea>
<textarea class="gf-form-input" rows="10" ng-model="ctrl.alert.message" placeholder="Notification message details..."></textarea> </div>
</div> </div>
</div> </div>
<div class="gf-form-group" style="max-width: 720px;" ng-if="ctrl.subTabIndex === 2">
<button class="btn btn-mini btn-danger pull-right" ng-click="ctrl.clearHistory()"><i class="fa fa-trash"></i>&nbsp;Clear history</button>
<h5 class="section-heading" style="whitespace: nowrap">
State history <span class="muted small">(last 50 state changes)</span>
</h5>
<div ng-show="ctrl.alertHistory.length === 0">
<br>
<i>No state changes recorded</i>
</div>
<ol class="alert-rule-list" >
<li class="alert-rule-item" ng-repeat="al in ctrl.alertHistory">
<div class="alert-rule-item__icon {{al.stateModel.stateClass}}">
<i class="{{al.stateModel.iconClass}}"></i>
</div>
<div class="alert-rule-item__body">
<div class="alert-rule-item__header">
<div class="alert-rule-item__text">
<span class="{{al.stateModel.stateClass}}">{{al.stateModel.text}}</span>
</div>
</div>
<span class="alert-list-info">{{al.info}}</span>
</div>
<div class="alert-rule-item__time">
<span>{{al.time}}</span>
</div>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="gf-form-group p-t-4 p-b-4" ng-if="!ctrl.alert">
<div class="empty-list-cta">
<div class="empty-list-cta__title">Panel has no alert rule defined</div>
<button class="empty-list-cta__button btn btn-xlarge btn-success" ng-click="ctrl.enable()">
<i class="icon-gf icon-gf-alert"></i>
Create Alert
</button>
</div>
</div>
</div> </div>

@ -1,20 +1,30 @@
// Libraries
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader'; // Services & Utils
import { EditorTabBody } from './EditorTabBody'; import { AngularComponent, getAngularLoader } from 'app/core/services/AngularLoader';
import appEvents from 'app/core/app_events';
// Components
import { EditorTabBody, EditorToolbarView } from './EditorTabBody';
import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA';
import StateHistory from './StateHistory';
import 'app/features/alerting/AlertTabCtrl'; import 'app/features/alerting/AlertTabCtrl';
// Types
import { DashboardModel } from '../dashboard_model';
import { PanelModel } from '../panel_model';
interface Props { interface Props {
angularPanel?: AngularComponent; angularPanel?: AngularComponent;
dashboard: DashboardModel;
panel: PanelModel;
} }
export class AlertTab extends PureComponent<Props> { export class AlertTab extends PureComponent<Props> {
element: any; element: any;
component: AngularComponent; component: AngularComponent;
panelCtrl: any;
constructor(props) {
super(props);
}
componentDidMount() { componentDidMount() {
if (this.shouldLoadAlertTab()) { if (this.shouldLoadAlertTab()) {
@ -29,7 +39,7 @@ export class AlertTab extends PureComponent<Props> {
} }
shouldLoadAlertTab() { shouldLoadAlertTab() {
return this.props.angularPanel && this.element; return this.props.angularPanel && this.element && !this.component;
} }
componentWillUnmount() { componentWillUnmount() {
@ -51,21 +61,80 @@ export class AlertTab extends PureComponent<Props> {
return; return;
} }
const panelCtrl = scope.$$childHead.ctrl; this.panelCtrl = scope.$$childHead.ctrl;
const loader = getAngularLoader(); const loader = getAngularLoader();
const template = '<alert-tab />'; const template = '<alert-tab />';
const scopeProps = { const scopeProps = {
ctrl: panelCtrl, ctrl: this.panelCtrl,
}; };
this.component = loader.load(this.element, scopeProps, template); this.component = loader.load(this.element, scopeProps, template);
} }
stateHistory = (): EditorToolbarView => {
return {
title: 'State history',
render: () => {
return (
<StateHistory
dashboard={this.props.dashboard}
panelId={this.props.panel.id}
onRefresh={this.panelCtrl.refresh}
/>
);
},
};
};
deleteAlert = (): EditorToolbarView => {
const { panel } = this.props;
return {
title: 'Delete',
btnType: 'danger',
onClick: () => {
appEvents.emit('confirm-modal', {
title: 'Delete Alert',
text: 'Are you sure you want to delete this alert rule?',
text2: 'You need to save dashboard for the delete to take effect',
icon: 'fa-trash',
yesText: 'Delete',
onConfirm: () => {
delete panel.alert;
panel.thresholds = [];
this.panelCtrl.alertState = null;
this.panelCtrl.render();
this.forceUpdate();
},
});
},
};
};
onAddAlert = () => {
this.panelCtrl._enableAlert();
this.component.digest();
this.forceUpdate();
};
render() { render() {
const { alert } = this.props.panel;
const toolbarItems = alert ? [this.stateHistory(), this.deleteAlert()] : [];
const model = {
title: 'Panel has no alert rule defined',
icon: 'icon-gf icon-gf-alert',
onClick: this.onAddAlert,
buttonTitle: 'Create Alert',
};
return ( return (
<EditorTabBody heading="Alert" toolbarItems={[]}> <EditorTabBody heading="Alert" toolbarItems={toolbarItems}>
<div ref={element => (this.element = element)} /> <>
<div ref={element => (this.element = element)} />
{!alert && <EmptyListCTA model={model} />}
</>
</EditorTabBody> </EditorTabBody>
); );
} }

@ -10,21 +10,22 @@ interface Props {
children: JSX.Element; children: JSX.Element;
heading: string; heading: string;
renderToolbar?: () => JSX.Element; renderToolbar?: () => JSX.Element;
toolbarItems?: EditorToolBarView[]; toolbarItems?: EditorToolbarView[];
} }
export interface EditorToolBarView { export interface EditorToolbarView {
title?: string; title?: string;
heading?: string; heading?: string;
imgSrc?: string;
icon?: string; icon?: string;
disabled?: boolean; disabled?: boolean;
onClick?: () => void; onClick?: () => void;
render: (closeFunction?: any) => JSX.Element | JSX.Element[]; render?: () => JSX.Element;
action?: () => void;
btnType?: 'danger';
} }
interface State { interface State {
openView?: EditorToolBarView; openView?: EditorToolbarView;
isOpen: boolean; isOpen: boolean;
fadeIn: boolean; fadeIn: boolean;
} }
@ -48,7 +49,7 @@ export class EditorTabBody extends PureComponent<Props, State> {
this.setState({ fadeIn: true }); this.setState({ fadeIn: true });
} }
onToggleToolBarView = (item: EditorToolBarView) => { onToggleToolBarView = (item: EditorToolbarView) => {
this.setState({ this.setState({
openView: item, openView: item,
isOpen: !this.state.isOpen, isOpen: !this.state.isOpen,
@ -74,12 +75,15 @@ export class EditorTabBody extends PureComponent<Props, State> {
return state; return state;
} }
renderButton(view: EditorToolBarView) { renderButton(view: EditorToolbarView) {
const onClick = () => { const onClick = () => {
if (view.onClick) { if (view.onClick) {
view.onClick(); view.onClick();
} }
this.onToggleToolBarView(view);
if (view.render) {
this.onToggleToolBarView(view);
}
}; };
return ( return (
@ -91,7 +95,7 @@ export class EditorTabBody extends PureComponent<Props, State> {
); );
} }
renderOpenView(view: EditorToolBarView) { renderOpenView(view: EditorToolbarView) {
return ( return (
<PanelOptionSection title={view.title || view.heading} onClose={this.onCloseOpenView}> <PanelOptionSection title={view.title || view.heading} onClose={this.onCloseOpenView}>
{view.render()} {view.render()}

@ -54,7 +54,7 @@ export class PanelEditor extends PureComponent<PanelEditorProps> {
case 'queries': case 'queries':
return <QueriesTab panel={panel} dashboard={dashboard} />; return <QueriesTab panel={panel} dashboard={dashboard} />;
case 'alert': case 'alert':
return <AlertTab angularPanel={angularPanel} />; return <AlertTab angularPanel={angularPanel} dashboard={dashboard} panel={panel} />;
case 'visualization': case 'visualization':
return ( return (
<VisualizationTab <VisualizationTab

@ -1,10 +1,10 @@
// Libraries // Libraries
import React, { SFC, PureComponent } from 'react'; import React, { PureComponent, SFC } from 'react';
import _ from 'lodash'; import _ from 'lodash';
// Components // Components
import './../../panel/metrics_tab'; import 'app/features/panel/metrics_tab';
import { EditorTabBody } 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';
@ -13,14 +13,14 @@ import { PanelOptionSection } from './PanelOptionSection';
// Services // Services
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
import { getBackendSrv, BackendSrv } from 'app/core/services/backend_srv'; import { BackendSrv, getBackendSrv } from 'app/core/services/backend_srv';
import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader'; import { AngularComponent, getAngularLoader } from 'app/core/services/AngularLoader';
import config from 'app/core/config'; import config from 'app/core/config';
// Types // Types
import { PanelModel } from '../panel_model'; import { PanelModel } from '../panel_model';
import { DashboardModel } from '../dashboard_model'; import { DashboardModel } from '../dashboard_model';
import { DataSourceSelectItem, DataQuery } from 'app/types'; import { DataQuery, DataSourceSelectItem } from 'app/types';
import { PluginHelp } from 'app/core/components/PluginHelp/PluginHelp'; import { PluginHelp } from 'app/core/components/PluginHelp/PluginHelp';
interface Props { interface Props {
@ -204,12 +204,12 @@ export class QueriesTab extends PureComponent<Props, State> {
const { panel } = this.props; const { panel } = this.props;
const { currentDS, isAddingMixed } = this.state; const { currentDS, isAddingMixed } = this.state;
const queryInspector = { const queryInspector: EditorToolbarView = {
title: 'Query Inspector', title: 'Query Inspector',
render: this.renderQueryInspector, render: this.renderQueryInspector,
}; };
const dsHelp = { const dsHelp: EditorToolbarView = {
heading: 'Help', heading: 'Help',
icon: 'fa fa-question', icon: 'fa fa-question',
render: this.renderHelp, render: this.renderHelp,

@ -0,0 +1,110 @@
import React, { PureComponent } from 'react';
import alertDef from '../../alerting/state/alertDef';
import { getBackendSrv } from 'app/core/services/backend_srv';
import { DashboardModel } from '../dashboard_model';
import appEvents from '../../../core/app_events';
interface Props {
dashboard: DashboardModel;
panelId: number;
onRefresh: () => void;
}
interface State {
stateHistoryItems: any[];
}
class StateHistory extends PureComponent<Props, State> {
state = {
stateHistoryItems: [],
};
componentDidMount(): void {
const { dashboard, panelId } = this.props;
getBackendSrv()
.get(`/api/annotations?dashboardId=${dashboard.id}&panelId=${panelId}&limit=50&type=alert`)
.then(res => {
const items = res.map(item => {
return {
stateModel: alertDef.getStateDisplayModel(item.newState),
time: dashboard.formatDate(item.time, 'MMM D, YYYY HH:mm:ss'),
info: alertDef.getAlertAnnotationInfo(item),
};
});
this.setState({
stateHistoryItems: items,
});
});
}
clearHistory = () => {
const { dashboard, onRefresh, panelId } = this.props;
appEvents.emit('confirm-modal', {
title: 'Delete Alert History',
text: 'Are you sure you want to remove all history & annotations for this alert?',
icon: 'fa-trash',
yesText: 'Yes',
onConfirm: () => {
getBackendSrv()
.post('/api/annotations/mass-delete', {
dashboardId: dashboard.id,
panelId: panelId,
})
.then(() => {
onRefresh();
});
this.setState({
stateHistoryItems: [],
});
},
});
};
render() {
const { stateHistoryItems } = this.state;
return (
<div>
{stateHistoryItems.length > 0 && (
<div className="p-b-1">
<span className="muted">Last 50 state changes</span>
<button className="btn btn-mini btn-danger pull-right" onClick={this.clearHistory}>
<i className="fa fa-trash" /> {` Clear history`}
</button>
</div>
)}
<ol className="alert-rule-list">
{stateHistoryItems.length > 0 ? (
stateHistoryItems.map((item, index) => {
return (
<li className="alert-rule-item" key={`${item.time}-${index}`}>
<div className={`alert-rule-item__icon ${item.stateModel.stateClass}`}>
<i className={item.stateModel.iconClass} />
</div>
<div className="alert-rule-item__body">
<div className="alert-rule-item__header">
<p className="alert-rule-item__name">{item.alertName}</p>
<div className="alert-rule-item__text">
<span className={`${item.stateModel.stateClass}`}>{item.stateModel.text}</span>
</div>
</div>
{item.info}
</div>
<div className="alert-rule-item__time">{item.time}</div>
</li>
);
})
) : (
<i>No state changes recorded</i>
)}
</ol>
</div>
);
}
}
export default StateHistory;

@ -2,10 +2,10 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
// Utils & Services // Utils & Services
import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader'; import { AngularComponent, getAngularLoader } from 'app/core/services/AngularLoader';
// Components // Components
import { EditorTabBody } from './EditorTabBody'; import { EditorTabBody, EditorToolbarView } from './EditorTabBody';
import { VizTypePicker } from './VizTypePicker'; import { VizTypePicker } from './VizTypePicker';
import { PluginHelp } from 'app/core/components/PluginHelp/PluginHelp'; import { PluginHelp } from 'app/core/components/PluginHelp/PluginHelp';
import { FadeIn } from 'app/core/components/Animations/FadeIn'; import { FadeIn } from 'app/core/components/Animations/FadeIn';
@ -206,7 +206,7 @@ export class VisualizationTab extends PureComponent<Props, State> {
const { plugin } = this.props; const { plugin } = this.props;
const { isVizPickerOpen, searchQuery } = this.state; const { isVizPickerOpen, searchQuery } = this.state;
const pluginHelp = { const pluginHelp: EditorToolbarView = {
heading: 'Help', heading: 'Help',
icon: 'fa fa-question', icon: 'fa fa-question',
render: this.renderHelp, render: this.renderHelp,

@ -107,6 +107,7 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
flex-grow: 1; flex-grow: 1;
justify-content: center;
overflow: hidden; overflow: hidden;
} }

Loading…
Cancel
Save