# All files / composer/components ProfileGroupItem.jsx

45.45% Statements 5/11
25% Branches 1/4
66.67% Functions 2/3
50% Lines 5/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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

    2x

    2x
    2x

    2x

    2x

     import React from 'react';
    import PropTypes from 'prop-types';
    import AppActionCreators from '../action-creators/AppActionCreators';
    import Button from '../components/Button';

    import styles from './css/ProfileGroupItem.css';

    class ProfileGroupItem extends React.Component {
      static propTypes = {
        group: PropTypes.object.isRequired,
        selectedProfileGroupsIds: PropTypes.array.isRequired,
      };

      onClick = (e) => {
        const { group, selectedProfileGroupsIds } = this.props;
        const { id } = group;

        if (this.isSelected(id)) AppActionCreators.unselectGroupProfiles(id, selectedProfileGroupsIds);
        else AppActionCreators.selectGroupProfiles(id);

        e.preventDefault();
      };

      isSelected = (id) => this.props.selectedProfileGroupsIds.includes(id);

      render() {
        const { group } = this.props;
        const profilesCount = group.profileIds.length;

        const groupItemClassName = [
          this.isSelected(group.id) ? styles.selectedGroupBtn : styles.unselectedGroupBtn,
          'js-disable-dragging',
        ].join(' ');

        return (
          <Button className={groupItemClassName} onClick={this.onClick}>
            <span className={styles.groupName}>{group.name}</span>
            <span className={styles.profilesCount}>{profilesCount}</span>
          </Button>
        );
      }
    }

    export default ProfileGroupItem;