insomnia/app/components/Sidebar.js

117 lines
3.9 KiB
JavaScript
Raw Normal View History

2016-03-23 05:26:27 +00:00
import React, {Component, PropTypes} from 'react'
2016-03-22 05:01:58 +00:00
import Dropdown from './base/Dropdown'
2016-03-23 05:26:27 +00:00
import DebouncingInput from './base/DebouncingInput'
2016-04-03 22:54:39 +00:00
import RequestActionsDropdown from './dropdowns/RequestActionsDropdown'
2016-03-18 00:36:00 +00:00
2016-03-23 05:26:27 +00:00
class Sidebar extends Component {
onFilterChange (value) {
this.props.changeFilter(value);
}
2016-04-03 22:54:39 +00:00
renderRequestGroupRow (requestGroup) {
2016-03-24 10:20:11 +00:00
const {activeFilter, addRequest, requests} = this.props;
const filteredRequests = requests.filter(
r => !requestGroup || requestGroup.requests.find(r.id)
).filter(
r => r.name.toLowerCase().indexOf(activeFilter.toLowerCase()) >= 0
);
if (requestGroup) {
return (
<li>
<div className="grid">
<button className="sidebar__item col text-left">
<i className="fa fa-folder-open-o"></i>&nbsp;&nbsp;&nbsp;Request Group
</button>
<button className="sidebar__item-btn" onClick={(e) => addRequest()}>
<i className="fa fa-plus-circle"></i>
</button>
</div>
<ul>
2016-04-03 22:54:39 +00:00
{filteredRequests.map(request => this.renderRequestRow(request))}
2016-03-24 10:20:11 +00:00
</ul>
</li>
)
} else {
return (
2016-04-03 22:54:39 +00:00
filteredRequests.map(request => this.renderRequestRow(request))
2016-03-24 10:20:11 +00:00
)
}
}
2016-04-03 22:54:39 +00:00
renderRequestRow (request) {
2016-03-24 10:20:11 +00:00
const {activeRequest, activateRequest} = this.props;
2016-04-03 22:54:39 +00:00
const isActive = activeRequest && request.id === activeRequest.id;
const className = ['grid'].concat(isActive ? ['active'] : '');
2016-03-24 10:20:11 +00:00
return (
2016-04-03 22:54:39 +00:00
<li key={request.id} className={className.join(' ')}>
<button className='sidebar__item col' onClick={() => {activateRequest(request.id)}}>
2016-03-24 10:20:11 +00:00
{request.name}
</button>
2016-04-03 22:54:39 +00:00
<RequestActionsDropdown right={true} request={request}/>
2016-03-24 10:20:11 +00:00
</li>
);
}
2016-03-23 05:26:27 +00:00
render () {
2016-03-24 10:20:11 +00:00
const {activeFilter, loading, addRequest, requestGroups} = this.props;
2016-03-23 05:26:27 +00:00
return (
<aside className="sidebar pane">
<div className="grid-v">
<header className="pane__header bg-primary">
<h1>
<Dropdown right={true}>
2016-03-23 18:34:39 +00:00
<button className="pane__header__content">
2016-03-23 05:26:27 +00:00
<i className="fa fa-angle-down pull-right"></i>
{loading ? <i className="fa fa-refresh fa-spin pull-right"></i> : ''}
Insomnia
2016-03-23 18:34:39 +00:00
</button>
2016-03-23 05:26:27 +00:00
<ul className="bg-super-light">
2016-03-23 18:34:39 +00:00
<li>
<button onClick={(e) => addRequest()}>
<i className="fa fa-plus-circle"></i> Add Request
</button>
</li>
<li><button><i className="fa fa-share-square-o"></i> Import/Export</button></li>
<li><button><i className="fa fa-empty"></i> Toggle Sidebar</button></li>
<li><button><i className="fa fa-empty"></i> Delete Workspace</button></li>
2016-03-23 05:26:27 +00:00
</ul>
</Dropdown>
</h1>
</header>
<div className="pane__body hide-scrollbars bg-dark">
<div className="stock-height form-control form-control--outlined col">
<DebouncingInput
type="text"
placeholder="Filter Requests"
debounceMillis={100}
value={activeFilter}
onChange={this.onFilterChange.bind(this)}/>
2016-03-22 05:01:58 +00:00
</div>
2016-03-23 05:26:27 +00:00
<ul>
2016-04-03 22:54:39 +00:00
{this.renderRequestGroupRow(null)}
{requestGroups.map(requestGroup => this.renderRequestGroupRow(requestGroup))}
2016-03-23 05:26:27 +00:00
</ul>
</div>
</div>
</aside>
)
}
}
2016-03-18 00:36:00 +00:00
2016-03-20 04:00:40 +00:00
Sidebar.propTypes = {
2016-03-20 04:47:43 +00:00
activateRequest: PropTypes.func.isRequired,
2016-03-22 05:01:58 +00:00
addRequest: PropTypes.func.isRequired,
2016-03-23 05:26:27 +00:00
changeFilter: PropTypes.func.isRequired,
activeFilter: PropTypes.string,
2016-03-20 23:20:00 +00:00
requests: PropTypes.array.isRequired,
2016-03-24 10:20:11 +00:00
requestGroups: PropTypes.array.isRequired,
2016-03-20 23:20:00 +00:00
activeRequest: PropTypes.object,
2016-03-20 04:00:40 +00:00
loading: PropTypes.bool.isRequired
};
2016-03-18 00:36:00 +00:00
export default Sidebar;