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