All files / components/header-bar/header-notifications header-notifications.jsx

80% Statements 8/10
46.15% Branches 6/13
75% Functions 3/4
80% Lines 8/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73            1x 1x 1x                   1x 1x                   1x                                                               1x           1x          
import React from 'react';
import NotificationItem from './notification-item.jsx';
import PropTypes from 'prop-types';
 
class HeaderNotifications extends React.Component {
  constructor(props) {
    super(props);
    this.state = { open: false };
    this.toggleDropdown = this.toggleDropdown.bind(this);
  }
 
  toggleDropdown(e) {
    if ((e.type === 'blur' && this.state.open) || e.type !== 'blur') {
      this.setState({ open: !this.state.open });
    }
  }
 
  render() {
    const notificationList = this.props.notifications.map((notificationDetails, i) => {
      return (
        <NotificationItem
          key={i}
          icon={notificationDetails.icon}
          content={notificationDetails.content}
          link={notificationDetails.link}
          onClick={notificationDetails.onClick}
        />
      );
    });
    return (
      <li className={`dropdown notifications-menu${this.state.open ? ' open' : ''}`} tabIndex="0" onBlur={this.toggleDropdown}>
        <a className="dropdown-toggle" data-toggle="dropdown-menu" onClick={this.toggleDropdown}>
          <i className="fa fa-bell-o" />
          <span className="label label-warning">
            {this.props.count || this.props.notifications.length}
          </span>
        </a>
        <ul className="dropdown-menu">
          <li className="header">
            You have {this.props.count || this.props.notifications.length} notifications
          </li>
          <li>
            <div className="slimScrollDiv">
              <ul className="menu">
                {notificationList}
              </ul>
              <div className="slimScrollBar" />
              <div className="slimScrollRail" />
            </div>
          </li>
          {this.props.clickHandler ? (
            <li className="footer" onClick={this.props.clickHandler}>
              <a>View all</a>
            </li>
          ) : ''}
        </ul>
      </li>
    );
  }
}
 
HeaderNotifications.propTypes = {
  count: PropTypes.number,
  notifications: PropTypes.array,
  clickHandler: PropTypes.func
};
 
HeaderNotifications.defaultProps = {
  notifications: []
};
 
export default HeaderNotifications;