AppNotificationItem.tsx 930 B

12345678910111213141516171819202122232425262728293031323334
  1. import React, { Component } from 'react';
  2. import { AppNotification } from 'app/types';
  3. import { Alert } from '@grafana/ui';
  4. interface Props {
  5. appNotification: AppNotification;
  6. onClearNotification: (id: number) => void;
  7. }
  8. export default class AppNotificationItem extends Component<Props> {
  9. shouldComponentUpdate(nextProps: Props) {
  10. return this.props.appNotification.id !== nextProps.appNotification.id;
  11. }
  12. componentDidMount() {
  13. const { appNotification, onClearNotification } = this.props;
  14. setTimeout(() => {
  15. onClearNotification(appNotification.id);
  16. }, appNotification.timeout);
  17. }
  18. render() {
  19. const { appNotification, onClearNotification } = this.props;
  20. return (
  21. <Alert
  22. severity={appNotification.severity}
  23. title={appNotification.title}
  24. children={appNotification.text}
  25. onRemove={() => onClearNotification(appNotification.id)}
  26. />
  27. );
  28. }
  29. }