SilenceDetails.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { dateMath, GrafanaTheme2, intervalToAbbreviatedDurationString } from '@grafana/data';
  4. import { useStyles2 } from '@grafana/ui';
  5. import SilencedAlertsTable from './SilencedAlertsTable';
  6. import { SilenceTableItem } from './SilencesTable';
  7. interface Props {
  8. silence: SilenceTableItem;
  9. }
  10. export const SilenceDetails = ({ silence }: Props) => {
  11. const { startsAt, endsAt, comment, createdBy, silencedAlerts } = silence;
  12. const styles = useStyles2(getStyles);
  13. const dateDisplayFormat = 'YYYY-MM-DD HH:mm';
  14. const startsAtDate = dateMath.parse(startsAt);
  15. const endsAtDate = dateMath.parse(endsAt);
  16. const duration = intervalToAbbreviatedDurationString({ start: new Date(startsAt), end: new Date(endsAt) });
  17. return (
  18. <div className={styles.container}>
  19. <div className={styles.title}>Comment</div>
  20. <div>{comment}</div>
  21. <div className={styles.title}>Schedule</div>
  22. <div>{`${startsAtDate?.format(dateDisplayFormat)} - ${endsAtDate?.format(dateDisplayFormat)}`}</div>
  23. <div className={styles.title}>Duration</div>
  24. <div> {duration}</div>
  25. <div className={styles.title}>Created by</div>
  26. <div> {createdBy}</div>
  27. <div className={styles.title}>Affected alerts</div>
  28. <SilencedAlertsTable silencedAlerts={silencedAlerts} />
  29. </div>
  30. );
  31. };
  32. const getStyles = (theme: GrafanaTheme2) => ({
  33. container: css`
  34. display: grid;
  35. grid-template-columns: 1fr 9fr;
  36. grid-row-gap: 1rem;
  37. `,
  38. title: css`
  39. color: ${theme.colors.text.primary};
  40. `,
  41. row: css`
  42. margin: ${theme.spacing(1, 0)};
  43. `,
  44. });