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

157 lines
5.1 KiB
JavaScript
Raw Normal View History

2017-08-10 01:56:27 +00:00
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import autobind from 'autobind-decorator';
import classnames from 'classnames';
import EnvironmentsDropdown from '../dropdowns/environments-dropdown';
import SidebarFilter from './sidebar-filter';
import SidebarChildren from './sidebar-children';
import SyncButton from '../dropdowns/sync-dropdown';
import WorkspaceDropdown from '../dropdowns/workspace-dropdown';
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
@autobind
2016-11-26 08:29:16 +00:00
class Sidebar extends PureComponent {
_handleChangeEnvironment (id) {
const {handleSetActiveEnvironment} = this.props;
handleSetActiveEnvironment(id);
}
2016-04-05 05:35:21 +00:00
_handleCreateRequestInWorkspace () {
2016-11-25 23:09:17 +00:00
const {workspace, handleCreateRequest} = this.props;
handleCreateRequest(workspace._id);
}
2016-04-05 05:35:21 +00:00
_handleCreateRequestGroupInWorkspace () {
2016-11-25 23:09:17 +00:00
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,
childObjects,
hidden,
width,
workspace,
workspaces,
2017-07-27 22:59:07 +00:00
unseenWorkspaces,
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,
handleCopyAsCurl,
2016-11-25 23:09:17 +00:00
handleCreateRequestGroup,
handleSetRequestGroupCollapsed,
2017-06-13 20:45:15 +00:00
moveDoc,
2016-11-25 23:09:17 +00:00
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}
2017-07-27 22:59:07 +00:00
unseenWorkspaces={unseenWorkspaces}
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
childObjects={childObjects}
2016-11-25 23:09:17 +00:00
handleActivateRequest={handleActivateRequest}
handleCreateRequest={handleCreateRequest}
handleCreateRequestGroup={handleCreateRequestGroup}
handleSetRequestGroupCollapsed={handleSetRequestGroupCollapsed}
handleDuplicateRequest={handleDuplicateRequest}
2016-11-28 07:12:17 +00:00
handleDuplicateRequestGroup={handleDuplicateRequestGroup}
handleGenerateCode={handleGenerateCode}
handleCopyAsCurl={handleCopyAsCurl}
2017-06-13 20:45:15 +00:00
moveDoc={moveDoc}
2016-11-25 23:09:17 +00:00
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,
2017-06-13 20:45:15 +00:00
moveDoc: 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,
handleCopyAsCurl: 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,
childObjects: PropTypes.arrayOf(PropTypes.object).isRequired,
workspaces: PropTypes.arrayOf(PropTypes.object).isRequired,
2017-07-27 22:59:07 +00:00
unseenWorkspaces: 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;