ErrorContainer.tsx 790 B

12345678910111213141516171819202122232425
  1. import React, { FunctionComponent } from 'react';
  2. import { DataQueryError } from '@grafana/data';
  3. import { Alert } from '@grafana/ui';
  4. import { FadeIn } from 'app/core/components/Animations/FadeIn';
  5. export interface ErrorContainerProps {
  6. queryError?: DataQueryError;
  7. }
  8. export const ErrorContainer: FunctionComponent<ErrorContainerProps> = (props) => {
  9. const { queryError } = props;
  10. const showError = queryError ? true : false;
  11. const duration = showError ? 100 : 10;
  12. const title = queryError ? 'Query error' : 'Unknown error';
  13. const message = queryError?.message || queryError?.data?.message || null;
  14. return (
  15. <FadeIn in={showError} duration={duration}>
  16. <Alert severity="error" title={title} topSpacing={2}>
  17. {message}
  18. </Alert>
  19. </FadeIn>
  20. );
  21. };