AlertGroup.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { css } from '@emotion/css';
  2. import React, { useState } from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { useStyles2 } from '@grafana/ui';
  5. import { AlertmanagerGroup, AlertState } from 'app/plugins/datasource/alertmanager/types';
  6. import { AlertLabels } from '../AlertLabels';
  7. import { CollapseToggle } from '../CollapseToggle';
  8. import { AlertGroupAlertsTable } from './AlertGroupAlertsTable';
  9. import { AlertGroupHeader } from './AlertGroupHeader';
  10. interface Props {
  11. group: AlertmanagerGroup;
  12. alertManagerSourceName: string;
  13. }
  14. export const AlertGroup = ({ alertManagerSourceName, group }: Props) => {
  15. const [isCollapsed, setIsCollapsed] = useState<boolean>(true);
  16. const styles = useStyles2(getStyles);
  17. return (
  18. <div className={styles.wrapper}>
  19. <div className={styles.header}>
  20. <div className={styles.group} data-testid="alert-group">
  21. <CollapseToggle
  22. isCollapsed={isCollapsed}
  23. onToggle={() => setIsCollapsed(!isCollapsed)}
  24. data-testid="alert-group-collapse-toggle"
  25. />
  26. {Object.keys(group.labels).length ? (
  27. <AlertLabels className={styles.headerLabels} labels={group.labels} />
  28. ) : (
  29. <span>No grouping</span>
  30. )}
  31. </div>
  32. <AlertGroupHeader group={group} />
  33. </div>
  34. {!isCollapsed && <AlertGroupAlertsTable alertManagerSourceName={alertManagerSourceName} alerts={group.alerts} />}
  35. </div>
  36. );
  37. };
  38. const getStyles = (theme: GrafanaTheme2) => ({
  39. wrapper: css`
  40. & + & {
  41. margin-top: ${theme.spacing(2)};
  42. }
  43. `,
  44. headerLabels: css`
  45. padding-bottom: 0 !important;
  46. margin-bottom: -${theme.spacing(0.5)};
  47. `,
  48. header: css`
  49. display: flex;
  50. flex-direction: row;
  51. flex-wrap: wrap;
  52. align-items: center;
  53. justify-content: space-between;
  54. padding: ${theme.spacing(1, 1, 1, 0)};
  55. background-color: ${theme.colors.background.secondary};
  56. width: 100%;
  57. `,
  58. group: css`
  59. display: flex;
  60. flex-direction: row;
  61. align-items: center;
  62. `,
  63. summary: css``,
  64. spanElement: css`
  65. margin-left: ${theme.spacing(0.5)};
  66. `,
  67. [AlertState.Active]: css`
  68. color: ${theme.colors.error.main};
  69. `,
  70. [AlertState.Suppressed]: css`
  71. color: ${theme.colors.primary.main};
  72. `,
  73. [AlertState.Unprocessed]: css`
  74. color: ${theme.colors.secondary.main};
  75. `,
  76. });