2016-07-16 02:06:10 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-07-06 20:18:26 +00:00
|
|
|
|
2016-07-22 22:27:04 +00:00
|
|
|
import Dropdown from '../base/Dropdown';
|
|
|
|
import DropdownHint from '../base/DropdownHint';
|
2016-07-16 02:06:10 +00:00
|
|
|
import SidebarRequestRow from './SidebarRequestRow';
|
2016-07-19 16:59:26 +00:00
|
|
|
import SidebarRequestGroupRow from './SidebarRequestGroupRow';
|
2016-07-22 22:27:04 +00:00
|
|
|
import WorkspaceDropdown from '../../containers/WorkspaceDropdown';
|
2016-03-18 00:36:00 +00:00
|
|
|
|
2016-07-25 22:27:29 +00:00
|
|
|
|
2016-03-23 05:26:27 +00:00
|
|
|
class Sidebar extends Component {
|
2016-06-19 00:08:14 +00:00
|
|
|
_onFilterChange (value) {
|
2016-03-23 05:26:27 +00:00
|
|
|
this.props.changeFilter(value);
|
|
|
|
}
|
|
|
|
|
2016-04-26 07:29:24 +00:00
|
|
|
_filterChildren (filter, children, extra = null) {
|
|
|
|
return children.filter(child => {
|
|
|
|
if (child.doc.type !== 'Request') {
|
2016-04-05 05:35:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-26 07:29:24 +00:00
|
|
|
const request = child.doc;
|
2016-04-05 05:35:21 +00:00
|
|
|
|
2016-04-26 07:29:24 +00:00
|
|
|
const otherMatches = extra || '';
|
|
|
|
const toMatch = `${request.method}❅${request.name}❅${otherMatches}`.toLowerCase();
|
|
|
|
const matchTokens = filter.toLowerCase().split(' ');
|
2016-04-05 05:35:21 +00:00
|
|
|
|
2016-04-26 07:29:24 +00:00
|
|
|
for (let i = 0; i < matchTokens.length; i++) {
|
|
|
|
let token = `${matchTokens[i]}`;
|
|
|
|
if (toMatch.indexOf(token) === -1) {
|
|
|
|
// Filter failed. Don't render children
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-04-07 01:11:16 +00:00
|
|
|
|
2016-04-26 07:29:24 +00:00
|
|
|
return true;
|
|
|
|
})
|
2016-03-24 10:20:11 +00:00
|
|
|
}
|
|
|
|
|
2016-04-26 07:29:24 +00:00
|
|
|
_renderChildren (children, requestGroup) {
|
2016-04-29 04:57:03 +00:00
|
|
|
const {
|
|
|
|
filter,
|
|
|
|
toggleRequestGroup,
|
2016-07-19 16:59:26 +00:00
|
|
|
addRequestToRequestGroup,
|
|
|
|
moveRequest,
|
|
|
|
moveRequestGroup,
|
|
|
|
activateRequest,
|
|
|
|
activeRequestId
|
2016-04-29 04:57:03 +00:00
|
|
|
} = this.props;
|
2016-04-26 07:29:24 +00:00
|
|
|
|
|
|
|
const filteredChildren = this._filterChildren(
|
|
|
|
filter,
|
|
|
|
children,
|
|
|
|
requestGroup && requestGroup.name
|
2016-07-19 16:59:26 +00:00
|
|
|
);
|
2016-04-26 07:29:24 +00:00
|
|
|
|
|
|
|
return filteredChildren.map(child => {
|
|
|
|
if (child.doc.type === 'Request') {
|
|
|
|
return (
|
|
|
|
<SidebarRequestRow
|
|
|
|
key={child.doc._id}
|
2016-07-19 16:59:26 +00:00
|
|
|
moveRequest={moveRequest}
|
|
|
|
activateRequest={activateRequest}
|
|
|
|
isActive={child.doc._id === activeRequestId}
|
2016-04-26 07:29:24 +00:00
|
|
|
request={child.doc}
|
|
|
|
/>
|
|
|
|
)
|
2016-04-29 04:57:03 +00:00
|
|
|
}
|
2016-05-01 19:56:30 +00:00
|
|
|
|
2016-04-29 04:57:03 +00:00
|
|
|
// We have a RequestGroup!
|
2016-04-26 07:29:24 +00:00
|
|
|
|
2016-04-29 04:57:03 +00:00
|
|
|
const requestGroup = child.doc;
|
2016-07-19 16:59:26 +00:00
|
|
|
const isActive = !!child.children.find(c => c.doc._id === activeRequestId);
|
2016-04-29 04:57:03 +00:00
|
|
|
|
|
|
|
const children = this._renderChildren(child.children, requestGroup);
|
|
|
|
|
|
|
|
// Don't render the row if there are no children while filtering
|
|
|
|
if (filter && !children.length) {
|
2016-04-26 07:29:24 +00:00
|
|
|
return null;
|
|
|
|
}
|
2016-04-29 04:57:03 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SidebarRequestGroupRow
|
|
|
|
key={requestGroup._id}
|
|
|
|
isActive={isActive}
|
2016-07-19 16:59:26 +00:00
|
|
|
moveRequestGroup={moveRequestGroup}
|
2016-07-21 03:58:52 +00:00
|
|
|
moveRequest={moveRequest}
|
2016-04-29 04:57:03 +00:00
|
|
|
toggleRequestGroup={toggleRequestGroup}
|
|
|
|
addRequestToRequestGroup={addRequestToRequestGroup}
|
|
|
|
numChildren={child.children.length}
|
2016-07-06 20:18:26 +00:00
|
|
|
requestGroup={requestGroup}>
|
2016-04-29 04:57:03 +00:00
|
|
|
{children}
|
|
|
|
</SidebarRequestGroupRow>
|
|
|
|
)
|
2016-04-26 07:29:24 +00:00
|
|
|
})
|
2016-03-24 10:20:11 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 05:26:27 +00:00
|
|
|
render () {
|
2016-07-21 19:15:35 +00:00
|
|
|
const {filter, children, requestCreate, requestGroupCreate} = this.props;
|
2016-03-23 05:26:27 +00:00
|
|
|
|
|
|
|
return (
|
2016-06-19 00:40:14 +00:00
|
|
|
<aside className="sidebar">
|
2016-05-01 19:56:30 +00:00
|
|
|
<header className="sidebar__header">
|
2016-04-15 02:13:49 +00:00
|
|
|
<WorkspaceDropdown />
|
2016-04-07 01:11:16 +00:00
|
|
|
</header>
|
2016-07-06 20:18:26 +00:00
|
|
|
|
2016-05-01 19:56:30 +00:00
|
|
|
<ul className="sidebar__list">
|
|
|
|
{this._renderChildren(children)}
|
|
|
|
</ul>
|
2016-07-06 20:18:26 +00:00
|
|
|
|
2016-07-21 19:15:35 +00:00
|
|
|
<footer className="sidebar__footer">
|
|
|
|
<Dropdown>
|
|
|
|
<button className="btn btn--compact">
|
|
|
|
<i className="fa fa-plus-circle"></i>
|
|
|
|
</button>
|
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
<button onClick={e => requestCreate()}>
|
|
|
|
<i className="fa fa-plus-circle"></i> New Request
|
2016-07-21 22:04:21 +00:00
|
|
|
<DropdownHint char="N"></DropdownHint>
|
2016-07-21 19:15:35 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<button onClick={e => requestGroupCreate()}>
|
|
|
|
<i className="fa fa-folder"></i> New Folder
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</Dropdown>
|
|
|
|
<div className="form-control form-control--underlined">
|
2016-07-28 20:10:26 +00:00
|
|
|
<input
|
2016-07-21 19:15:35 +00:00
|
|
|
type="text"
|
|
|
|
placeholder="Filter Requests"
|
|
|
|
value={filter}
|
2016-07-28 20:10:26 +00:00
|
|
|
onChange={e => this._onFilterChange(e.target.value)}
|
2016-07-21 19:15:35 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2016-07-19 16:15:03 +00:00
|
|
|
</footer>
|
2016-05-01 19:56:30 +00:00
|
|
|
</aside>
|
2016-03-23 05:26:27 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2016-03-18 00:36:00 +00:00
|
|
|
|
2016-03-20 04:00:40 +00:00
|
|
|
Sidebar.propTypes = {
|
2016-04-26 07:29:24 +00:00
|
|
|
// Functions
|
2016-03-20 04:47:43 +00:00
|
|
|
activateRequest: PropTypes.func.isRequired,
|
2016-04-26 07:29:24 +00:00
|
|
|
toggleRequestGroup: PropTypes.func.isRequired,
|
2016-04-16 23:24:57 +00:00
|
|
|
addRequestToRequestGroup: PropTypes.func.isRequired,
|
2016-03-23 05:26:27 +00:00
|
|
|
changeFilter: PropTypes.func.isRequired,
|
2016-07-19 16:59:26 +00:00
|
|
|
moveRequest: PropTypes.func.isRequired,
|
|
|
|
moveRequestGroup: PropTypes.func.isRequired,
|
2016-07-21 19:15:35 +00:00
|
|
|
requestCreate: PropTypes.func.isRequired,
|
|
|
|
requestGroupCreate: PropTypes.func.isRequired,
|
2016-04-26 07:29:24 +00:00
|
|
|
|
|
|
|
// Other
|
|
|
|
children: PropTypes.array.isRequired,
|
|
|
|
|
|
|
|
// Optional
|
|
|
|
filter: PropTypes.string,
|
|
|
|
activeRequestId: PropTypes.string
|
2016-03-20 04:00:40 +00:00
|
|
|
};
|
2016-03-18 00:36:00 +00:00
|
|
|
|
|
|
|
export default Sidebar;
|