grafana/public/app/core/components/AppNotifications/AppNotificationItem.tsx

35 lines
959 B
TypeScript
Raw Normal View History

2018-10-24 07:33:53 -05:00
import React, { Component } from 'react';
import { AppNotification } from 'app/types';
import { Alert } from '@grafana/ui';
2018-10-24 07:33:53 -05:00
interface Props {
appNotification: AppNotification;
onClearNotification: (id: number) => void;
2018-10-24 07:33:53 -05:00
}
export default class AppNotificationItem extends Component<Props> {
shouldComponentUpdate(nextProps: Props) {
2018-10-24 07:33:53 -05: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 03:04:25 -06:00
2018-10-24 07:33:53 -05:00
return (
<Alert
severity={appNotification.severity}
title={appNotification.title}
children={appNotification.component || appNotification.text}
onRemove={() => onClearNotification(appNotification.id)}
/>
2018-10-24 07:33:53 -05:00
);
}
}