grafana/public/app/features/alerting/AlertRuleItem.tsx

71 lines
2.2 KiB
TypeScript
Raw Normal View History

2018-09-03 07:05:12 -05:00
import React, { PureComponent } from 'react';
2019-05-13 02:38:19 -05:00
// @ts-ignore
2018-09-03 06:46:39 -05:00
import Highlighter from 'react-highlight-words';
2018-12-25 04:42:23 -06:00
import classNames from 'classnames';
2018-09-03 06:46:39 -05:00
import { AlertRule } from '../../types';
export interface Props {
rule: AlertRule;
search: string;
onTogglePause: () => void;
2018-09-03 06:46:39 -05:00
}
class AlertRuleItem extends PureComponent<Props> {
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, onTogglePause } = this.props;
2018-09-03 06:46:39 -05:00
2018-12-25 04:42:23 -06:00
const iconClassName = classNames({
2018-09-03 06:46:39 -05:00
fa: true,
'fa-play': rule.state === 'paused',
'fa-pause': rule.state !== 'paused',
});
const ruleUrl = `${rule.url}?panelId=${rule.panelId}&fullscreen&edit&tab=alert`;
2018-09-03 06:46:39 -05:00
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"
onClick={onTogglePause}
2018-09-03 06:46:39 -05:00
>
2018-12-25 04:42:23 -06:00
<i className={iconClassName} />
2018-09-03 06:46:39 -05:00
</button>
<a className="btn btn-small btn-inverse alert-list__btn width-2" href={ruleUrl} title="Edit alert rule">
<i className="gicon gicon-cog" />
2018-09-03 06:46:39 -05:00
</a>
</div>
</li>
);
}
}
export default AlertRuleItem;