Code coverage report for src/components/reference-book/reference-book.cjsx

Statements: 100% (32 / 32)      Branches: 75% (12 / 16)      Functions: 100% (8 / 8)      Lines: 100% (32 / 32)      Ignored: none     

All files » src/components/reference-book/ » reference-book.cjsx
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                                                             38× 38× 38×                   27×     11× 11×         12×                   54× 54×     54× 54×       54×                                                                
var ChapterSectionMixin, MENU_VISIBLE_BREAKPOINT, Menu, NavBar, PageNavigation, PageShell, React, ReferenceBookActions, ReferenceBookStore, ResizeListenerMixin, SpyMode, _, classnames, ref, ref1;
 
React = require('react');
 
_ = require('underscore');
 
classnames = require('classnames');
 
SpyMode = require('openstax-react-components').SpyMode;
 
ref = require('../../flux/reference-book'), ReferenceBookActions = ref.ReferenceBookActions, ReferenceBookStore = ref.ReferenceBookStore;
 
NavBar = require('./navbar');
 
Menu = require('./slide-out-menu');
 
ref1 = require('openstax-react-components'), ChapterSectionMixin = ref1.ChapterSectionMixin, ResizeListenerMixin = ref1.ResizeListenerMixin;
 
PageShell = require('./page-shell');
 
PageNavigation = require('./page-navigation');
 
MENU_VISIBLE_BREAKPOINT = 1350;
 
module.exports = React.createClass({
  displayName: 'ReferenceBook',
  mixins: [ResizeListenerMixin, ChapterSectionMixin],
  propTypes: {
    navbarControls: React.PropTypes.element,
    ecosystemId: React.PropTypes.string.isRequired,
    dataProps: React.PropTypes.object,
    section: React.PropTypes.string,
    cnxId: React.PropTypes.string,
    className: React.PropTypes.string,
    contentComponent: React.PropTypes.func,
    menuRouterLinkTarget: React.PropTypes.string,
    onSectionSelection: React.PropTypes.func
  },
  getDefaultProps: function() {
    return {
      contentComponent: PageShell
    };
  },
  defaultStateFromProps: function(props) {
    var section;
    section = props.section || this.sectionFormat(ReferenceBookStore.getFirstSection(this.props.ecosystemId));
    return this.setState({
      section: section,
      ecosystemId: props.ecosystemId || this.props.ecosystemId,
      cnxId: props.cnxId || ReferenceBookStore.getChapterSectionPage({
        ecosystemId: this.props.ecosystemId,
        section: section
      }).cnx_id
    });
  },
  componentWillReceiveProps: function(nextProps) {
    return this.defaultStateFromProps(nextProps);
  },
  componentWillMount: function() {
    this.defaultStateFromProps(this.props);
    return this.setState({
      isMenuVisible: !this.isMenuOnTop()
    });
  },
  isMenuOnTop: function() {
    return this.state.windowEl.width < MENU_VISIBLE_BREAKPOINT;
  },
  onMenuClick: function(section, ev) {
    var base;
    Eif (this.isMenuOnTop()) {
      this.toggleMenuState();
    }
    return typeof (base = this.props).onSectionSelection === "function" ? base.onSectionSelection(section, ev) : void 0;
  },
  toggleMenuState: function(ev) {
    this.setState({
      isMenuVisible: !this.state.isMenuVisible
    });
    return ev != null ? ev.preventDefault() : void 0;
  },
  render: function() {
    var className, nav, pageInfo, ref2, ref3;
    className = classnames('reference-book', this.props.className, {
      'menu-open': this.state.isMenuVisible
    });
    pageInfo = ReferenceBookStore.getPageInfo(this.state);
    nav = _.defaults({}, this.props.navigation, {
      next: !!pageInfo.next,
      prev: !!pageInfo.prev
    });
    return React.createElement("div", React.__spread({}, this.props.dataProps, {
      "className": className
    }), React.createElement(SpyMode.Wrapper, null, React.createElement(NavBar, {
      "ecosystemId": this.props.ecosystemId,
      "section": this.state.section,
      "toggleTocMenu": this.toggleMenuState,
      "isMenuVisible": this.state.isMenuVisible,
      "extraControls": this.props.navbarControls
    }), React.createElement("div", {
      "className": "content"
    }, React.createElement(Menu, React.__spread({}, this.props, {
      "ecosystemId": this.props.ecosystemId,
      "activeSection": this.state.section,
      "onMenuSelection": this.onMenuClick
    })), React.createElement(PageNavigation, React.__spread({
      "direction": 'prev'
    }, this.props, {
      "enabled": nav.prev,
      "section": this.sectionFormat((ref2 = pageInfo.prev) != null ? ref2.chapter_section : void 0)
    })), React.createElement(this.props.contentComponent, {
      "cnxId": this.state.cnxId,
      "section": this.state.section,
      "ecosystemId": this.props.ecosystemId
    }), React.createElement(PageNavigation, React.__spread({
      "direction": 'next'
    }, this.props, {
      "enabled": nav.next,
      "section": this.sectionFormat((ref3 = pageInfo.next) != null ? ref3.chapter_section : void 0)
    })))));
  }
});