const React = require('react'); const _ = require('lodash'); const AppActions = require('../actions/app-actions'); const GROUPINGS = [{ id: 'none', iconClass: 'fa fa-th', needsTopology: false }, { id: 'grouped', iconClass: 'fa fa-th-large', needsTopology: 'grouped_url' }]; const Groupings = React.createClass({ onGroupingClick: function(ev) { ev.preventDefault(); AppActions.clickGrouping(ev.currentTarget.getAttribute('rel')); }, getGroupingsSupportedByTopology: function(topology) { return _.filter(GROUPINGS, _.partial(this.isGroupingSupportedByTopology, topology)); }, renderGrouping: function(grouping, activeGroupingId) { let className = 'groupings-item'; const isSupportedByTopology = this.isGroupingSupportedByTopology(this.props.currentTopology, grouping); if (grouping.id === activeGroupingId) { className += ' groupings-item-active'; } else if (!isSupportedByTopology) { className += ' groupings-item-disabled'; } else { className += ' groupings-item-default'; } return (
); }, render: function() { const activeGrouping = this.props.active; const isGroupingSupported = _.size(this.getGroupingsSupportedByTopology(this.props.currentTopology)) > 1; return (
{isGroupingSupported && GROUPINGS.map(function(grouping) { return this.renderGrouping(grouping, activeGrouping); }, this)}
); }, isGroupingSupportedByTopology: function(topology, grouping) { return !grouping.needsTopology || topology && topology[grouping.needsTopology]; } }); module.exports = Groupings;