RuleHealth.tsx 921 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { css } from '@emotion/css';
  2. import React, { FC } from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { Icon, Tooltip, useStyles2 } from '@grafana/ui';
  5. import { Rule } from 'app/types/unified-alerting';
  6. interface Prom {
  7. rule: Rule;
  8. }
  9. export const RuleHealth: FC<Prom> = ({ rule }) => {
  10. const style = useStyles2(getStyle);
  11. if (rule.health === 'err' || rule.health === 'error') {
  12. return (
  13. <Tooltip theme="error" content={rule.lastError || 'No error message provided.'}>
  14. <div className={style.warn}>
  15. <Icon name="exclamation-triangle" />
  16. <span>error</span>
  17. </div>
  18. </Tooltip>
  19. );
  20. }
  21. return <>{rule.health}</>;
  22. };
  23. const getStyle = (theme: GrafanaTheme2) => ({
  24. warn: css`
  25. display: inline-flex;
  26. flex-direction: row;
  27. color: ${theme.colors.warning.text};
  28. & > * + * {
  29. margin-left: ${theme.spacing(1)};
  30. }
  31. `,
  32. });