2018-09-03 07:05:12 -05:00
|
|
|
import React, { PureComponent } from 'react';
|
2018-09-03 08:44:39 -05:00
|
|
|
import { connect } from 'react-redux';
|
2018-09-03 06:46:39 -05:00
|
|
|
import Highlighter from 'react-highlight-words';
|
|
|
|
import classNames from 'classnames/bind';
|
2018-09-03 08:44:39 -05:00
|
|
|
import { togglePauseAlertRule } from './state/actions';
|
2018-09-03 06:46:39 -05:00
|
|
|
import { AlertRule } from '../../types';
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
rule: AlertRule;
|
|
|
|
search: string;
|
2018-09-03 08:44:39 -05:00
|
|
|
togglePauseAlertRule: typeof togglePauseAlertRule;
|
2018-09-03 06:46:39 -05:00
|
|
|
}
|
|
|
|
|
2018-09-03 08:44:39 -05:00
|
|
|
class AlertRuleItem extends PureComponent<Props, any> {
|
|
|
|
togglePaused = () => {
|
|
|
|
const { rule } = this.props;
|
|
|
|
|
2018-09-04 08:00:04 -05:00
|
|
|
this.props.togglePauseAlertRule(rule.id, { paused: rule.state !== 'paused' });
|
2018-09-03 06:46:39 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
renderText(text: string) {
|
|
|
|
return (
|
|
|
|
<Highlighter
|
|
|
|
highlightClassName="highlight-search-match"
|
|
|
|
textToHighlight={text}
|
|
|
|
searchWords={[this.props.search]}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { rule } = this.props;
|
|
|
|
|
|
|
|
const stateClass = classNames({
|
|
|
|
fa: true,
|
|
|
|
'fa-play': rule.state === 'paused',
|
|
|
|
'fa-pause': rule.state !== 'paused',
|
|
|
|
});
|
|
|
|
|
|
|
|
const ruleUrl = `${rule.url}?panelId=${rule.panelId}&fullscreen=true&edit=true&tab=alert`;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li className="alert-rule-item">
|
|
|
|
<span className={`alert-rule-item__icon ${rule.stateClass}`}>
|
|
|
|
<i className={rule.stateIcon} />
|
|
|
|
</span>
|
|
|
|
<div className="alert-rule-item__body">
|
|
|
|
<div className="alert-rule-item__header">
|
|
|
|
<div className="alert-rule-item__name">
|
|
|
|
<a href={ruleUrl}>{this.renderText(rule.name)}</a>
|
|
|
|
</div>
|
|
|
|
<div className="alert-rule-item__text">
|
|
|
|
<span className={`${rule.stateClass}`}>{this.renderText(rule.stateText)}</span>
|
|
|
|
<span className="alert-rule-item__time"> for {rule.stateAge}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{rule.info && <div className="small muted alert-rule-item__info">{this.renderText(rule.info)}</div>}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="alert-rule-item__actions">
|
|
|
|
<button
|
|
|
|
className="btn btn-small btn-inverse alert-list__btn width-2"
|
|
|
|
title="Pausing an alert rule prevents it from executing"
|
2018-09-03 08:44:39 -05:00
|
|
|
onClick={this.togglePaused}
|
2018-09-03 06:46:39 -05:00
|
|
|
>
|
|
|
|
<i className={stateClass} />
|
|
|
|
</button>
|
|
|
|
<a className="btn btn-small btn-inverse alert-list__btn width-2" href={ruleUrl} title="Edit alert rule">
|
|
|
|
<i className="icon-gf icon-gf-settings" />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-09-03 08:44:39 -05:00
|
|
|
|
|
|
|
export default connect(null, {
|
|
|
|
togglePauseAlertRule,
|
|
|
|
})(AlertRuleItem);
|