All files / components/topMenu TopMenuCmp.tsx

80% Statements 12/15
55.56% Branches 5/9
50% Functions 2/4
75% Lines 9/12
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    5x 5x     5x                 2x       2x       5x 4x       2x                                     5x
import React from 'react';
import './TopMenuCmp.css';
const burgerIconSvg = require('./burger-icon.svg');
const leftArrowSvg = require('./left-arrow.svg');
 
 
export default class TopMenu extends React.PureComponent {
 
  public props: {
    leftIcon?: string;
    onClickMenuBtn?: Function;
    children?: any;
    [attrs: string]: any;
  };
 
  private onClickMenuBtn = () => {
    this.props.onClickMenuBtn && this.props.onClickMenuBtn();
  };
 
  private onClickBtnGoBack = () => {
    window.history.back();
  };
 
  public render(){
    const {leftIcon, children} = this.props;
    //todo: refactor
    // Not root route => Render top left arrow button
    if (window.location.hash !== "#/") {
      return(
        <div className="top-menu">
          <img src={ leftArrowSvg } className="top-menu-icon-left" onClick={ this.onClickBtnGoBack }/>
          { children }
          <img src={ leftIcon || burgerIconSvg } className="top-menu-icon-right"
            onClick={ this.onClickMenuBtn }/>
        </div>
      )
      // In root route => not to render top left arrow button
    } else {
      return (
        <div className="top-menu">
          { children }
          <img src={ leftIcon || burgerIconSvg } className="top-menu-icon-right"
            onClick={ this.onClickMenuBtn }/>
        </div>
      )
    }
  }
}