import React from 'react' import PropTypes from 'prop-types' import { translate } from 'react-i18next' export class TableHeaderSortItem extends React.Component { static propTypes = { t: PropTypes.func.isRequired, isSorted: PropTypes.bool.isRequired, sortDirection: PropTypes.string.isRequired, title: PropTypes.string.isRequired, width: PropTypes.string, sortAction: PropTypes.func.isRequired, fieldName: PropTypes.string.isRequired, textAlign: PropTypes.string }; onClick = () => { const sortDirection = (!this.props.isSorted || this.props.sortDirection === 'desc') ? 'asc' : 'desc' this.props.sortAction({sortByField: this.props.fieldName, sortDirection: sortDirection}) }; render () { const {t, isSorted, sortDirection} = this.props return ( {t(this.props.title)} {!isSorted && } {isSorted && sortDirection === 'asc' && } {isSorted && sortDirection === 'desc' && } ) } } export default translate(['tabsContent'], { wait: true })(TableHeaderSortItem)