All files / src/components/HistoryLink index.jsx

0% Statements 0/33
0% Branches 0/18
0% Functions 0/2
0% Lines 0/20
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                                                                                     
import styles from './style.postcss';
 
import React from 'react';
import pure from 'recompose/pure';
import is from 'is_js';
import { Link } from 'react-router';
import classnames from 'classnames';
import Icon from 'components/Icon';
import PropTypes from 'prop-types';
import testClass from 'domain/testClass';
 
const HistoryLink = (props) => {
  const currentRoute = props.routes[props.routes.length - 1];
  let history = currentRoute.history;
 
  if (is.function(currentRoute.canAccess) && (! (currentRoute.canAccess(props)))) return null;
 
  if (! (is.object(history) || is.function(history))) return null;
 
  if (is.function(history)) {
    history = history(props);
  }
 
  if (history && is.not.string(history.link)) return null;
 
  return <div className={classnames(styles.HistoryLink, props.className, testClass('history-link'))}>
    <Link to={history.link}
        draggable={false}>
      History
      <Icon id="history2" />
    </Link>
  </div>;
};
 
HistoryLink.propTypes = {
  className: PropTypes.string,
  params: PropTypes.object.isRequired,
  routes: PropTypes.array.isRequired,
  buildRoute: PropTypes.func.isRequired,
};
 
export default pure(HistoryLink);