SilencedAlertsTable.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { css, cx } from '@emotion/css';
  2. import React, { FC } from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { useStyles2 } from '@grafana/ui';
  5. import { AlertmanagerAlert } from 'app/plugins/datasource/alertmanager/types';
  6. import { getAlertTableStyles } from '../../styles/table';
  7. import { SilencedAlertsTableRow } from './SilencedAlertsTableRow';
  8. interface Props {
  9. silencedAlerts: AlertmanagerAlert[];
  10. }
  11. const SilencedAlertsTable: FC<Props> = ({ silencedAlerts }) => {
  12. const tableStyles = useStyles2(getAlertTableStyles);
  13. const styles = useStyles2(getStyles);
  14. if (!!silencedAlerts.length) {
  15. return (
  16. <table className={cx(tableStyles.table, styles.tableMargin)}>
  17. <colgroup>
  18. <col className={tableStyles.colExpand} />
  19. <col className={styles.colState} />
  20. <col />
  21. <col className={styles.colName} />
  22. </colgroup>
  23. <thead>
  24. <tr>
  25. <th></th>
  26. <th>State</th>
  27. <th></th>
  28. <th>Alert name</th>
  29. </tr>
  30. </thead>
  31. <tbody>
  32. {silencedAlerts.map((alert, index) => {
  33. return (
  34. <SilencedAlertsTableRow
  35. key={alert.fingerprint}
  36. alert={alert}
  37. className={index % 2 === 0 ? tableStyles.evenRow : ''}
  38. />
  39. );
  40. })}
  41. </tbody>
  42. </table>
  43. );
  44. } else {
  45. return null;
  46. }
  47. };
  48. const getStyles = (theme: GrafanaTheme2) => ({
  49. tableMargin: css`
  50. margin-bottom: ${theme.spacing(1)};
  51. `,
  52. colState: css`
  53. width: 110px;
  54. `,
  55. colName: css`
  56. width: 65%;
  57. `,
  58. });
  59. export default SilencedAlertsTable;