2018-06-14 09:14:32 +00:00
|
|
|
// @flow
|
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
import { FlagGroup } from '@atlaskit/flag';
|
2018-06-14 09:14:32 +00:00
|
|
|
import React from 'react';
|
2019-03-21 16:38:29 +00:00
|
|
|
|
2019-03-27 14:00:10 +00:00
|
|
|
import { connect } from '../../../base/redux';
|
2017-07-28 17:56:49 +00:00
|
|
|
|
2018-06-14 09:14:32 +00:00
|
|
|
import AbstractNotificationsContainer, {
|
2020-02-25 10:47:37 +00:00
|
|
|
_abstractMapStateToProps,
|
|
|
|
type Props as AbstractProps
|
2019-03-27 14:00:10 +00:00
|
|
|
} from '../AbstractNotificationsContainer';
|
|
|
|
|
2018-06-14 09:14:32 +00:00
|
|
|
import Notification from './Notification';
|
2017-12-11 18:33:09 +00:00
|
|
|
|
2020-02-25 10:47:37 +00:00
|
|
|
type Props = AbstractProps & {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whther we are a SIP gateway or not.
|
|
|
|
*/
|
|
|
|
_iAmSipGateway: boolean
|
|
|
|
};
|
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} which displays notifications and handles
|
|
|
|
* automatic dismissmal after a notification is shown for a defined timeout
|
|
|
|
* period.
|
|
|
|
*
|
|
|
|
* @extends {Component}
|
|
|
|
*/
|
2018-06-14 09:14:32 +00:00
|
|
|
class NotificationsContainer extends AbstractNotificationsContainer<Props> {
|
2017-07-28 17:56:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2020-02-25 10:47:37 +00:00
|
|
|
if (this.props._iAmSipGateway) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
return (
|
|
|
|
<FlagGroup onDismissed = { this._onDismissed }>
|
2017-08-02 18:15:55 +00:00
|
|
|
{ this._renderFlags() }
|
2017-07-28 17:56:49 +00:00
|
|
|
</FlagGroup>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-14 09:14:32 +00:00
|
|
|
_onDismissed: number => void;
|
2017-08-02 18:15:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders notifications to display as ReactElements. An empty array will
|
|
|
|
* be returned if notifications are disabled.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement[]}
|
|
|
|
*/
|
|
|
|
_renderFlags() {
|
2018-06-14 09:14:32 +00:00
|
|
|
const { _notifications } = this.props;
|
2017-08-02 18:15:55 +00:00
|
|
|
|
|
|
|
return _notifications.map(notification => {
|
|
|
|
const { props, uid } = notification;
|
|
|
|
|
|
|
|
// The id attribute is necessary as {@code FlagGroup} looks for
|
|
|
|
// either id or key to set a key on notifications, but accessing
|
|
|
|
// props.key will cause React to print an error.
|
|
|
|
return (
|
|
|
|
<Notification
|
|
|
|
{ ...props }
|
|
|
|
id = { uid }
|
|
|
|
key = { uid }
|
|
|
|
uid = { uid } />
|
|
|
|
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2017-07-28 17:56:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 10:47:37 +00:00
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated props for this component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
const { iAmSipGateway } = state['features/base/config'];
|
|
|
|
|
|
|
|
return {
|
|
|
|
..._abstractMapStateToProps(state),
|
|
|
|
_iAmSipGateway: Boolean(iAmSipGateway)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
export default connect(_mapStateToProps)(NotificationsContainer);
|