QueryErrorAlert.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { DataQueryError, GrafanaTheme2 } from '@grafana/data';
  4. import { Icon, useStyles2 } from '@grafana/ui';
  5. export interface Props {
  6. error: DataQueryError;
  7. }
  8. export function QueryErrorAlert({ error }: Props) {
  9. const styles = useStyles2(getStyles);
  10. const message = error?.message ?? error?.data?.message ?? 'Query error';
  11. return (
  12. <div className={styles.wrapper}>
  13. <div className={styles.icon}>
  14. <Icon name="exclamation-triangle" />
  15. </div>
  16. <div className={styles.message}>{message}</div>
  17. </div>
  18. );
  19. }
  20. const getStyles = (theme: GrafanaTheme2) => ({
  21. wrapper: css({
  22. marginTop: theme.spacing(0.5),
  23. background: theme.colors.background.secondary,
  24. display: 'flex',
  25. }),
  26. icon: css({
  27. background: theme.colors.error.main,
  28. color: theme.colors.error.contrastText,
  29. padding: theme.spacing(1),
  30. }),
  31. message: css({
  32. fontSize: theme.typography.bodySmall.fontSize,
  33. fontFamily: theme.typography.fontFamilyMonospace,
  34. padding: theme.spacing(1),
  35. }),
  36. });