SilencedAlertsTableRow.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React, { FC, useState } from 'react';
  2. import { intervalToAbbreviatedDurationString } from '@grafana/data';
  3. import { AlertmanagerAlert } from 'app/plugins/datasource/alertmanager/types';
  4. import { AlertLabels } from '../AlertLabels';
  5. import { CollapseToggle } from '../CollapseToggle';
  6. import { AmAlertStateTag } from './AmAlertStateTag';
  7. interface Props {
  8. alert: AlertmanagerAlert;
  9. className?: string;
  10. }
  11. export const SilencedAlertsTableRow: FC<Props> = ({ alert, className }) => {
  12. const [isCollapsed, setIsCollapsed] = useState(true);
  13. const duration = intervalToAbbreviatedDurationString({
  14. start: new Date(alert.startsAt),
  15. end: new Date(alert.endsAt),
  16. });
  17. const alertName = Object.entries(alert.labels).reduce((name, [labelKey, labelValue]) => {
  18. if (labelKey === 'alertname' || labelKey === '__alert_rule_title__') {
  19. name = labelValue;
  20. }
  21. return name;
  22. }, '');
  23. return (
  24. <>
  25. <tr className={className}>
  26. <td>
  27. <CollapseToggle isCollapsed={isCollapsed} onToggle={(collapsed) => setIsCollapsed(collapsed)} />
  28. </td>
  29. <td>
  30. <AmAlertStateTag state={alert.status.state} />
  31. </td>
  32. <td>for {duration} seconds</td>
  33. <td>{alertName}</td>
  34. </tr>
  35. {!isCollapsed && (
  36. <tr className={className}>
  37. <td></td>
  38. <td colSpan={5}>
  39. <AlertLabels labels={alert.labels} />
  40. </td>
  41. </tr>
  42. )}
  43. </>
  44. );
  45. };