import React, {Component, PropTypes} from 'react' import classnames from 'classnames' import WorkspaceDropdown from './dropdowns/WorkspaceDropdown' import DebouncingInput from './base/DebouncingInput' import RequestActionsDropdown from './dropdowns/RequestActionsDropdown' import MethodTag from './MethodTag' import Dropdown from './base/Dropdown' class Sidebar extends Component { onFilterChange (value) { this.props.changeFilter(value); } renderRequestGroupRow (requestGroup) { const {activeFilter, activeRequest, addRequest, toggleRequestGroup, requests, requestGroups} = this.props; let filteredRequests = requests.filter( r => { // TODO: Move this to a lib file if (!activeFilter) { return true; } const toMatch = `${r.method} ::: ${r.name}`.toLowerCase(); const matchTokens = activeFilter.split(' '); for (let i = 0; i < matchTokens.length; i++) { if (toMatch.indexOf(matchTokens[i]) === -1) { return false; } } return true; } ); if (!requestGroup) { // Grab all requests that are not children of request groups // TODO: Optimize this filteredRequests = filteredRequests.filter(r => { return !requestGroups.find(rg => { return rg.children.find(c => c.id === r.id) }) }); return filteredRequests.map(request => this.renderRequestRow(request)); } // Grab all of the children for this request group filteredRequests = filteredRequests.filter( r => requestGroup.children.find(c => c.id === r.id) ); // Don't show folder if it was not in the filter if (activeFilter && !filteredRequests.length) { return null; } const isActive = activeRequest && filteredRequests.find(r => r.id == activeRequest.id); let folderIconClass = 'fa-folder'; let expanded = activeFilter || !requestGroup.collapsed; folderIconClass += !expanded ? '' : '-open'; folderIconClass += isActive ? '' : '-o'; const sidebarItemClassNames = classnames( 'sidebar__item', 'sidebar__item--bordered', {'sidebar__item--active': isActive} ); return (
  • ); } renderRequestRow (request, requestGroup = null) { const {activeRequest, activateRequest} = this.props; const isActive = activeRequest && request.id === activeRequest.id; return (
  • ); } render () { const {activeFilter, requestGroups} = this.props; return ( ) } } Sidebar.propTypes = { activateRequest: PropTypes.func.isRequired, changeFilter: PropTypes.func.isRequired, toggleRequestGroup: PropTypes.func.isRequired, activeFilter: PropTypes.string, requests: PropTypes.array.isRequired, requestGroups: PropTypes.array.isRequired, activeRequest: PropTypes.object }; export default Sidebar;