insomnia/app/ui/components/sidebar/Sidebar.js

152 lines
4.9 KiB
JavaScript
Raw Normal View History

2016-11-26 08:29:16 +00:00
import React, {PureComponent, PropTypes} from 'react';
import classnames from 'classnames';
import EnvironmentsDropdown from '../dropdowns/EnvironmentsDropdown';
import SidebarFilter from './SidebarFilter';
2016-11-25 23:09:17 +00:00
import SidebarChildren from './SidebarChildren';
2016-11-11 23:06:24 +00:00
import SyncButton from '../dropdowns/SyncDropdown';
import WorkspaceDropdown from '../dropdowns/WorkspaceDropdown';
2016-11-25 23:09:17 +00:00
import {SIDEBAR_SKINNY_REMS, COLLAPSE_SIDEBAR_REMS} from '../../../common/constants';
2016-03-18 00:36:00 +00:00
2016-11-26 08:29:16 +00:00
class Sidebar extends PureComponent {
_handleChangeEnvironment = id => {
const {handleSetActiveEnvironment} = this.props;
handleSetActiveEnvironment(id);
2016-11-25 23:09:17 +00:00
};
2016-04-05 05:35:21 +00:00
2016-11-25 23:09:17 +00:00
_handleCreateRequestInWorkspace = () => {
const {workspace, handleCreateRequest} = this.props;
handleCreateRequest(workspace._id);
};
2016-04-05 05:35:21 +00:00
2016-11-25 23:09:17 +00:00
_handleCreateRequestGroupInWorkspace = () => {
const {workspace, handleCreateRequestGroup} = this.props;
handleCreateRequestGroup(workspace._id);
};
2016-03-24 10:20:11 +00:00
2016-03-23 05:26:27 +00:00
render () {
const {
showCookiesModal,
filter,
children,
hidden,
width,
workspace,
workspaces,
environments,
activeEnvironment,
handleSetActiveWorkspace,
handleImportFile,
handleExportFile,
handleChangeFilter,
isLoading,
2016-11-25 23:09:17 +00:00
handleCreateRequest,
handleDuplicateRequest,
2016-11-28 07:12:17 +00:00
handleDuplicateRequestGroup,
handleGenerateCode,
2016-11-25 23:09:17 +00:00
handleCreateRequestGroup,
handleSetRequestGroupCollapsed,
moveRequest,
moveRequestGroup,
handleActivateRequest,
activeRequest,
} = this.props;
2016-03-23 05:26:27 +00:00
return (
<aside className={classnames('sidebar', {
'sidebar--hidden': hidden,
'sidebar--skinny': width < SIDEBAR_SKINNY_REMS,
'sidebar--collapsed': width < COLLAPSE_SIDEBAR_REMS
})}>
<WorkspaceDropdown
className="sidebar__header"
activeWorkspace={workspace}
workspaces={workspaces}
handleExportFile={handleExportFile}
handleImportFile={handleImportFile}
handleSetActiveWorkspace={handleSetActiveWorkspace}
isLoading={isLoading}
/>
<div className="sidebar__menu">
<EnvironmentsDropdown
2016-11-25 23:09:17 +00:00
handleChangeEnvironment={this._handleChangeEnvironment}
activeEnvironment={activeEnvironment}
environments={environments}
workspace={workspace}
/>
2016-11-25 23:09:17 +00:00
<button className="btn btn--super-compact" onClick={showCookiesModal}>
<div className="sidebar__menu__thing">
<span>Cookies</span>
</div>
</button>
</div>
<SidebarFilter
2016-11-25 23:09:17 +00:00
onChange={handleChangeFilter}
requestCreate={this._handleCreateRequestInWorkspace}
requestGroupCreate={this._handleCreateRequestGroupInWorkspace}
filter={filter || ''}
/>
2016-11-25 23:09:17 +00:00
<SidebarChildren
children={children}
handleActivateRequest={handleActivateRequest}
handleCreateRequest={handleCreateRequest}
handleCreateRequestGroup={handleCreateRequestGroup}
handleSetRequestGroupCollapsed={handleSetRequestGroupCollapsed}
handleDuplicateRequest={handleDuplicateRequest}
2016-11-28 07:12:17 +00:00
handleDuplicateRequestGroup={handleDuplicateRequestGroup}
handleGenerateCode={handleGenerateCode}
2016-11-25 23:09:17 +00:00
moveRequest={moveRequest}
moveRequestGroup={moveRequestGroup}
workspace={workspace}
activeRequest={activeRequest}
/>
<SyncButton
className="sidebar__footer"
key={workspace._id}
workspace={workspace}
/>
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 = {
// Functions
handleActivateRequest: PropTypes.func.isRequired,
handleSetRequestGroupCollapsed: PropTypes.func.isRequired,
handleChangeFilter: PropTypes.func.isRequired,
handleImportFile: PropTypes.func.isRequired,
handleExportFile: PropTypes.func.isRequired,
handleSetActiveWorkspace: PropTypes.func.isRequired,
handleSetActiveEnvironment: PropTypes.func.isRequired,
moveRequest: PropTypes.func.isRequired,
moveRequestGroup: PropTypes.func.isRequired,
handleCreateRequest: PropTypes.func.isRequired,
handleCreateRequestGroup: PropTypes.func.isRequired,
handleDuplicateRequest: PropTypes.func.isRequired,
2016-11-28 07:12:17 +00:00
handleDuplicateRequestGroup: PropTypes.func.isRequired,
handleGenerateCode: PropTypes.func.isRequired,
showEnvironmentsModal: PropTypes.func.isRequired,
showCookiesModal: PropTypes.func.isRequired,
// Other
hidden: PropTypes.bool.isRequired,
width: PropTypes.number.isRequired,
isLoading: PropTypes.bool.isRequired,
workspace: PropTypes.object.isRequired,
2016-11-26 08:29:16 +00:00
children: PropTypes.arrayOf(PropTypes.object).isRequired,
workspaces: PropTypes.arrayOf(PropTypes.object).isRequired,
environments: PropTypes.arrayOf(PropTypes.object).isRequired,
// Optional
filter: PropTypes.string,
activeRequest: PropTypes.object,
activeEnvironment: PropTypes.object,
2016-03-20 04:00:40 +00:00
};
2016-03-18 00:36:00 +00:00
export default Sidebar;