2017-08-10 01:56:27 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-03-08 05:52:17 +00:00
|
|
|
import SidebarRequestRow from './sidebar-request-row';
|
|
|
|
import SidebarRequestGroupRow from './sidebar-request-group-row';
|
2017-07-31 21:14:16 +00:00
|
|
|
import * as models from '../../../models/index';
|
2016-11-25 23:09:17 +00:00
|
|
|
|
2016-11-25 23:21:07 +00:00
|
|
|
class SidebarChildren extends PureComponent {
|
2017-02-01 03:01:27 +00:00
|
|
|
_renderChildren (children) {
|
2016-11-25 23:09:17 +00:00
|
|
|
const {
|
|
|
|
handleCreateRequest,
|
|
|
|
handleCreateRequestGroup,
|
|
|
|
handleSetRequestGroupCollapsed,
|
2016-11-27 21:42:38 +00:00
|
|
|
handleDuplicateRequest,
|
2016-11-28 07:12:17 +00:00
|
|
|
handleDuplicateRequestGroup,
|
|
|
|
handleGenerateCode,
|
2017-06-29 18:27:29 +00:00
|
|
|
handleCopyAsCurl,
|
2017-06-13 20:45:15 +00:00
|
|
|
moveDoc,
|
2016-11-25 23:09:17 +00:00
|
|
|
handleActivateRequest,
|
|
|
|
activeRequest,
|
2017-03-03 20:09:08 +00:00
|
|
|
workspace
|
2016-11-25 23:09:17 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const activeRequestId = activeRequest ? activeRequest._id : 'n/a';
|
|
|
|
|
2017-02-01 03:01:27 +00:00
|
|
|
return children.map(child => {
|
|
|
|
if (child.hidden) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-07-31 21:14:16 +00:00
|
|
|
if (child.doc.type === models.request.type) {
|
2016-11-25 23:09:17 +00:00
|
|
|
return (
|
|
|
|
<SidebarRequestRow
|
|
|
|
key={child.doc._id}
|
2017-06-13 20:45:15 +00:00
|
|
|
moveDoc={moveDoc}
|
2016-11-25 23:09:17 +00:00
|
|
|
handleActivateRequest={handleActivateRequest}
|
2016-11-28 07:12:17 +00:00
|
|
|
handleDuplicateRequest={handleDuplicateRequest}
|
|
|
|
handleGenerateCode={handleGenerateCode}
|
2017-06-29 18:27:29 +00:00
|
|
|
handleCopyAsCurl={handleCopyAsCurl}
|
2016-11-25 23:09:17 +00:00
|
|
|
requestCreate={handleCreateRequest}
|
|
|
|
isActive={child.doc._id === activeRequestId}
|
|
|
|
request={child.doc}
|
|
|
|
workspace={workspace}
|
|
|
|
/>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2016-11-25 23:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We have a RequestGroup!
|
|
|
|
|
|
|
|
const requestGroup = child.doc;
|
|
|
|
|
|
|
|
function hasActiveChild (children) {
|
|
|
|
for (const c of children) {
|
2016-11-25 23:21:07 +00:00
|
|
|
if (hasActiveChild(c.children || [])) {
|
|
|
|
return true;
|
2016-11-25 23:09:17 +00:00
|
|
|
} else if (c.doc._id === activeRequestId) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Didn't find anything, so return
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const isActive = hasActiveChild(child.children);
|
2017-02-01 03:01:27 +00:00
|
|
|
const children = this._renderChildren(child.children);
|
2016-11-25 23:09:17 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SidebarRequestGroupRow
|
|
|
|
handleActivateRequest={handleActivateRequest}
|
|
|
|
key={requestGroup._id}
|
|
|
|
isActive={isActive}
|
2017-06-13 20:45:15 +00:00
|
|
|
moveDoc={moveDoc}
|
2016-11-25 23:09:17 +00:00
|
|
|
handleSetRequestGroupCollapsed={handleSetRequestGroupCollapsed}
|
2016-11-28 07:12:17 +00:00
|
|
|
handleDuplicateRequestGroup={handleDuplicateRequestGroup}
|
2016-11-25 23:09:17 +00:00
|
|
|
isCollapsed={child.collapsed}
|
|
|
|
handleCreateRequest={handleCreateRequest}
|
|
|
|
handleCreateRequestGroup={handleCreateRequestGroup}
|
|
|
|
numChildren={child.children.length}
|
|
|
|
workspace={workspace}
|
|
|
|
requestGroup={requestGroup}
|
|
|
|
children={children}
|
|
|
|
/>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
|
|
|
});
|
2016-11-25 23:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2017-03-08 05:52:17 +00:00
|
|
|
const {childObjects} = this.props;
|
2016-11-25 23:09:17 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ul className="sidebar__list sidebar__list-root">
|
2017-03-08 05:52:17 +00:00
|
|
|
{this._renderChildren(childObjects)}
|
2016-11-25 23:09:17 +00:00
|
|
|
</ul>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2016-11-25 23:09:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SidebarChildren.propTypes = {
|
|
|
|
// Required
|
|
|
|
handleActivateRequest: PropTypes.func.isRequired,
|
|
|
|
handleCreateRequest: PropTypes.func.isRequired,
|
|
|
|
handleCreateRequestGroup: PropTypes.func.isRequired,
|
|
|
|
handleSetRequestGroupCollapsed: PropTypes.func.isRequired,
|
2016-11-27 21:42:38 +00:00
|
|
|
handleDuplicateRequest: PropTypes.func.isRequired,
|
2016-11-28 07:12:17 +00:00
|
|
|
handleDuplicateRequestGroup: PropTypes.func.isRequired,
|
|
|
|
handleGenerateCode: PropTypes.func.isRequired,
|
2017-06-29 18:27:29 +00:00
|
|
|
handleCopyAsCurl: PropTypes.func.isRequired,
|
2017-06-13 20:45:15 +00:00
|
|
|
moveDoc: PropTypes.func.isRequired,
|
2017-03-08 05:52:17 +00:00
|
|
|
childObjects: PropTypes.arrayOf(PropTypes.object).isRequired,
|
2016-11-25 23:09:17 +00:00
|
|
|
workspace: PropTypes.object.isRequired,
|
|
|
|
|
|
|
|
// Optional
|
2017-03-03 20:09:08 +00:00
|
|
|
activeRequest: PropTypes.object
|
2016-11-25 23:09:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default SidebarChildren;
|