import React from 'react'; import PropTypes from 'prop-types'; import { gettext } from '../../../utils/constants'; const propTypes = { type: PropTypes.string.isRequired, children: PropTypes.oneOfType([PropTypes.bool, PropTypes.array]), }; class TrafficTable extends React.Component { constructor(props) { super(props); this.state = { showIconName: 'link_file_download' }; } componentDidMount() { let { showIconName } = this.state; let { sortOrder } = this.props; this.props.sortBySize(showIconName, sortOrder); } getTrafficTypeName = () => { let { type } = this.props; let trafficTypeName; switch(type) { case 'user': trafficTypeName = 'User'; break; case 'org': trafficTypeName = 'Org'; break; } return trafficTypeName; } sortBySize = (sortByType) => { let { sortOrder } = this.props; let newSortOrder = sortOrder === 'asc' ? 'desc' : 'asc'; this.setState({ showIconName: sortByType }); this.props.sortBySize(sortByType, newSortOrder); } render() { let { sortOrder } = this.props; let { showIconName } = this.state; let trafficTypeName = this.getTrafficTypeName(); const sortIcon = sortOrder == 'asc' ? : ; return ( {this.props.children}
{gettext('{trafficTypeName}').replace('{trafficTypeName}', trafficTypeName)}
{gettext('Sync Upload')} {showIconName === 'sync_file_upload' && sortIcon}
{gettext('Sync Download')} {showIconName === 'sync_file_donwload' && sortIcon}
{gettext('Web Upload')} {showIconName === 'web_file_upload' && sortIcon}
{gettext('Web Download')} {showIconName === 'web_file_download' && sortIcon}
{gettext('Link Upload')} {showIconName === 'link_file_upload' && sortIcon}
{gettext('Link Download')} {showIconName === 'link_file_download' && sortIcon}
); } } TrafficTable.propTypes = propTypes; export default TrafficTable;