AlertRuleItem.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React, { PureComponent } from 'react';
  2. // @ts-ignore
  3. import Highlighter from 'react-highlight-words';
  4. import classNames from 'classnames';
  5. import { AlertRule } from '../../types';
  6. export interface Props {
  7. rule: AlertRule;
  8. search: string;
  9. onTogglePause: () => void;
  10. }
  11. class AlertRuleItem extends PureComponent<Props> {
  12. renderText(text: string) {
  13. return (
  14. <Highlighter
  15. highlightClassName="highlight-search-match"
  16. textToHighlight={text}
  17. searchWords={[this.props.search]}
  18. />
  19. );
  20. }
  21. render() {
  22. const { rule, onTogglePause } = this.props;
  23. const iconClassName = classNames({
  24. fa: true,
  25. 'fa-play': rule.state === 'paused',
  26. 'fa-pause': rule.state !== 'paused',
  27. });
  28. const ruleUrl = `${rule.url}?panelId=${rule.panelId}&fullscreen&edit&tab=alert`;
  29. return (
  30. <li className="alert-rule-item">
  31. <span className={`alert-rule-item__icon ${rule.stateClass}`}>
  32. <i className={rule.stateIcon} />
  33. </span>
  34. <div className="alert-rule-item__body">
  35. <div className="alert-rule-item__header">
  36. <div className="alert-rule-item__name">
  37. <a href={ruleUrl}>{this.renderText(rule.name)}</a>
  38. </div>
  39. <div className="alert-rule-item__text">
  40. <span className={`${rule.stateClass}`}>{this.renderText(rule.stateText)}</span>
  41. <span className="alert-rule-item__time"> for {rule.stateAge}</span>
  42. </div>
  43. </div>
  44. {rule.info && <div className="small muted alert-rule-item__info">{this.renderText(rule.info)}</div>}
  45. </div>
  46. <div className="alert-rule-item__actions">
  47. <button
  48. className="btn btn-small btn-inverse alert-list__btn width-2"
  49. title="Pausing an alert rule prevents it from executing"
  50. onClick={onTogglePause}
  51. >
  52. <i className={iconClassName} />
  53. </button>
  54. <a className="btn btn-small btn-inverse alert-list__btn width-2" href={ruleUrl} title="Edit alert rule">
  55. <i className="gicon gicon-cog" />
  56. </a>
  57. </div>
  58. </li>
  59. );
  60. }
  61. }
  62. export default AlertRuleItem;