您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

NotificationsContainer.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // @flow
  2. import { FlagGroup } from '@atlaskit/flag';
  3. import React from 'react';
  4. import { translate } from '../../../base/i18n';
  5. import { connect } from '../../../base/redux';
  6. import AbstractNotificationsContainer, {
  7. _abstractMapStateToProps,
  8. type Props as AbstractProps
  9. } from '../AbstractNotificationsContainer';
  10. import Notification from './Notification';
  11. type Props = AbstractProps & {
  12. /**
  13. * Whether we are a SIP gateway or not.
  14. */
  15. _iAmSipGateway: boolean,
  16. /**
  17. * Invoked to obtain translated strings.
  18. */
  19. t: Function
  20. };
  21. /**
  22. * Implements a React {@link Component} which displays notifications and handles
  23. * automatic dismissmal after a notification is shown for a defined timeout
  24. * period.
  25. *
  26. * @extends {Component}
  27. */
  28. class NotificationsContainer extends AbstractNotificationsContainer<Props> {
  29. /**
  30. * Implements React's {@link Component#render()}.
  31. *
  32. * @inheritdoc
  33. * @returns {ReactElement}
  34. */
  35. render() {
  36. if (this.props._iAmSipGateway) {
  37. return null;
  38. }
  39. return (
  40. <FlagGroup
  41. id = 'notifications-container'
  42. label = { this.props.t('notify.groupTitle') }
  43. onDismissed = { this._onDismissed }>
  44. { this._renderFlags() }
  45. </FlagGroup>
  46. );
  47. }
  48. _onDismissed: number => void;
  49. /**
  50. * Renders notifications to display as ReactElements. An empty array will
  51. * be returned if notifications are disabled.
  52. *
  53. * @private
  54. * @returns {ReactElement[]}
  55. */
  56. _renderFlags() {
  57. const { _notifications } = this.props;
  58. return _notifications.map(notification => {
  59. const { props, uid } = notification;
  60. // The id attribute is necessary as {@code FlagGroup} looks for
  61. // either id or key to set a key on notifications, but accessing
  62. // props.key will cause React to print an error.
  63. return (
  64. <Notification
  65. { ...props }
  66. id = { uid }
  67. key = { uid }
  68. onDismissed = { this._onDismissed }
  69. uid = { uid } />
  70. );
  71. });
  72. }
  73. }
  74. /**
  75. * Maps (parts of) the Redux state to the associated props for this component.
  76. *
  77. * @param {Object} state - The Redux state.
  78. * @private
  79. * @returns {Props}
  80. */
  81. function _mapStateToProps(state) {
  82. const { iAmSipGateway } = state['features/base/config'];
  83. return {
  84. ..._abstractMapStateToProps(state),
  85. _iAmSipGateway: Boolean(iAmSipGateway)
  86. };
  87. }
  88. export default translate(connect(_mapStateToProps)(NotificationsContainer));