2018-10-24 20:33:53 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { AppNotification } from 'app/types';
|
2019-09-20 19:41:00 +08:00
|
|
|
import { Alert } from '@grafana/ui';
|
2018-10-24 20:33:53 +08:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
appNotification: AppNotification;
|
2020-08-26 17:38:39 +08:00
|
|
|
onClearNotification: (id: string) => void;
|
2018-10-24 20:33:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class AppNotificationItem extends Component<Props> {
|
2019-05-12 20:15:23 +08:00
|
|
|
shouldComponentUpdate(nextProps: Props) {
|
2018-10-24 20:33:53 +08:00
|
|
|
return this.props.appNotification.id !== nextProps.appNotification.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const { appNotification, onClearNotification } = this.props;
|
|
|
|
setTimeout(() => {
|
|
|
|
onClearNotification(appNotification.id);
|
|
|
|
}, appNotification.timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { appNotification, onClearNotification } = this.props;
|
2018-12-15 17:04:25 +08:00
|
|
|
|
2018-10-24 20:33:53 +08:00
|
|
|
return (
|
2019-09-20 19:41:00 +08:00
|
|
|
<Alert
|
2019-02-07 02:42:04 +08:00
|
|
|
severity={appNotification.severity}
|
|
|
|
title={appNotification.title}
|
2019-09-20 19:41:00 +08:00
|
|
|
onRemove={() => onClearNotification(appNotification.id)}
|
2021-04-14 00:00:55 +08:00
|
|
|
elevated
|
2020-11-18 22:36:35 +08:00
|
|
|
>
|
|
|
|
{appNotification.component || appNotification.text}
|
|
|
|
</Alert>
|
2018-10-24 20:33:53 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|