All files / comparison_chart/components/Footer index.jsx

60% Statements 12/20
0% Branches 0/2
0% Functions 0/6
63.16% Lines 12/19
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157                                1x             1x         1x         1x       1x                                               1x                                     1x                 1x                         1x                                         1x               1x       1x                                          
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
 
import Text from '@bufferapp/components/Text';
 
import {
  GridItem,
  ProfileIcon,
  SocialIcon,
} from '@bufferapp/analyze-shared-components';
 
function capitalizeWord(name) {
  return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
}
 
const Grid = styled.ul`
  display: flex;
  flex-wrap: wrap;
  padding: 0 0 0 0.5rem;
  margin: 0 auto;
`;
 
const Wrapper = styled.section`
  position: relative;
  padding: 0.5rem 0 0;
`;
 
const ProfileAvatarWrapper = styled.div`
  display: inline-flex;
  align-items: center;
  margin: 0 0.5rem 0 0;
`;
const ProfileUsernameWrapper = styled.div`
  margin: 0 0.75rem 0 0;
`;
 
const ProfileCell = ({ profileTotal, profile, gridWidth }) => (
  <GridItem
    gridWidth={gridWidth}
    metric={{
      label: profileTotal.metric.label,
      value: profileTotal.currentPeriodTotal,
      diff: profileTotal.currentPeriodDiff,
    }}
    smaller
    customLabel={
      <ProfileUsernameWrapper>
        <Text weight="medium" color="outerSpace" size="small">
          {profile.username}
        </Text>
      </ProfileUsernameWrapper>
    }
    prefix={
      <ProfileAvatarWrapper>
        <ProfileIcon color={profileTotal.metric.color} profile={profile} />
      </ProfileAvatarWrapper>
    }
  />
);
 
ProfileCell.propTypes = {
  profileTotal: PropTypes.shape({
    metric: PropTypes.shape({
      label: PropTypes.string.isRequired,
      color: PropTypes.string.isRequired,
    }),
    currentPeriodTotal: PropTypes.number.isRequired,
    currentPeriodDiff: PropTypes.number.isRequired,
    profileId: PropTypes.string.isRequired,
  }).isRequired,
  gridWidth: PropTypes.string.isRequired,
  profile: PropTypes.shape({
    id: PropTypes.string.isRequired,
    username: PropTypes.string.isRequired,
    avatarUrl: PropTypes.string.isRequired,
    service: PropTypes.string.isRequired,
  }).isRequired,
};
 
const ComingSoonWrapper = styled.div`
  display: flex;
  flex-wrap: wrap;
  margin-left: 0.8rem;
  margin-top: 1rem;
  position: relative;
  align-items: center;
`;
 
const ComingSoon = ({ metricKey, profile }) => (
  <ComingSoonWrapper>
    <SocialIcon
      service={profile.service}
      socialIconSize={18}
      avatarSize={12}
      inline
    />
    <Text size="small" color="lightSlate">
      {`${capitalizeWord(profile.service)} ${metricKey} coming soon`}
    </Text>
  </ComingSoonWrapper>
);
ComingSoon.propTypes = {
  metricKey: PropTypes.string.isRequired,
  profile: PropTypes.shape({
    id: PropTypes.string.isRequired,
    username: PropTypes.string.isRequired,
    avatarUrl: PropTypes.string.isRequired,
    service: PropTypes.string.isRequired,
  }).isRequired,
};
 
function renderGridItem(profileTotal) {
  const profile = this.profiles.find(p => p.id === profileTotal.profileId);
  const gridWidth = this.profileTotals.length === 4 ? '50%' : '33%';
  return (<ProfileCell
    gridWidth={gridWidth}
    key={profileTotal.profileId}
    profileTotal={profileTotal}
    profile={profile}
  />);
}
 
const ComparisonFooter = ({ profileTotals, profiles, metricKey }) => (
  <Wrapper>
    <Grid>
      {profileTotals.map(renderGridItem, { profiles, metricKey, profileTotals })}
    </Grid>
  </Wrapper>
);
 
ComparisonFooter.defaultProps = {
  loading: false,
};
 
ComparisonFooter.propTypes = {
  metricKey: PropTypes.string.isRequired,
  profileTotals: PropTypes.arrayOf(PropTypes.shape({
    metric: PropTypes.shape({
      label: PropTypes.string.isRequired,
      color: PropTypes.string.isRequired,
    }),
    currentPeriodTotal: PropTypes.number.isRequired,
    currentPeriodDiff: PropTypes.number.isRequired,
    profileId: PropTypes.string.isRequired,
  })).isRequired,
  profiles: PropTypes.arrayOf(PropTypes.shape({
    id: PropTypes.string.isRequired,
    username: PropTypes.string.isRequired,
    avatarUrl: PropTypes.string.isRequired,
    service: PropTypes.string.isRequired,
  })).isRequired,
};
 
export default ComparisonFooter;