2019-05-10 14:00:39 +02:00
|
|
|
import React, { FunctionComponent } from 'react';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2019-10-31 10:48:05 +01:00
|
|
|
import { DataQueryError } from '@grafana/data';
|
2022-04-14 12:57:56 +02:00
|
|
|
import { Alert } from '@grafana/ui';
|
2019-05-10 14:00:39 +02:00
|
|
|
import { FadeIn } from 'app/core/components/Animations/FadeIn';
|
|
|
|
|
|
2020-03-11 10:01:58 +01:00
|
|
|
export interface ErrorContainerProps {
|
|
|
|
|
queryError?: DataQueryError;
|
2019-05-10 14:00:39 +02:00
|
|
|
}
|
|
|
|
|
|
2021-01-20 07:59:48 +01:00
|
|
|
export const ErrorContainer: FunctionComponent<ErrorContainerProps> = (props) => {
|
2020-03-11 10:01:58 +01:00
|
|
|
const { queryError } = props;
|
2019-05-10 14:00:39 +02:00
|
|
|
const showError = queryError ? true : false;
|
|
|
|
|
const duration = showError ? 100 : 10;
|
2021-04-27 15:13:08 +02:00
|
|
|
const title = queryError ? 'Query error' : 'Unknown error';
|
|
|
|
|
const message = queryError?.message || queryError?.data?.message || null;
|
2019-05-10 14:00:39 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<FadeIn in={showError} duration={duration}>
|
2022-04-14 12:57:56 +02:00
|
|
|
<Alert severity="error" title={title} topSpacing={2}>
|
2021-04-27 15:13:08 +02:00
|
|
|
{message}
|
|
|
|
|
</Alert>
|
2019-05-10 14:00:39 +02:00
|
|
|
</FadeIn>
|
|
|
|
|
);
|
|
|
|
|
};
|