2022-04-22 08:33:13 -05:00
|
|
|
import { css } from '@emotion/css';
|
2022-04-20 04:42:32 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { useEffectOnce } from 'react-use';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2022-04-20 04:42:32 -05:00
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { Alert, useStyles2 } from '@grafana/ui';
|
2022-04-20 04:42:32 -05:00
|
|
|
import { AppNotification, timeoutMap } from 'app/types';
|
2018-10-24 07:33:53 -05:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
appNotification: AppNotification;
|
2020-08-26 04:38:39 -05:00
|
|
|
onClearNotification: (id: string) => void;
|
2018-10-24 07:33:53 -05:00
|
|
|
}
|
|
|
|
|
2022-04-20 04:42:32 -05:00
|
|
|
export default function AppNotificationItem({ appNotification, onClearNotification }: Props) {
|
|
|
|
const styles = useStyles2(getStyles);
|
2018-10-24 07:33:53 -05:00
|
|
|
|
2022-04-20 04:42:32 -05:00
|
|
|
useEffectOnce(() => {
|
2018-10-24 07:33:53 -05:00
|
|
|
setTimeout(() => {
|
|
|
|
onClearNotification(appNotification.id);
|
2022-04-20 04:42:32 -05:00
|
|
|
}, timeoutMap[appNotification.severity]);
|
|
|
|
});
|
2018-10-24 07:33:53 -05:00
|
|
|
|
2023-04-24 03:20:47 -05:00
|
|
|
const hasBody = appNotification.component || appNotification.text || appNotification.traceId;
|
|
|
|
|
2022-04-20 04:42:32 -05:00
|
|
|
return (
|
|
|
|
<Alert
|
|
|
|
severity={appNotification.severity}
|
|
|
|
title={appNotification.title}
|
|
|
|
onRemove={() => onClearNotification(appNotification.id)}
|
|
|
|
elevated
|
|
|
|
>
|
2023-04-24 03:20:47 -05:00
|
|
|
{hasBody && (
|
|
|
|
<div className={styles.wrapper}>
|
|
|
|
<span>{appNotification.component || appNotification.text}</span>
|
|
|
|
{appNotification.traceId && <span className={styles.trace}>Trace ID: {appNotification.traceId}</span>}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-04-20 04:42:32 -05:00
|
|
|
</Alert>
|
|
|
|
);
|
|
|
|
}
|
2018-12-15 03:04:25 -06:00
|
|
|
|
2022-04-20 04:42:32 -05:00
|
|
|
function getStyles(theme: GrafanaTheme2) {
|
|
|
|
return {
|
|
|
|
wrapper: css({
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
}),
|
|
|
|
trace: css({
|
|
|
|
fontSize: theme.typography.pxToRem(10),
|
|
|
|
}),
|
|
|
|
};
|
2018-10-24 07:33:53 -05:00
|
|
|
}
|