2016-11-16 17:18:39 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-11-28 20:16:07 +00:00
|
|
|
import classnames from 'classnames';
|
2016-11-16 17:18:39 +00:00
|
|
|
import {ipcRenderer, shell} from 'electron';
|
2016-11-29 01:47:04 +00:00
|
|
|
import {Dropdown, DropdownDivider, DropdownButton, DropdownItem, DropdownHint, DropdownRight} from '../base/dropdown';
|
2016-11-16 17:18:39 +00:00
|
|
|
import PromptModal from '../modals/PromptModal';
|
2016-11-28 20:16:07 +00:00
|
|
|
import SettingsModal, {TAB_INDEX_EXPORT} from '../modals/SettingsModal';
|
2016-11-16 17:18:39 +00:00
|
|
|
import * as models from '../../../models';
|
|
|
|
import {getAppVersion} from '../../../common/constants';
|
|
|
|
import {showModal} from '../modals/index';
|
2016-11-23 19:33:24 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2016-11-23 20:10:53 +00:00
|
|
|
import Link from '../base/Link';
|
2016-11-28 20:16:07 +00:00
|
|
|
import WorkspaceSettingsModal from '../modals/WorkspaceSettingsModal';
|
2016-12-21 23:37:48 +00:00
|
|
|
import WorkspaceShareSettingsModal from '../modals/WorkspaceShareSettingsModal';
|
2016-12-23 19:31:38 +00:00
|
|
|
import * as session from '../../../sync/session';
|
|
|
|
import PromptButton from '../base/PromptButton';
|
|
|
|
import LoginModal from '../modals/LoginModal';
|
2016-11-16 17:18:39 +00:00
|
|
|
|
|
|
|
class WorkspaceDropdown extends Component {
|
2016-12-23 19:31:38 +00:00
|
|
|
state = {
|
|
|
|
loggedIn: false
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleDropdownOpen = () => {
|
|
|
|
if (this.state.loggedIn !== session.isLoggedIn()) {
|
|
|
|
this.setState({loggedIn: session.isLoggedIn()});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleShowLogin = () => {
|
|
|
|
showModal(LoginModal);
|
|
|
|
};
|
|
|
|
|
2016-11-28 20:16:07 +00:00
|
|
|
_handleShowExport = () => showModal(SettingsModal, TAB_INDEX_EXPORT);
|
|
|
|
_handleShowSettings = () => showModal(SettingsModal);
|
|
|
|
_handleShowWorkspaceSettings = () => {
|
|
|
|
showModal(WorkspaceSettingsModal, {
|
|
|
|
workspace: this.props.activeWorkspace,
|
2016-11-16 17:18:39 +00:00
|
|
|
});
|
2016-11-28 20:16:07 +00:00
|
|
|
};
|
2016-12-23 19:31:38 +00:00
|
|
|
// _handleShowShareSettings = () => {
|
|
|
|
// showModal(WorkspaceShareSettingsModal, {
|
|
|
|
// workspace: this.props.activeWorkspace,
|
|
|
|
// });
|
|
|
|
// };
|
2016-11-16 17:18:39 +00:00
|
|
|
|
2016-11-28 20:16:07 +00:00
|
|
|
_handleSwitchWorkspace = workspaceId => {
|
|
|
|
this.props.handleSetActiveWorkspace(workspaceId);
|
|
|
|
trackEvent('Workspace', 'Switch');
|
|
|
|
};
|
2016-11-16 17:18:39 +00:00
|
|
|
|
2016-11-28 20:16:07 +00:00
|
|
|
_handleWorkspaceCreate = async noTrack => {
|
2016-11-16 17:18:39 +00:00
|
|
|
const name = await showModal(PromptModal, {
|
|
|
|
headerName: 'Create New Workspace',
|
|
|
|
defaultValue: 'My Workspace',
|
|
|
|
submitName: 'Create',
|
|
|
|
selectText: true
|
|
|
|
});
|
|
|
|
|
|
|
|
const workspace = await models.workspace.create({name});
|
|
|
|
this.props.handleSetActiveWorkspace(workspace._id);
|
|
|
|
|
2016-11-28 20:16:07 +00:00
|
|
|
if (!noTrack) {
|
|
|
|
trackEvent('Workspace', 'Create');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
className,
|
|
|
|
workspaces,
|
|
|
|
activeWorkspace,
|
|
|
|
isLoading,
|
|
|
|
...other
|
|
|
|
} = this.props;
|
|
|
|
|
2016-11-28 20:16:07 +00:00
|
|
|
const nonActiveWorkspaces = workspaces.filter(w => w._id !== activeWorkspace._id);
|
|
|
|
|
2016-12-23 19:31:38 +00:00
|
|
|
const classes = classnames(className, 'wide', 'workspace-dropdown');
|
2016-11-16 17:18:39 +00:00
|
|
|
return (
|
2016-12-23 19:31:38 +00:00
|
|
|
<Dropdown className={classes} onOpen={this._handleDropdownOpen} {...other}>
|
2016-11-16 17:18:39 +00:00
|
|
|
<DropdownButton className="btn wide">
|
|
|
|
<h1 className="no-pad text-left">
|
|
|
|
<div className="pull-right">
|
2016-11-28 20:16:07 +00:00
|
|
|
{isLoading ? <i className="fa fa-refresh fa-spin txt-lg"/> : null}
|
|
|
|
{" "}
|
|
|
|
<i className="fa fa-caret-down"/>
|
2016-11-16 17:18:39 +00:00
|
|
|
</div>
|
|
|
|
{activeWorkspace.name}
|
|
|
|
</h1>
|
|
|
|
</DropdownButton>
|
2016-12-21 23:37:48 +00:00
|
|
|
<DropdownDivider>{activeWorkspace.name}</DropdownDivider>
|
2016-11-28 20:16:07 +00:00
|
|
|
<DropdownItem onClick={this._handleShowWorkspaceSettings}>
|
2016-11-29 21:28:22 +00:00
|
|
|
<i className="fa fa-wrench"/> Workspace Settings
|
2016-11-28 20:58:41 +00:00
|
|
|
<DropdownHint char="⇧,"/>
|
2016-11-16 17:18:39 +00:00
|
|
|
</DropdownItem>
|
2016-12-21 23:37:48 +00:00
|
|
|
{/*<DropdownItem onClick={this._handleShowShareSettings}>*/}
|
2016-12-23 19:31:38 +00:00
|
|
|
{/*<i className="fa fa-user"/> Share <strong>{activeWorkspace.name}</strong>*/}
|
2016-12-21 23:37:48 +00:00
|
|
|
{/*</DropdownItem>*/}
|
2016-11-16 17:18:39 +00:00
|
|
|
|
2016-12-21 23:37:48 +00:00
|
|
|
<DropdownDivider>Switch Workspace</DropdownDivider>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
2016-11-28 20:16:07 +00:00
|
|
|
{nonActiveWorkspaces.map(w => (
|
|
|
|
<DropdownItem key={w._id} onClick={this._handleSwitchWorkspace} value={w._id}>
|
2016-11-28 20:58:41 +00:00
|
|
|
<i className="fa fa-random"/> To <strong>{w.name}</strong>
|
2016-11-16 17:18:39 +00:00
|
|
|
</DropdownItem>
|
|
|
|
))}
|
2016-11-28 20:16:07 +00:00
|
|
|
<DropdownItem onClick={this._handleWorkspaceCreate}>
|
2016-11-28 20:58:41 +00:00
|
|
|
<i className="fa fa-empty"/> New Workspace
|
2016-11-16 17:18:39 +00:00
|
|
|
</DropdownItem>
|
|
|
|
|
2016-12-21 23:37:48 +00:00
|
|
|
<DropdownDivider>Insomnia Version {getAppVersion()}</DropdownDivider>
|
2016-11-16 17:18:39 +00:00
|
|
|
|
2016-11-28 20:16:07 +00:00
|
|
|
<DropdownItem onClick={this._handleShowSettings}>
|
2016-12-21 23:37:48 +00:00
|
|
|
<i className="fa fa-cog"/> App Settings
|
2016-11-29 01:47:04 +00:00
|
|
|
<DropdownHint char=","/>
|
2016-11-16 17:18:39 +00:00
|
|
|
</DropdownItem>
|
2016-11-28 20:58:41 +00:00
|
|
|
<DropdownItem onClick={this._handleShowExport}>
|
|
|
|
<i className="fa fa-share"/> Import/Export
|
|
|
|
</DropdownItem>
|
2016-12-23 19:31:38 +00:00
|
|
|
{!this.state.loggedIn ? [
|
2016-12-24 22:24:10 +00:00
|
|
|
<DropdownItem key="login" onClick={this._handleShowLogin}>
|
2016-12-23 19:31:38 +00:00
|
|
|
<i className="fa fa-sign-in"/> Log In
|
|
|
|
</DropdownItem>,
|
|
|
|
<DropdownItem key="invite"
|
|
|
|
buttonClass={Link}
|
|
|
|
href="https://insomnia.rest/pricing/"
|
|
|
|
button={true}>
|
|
|
|
<i className="fa fa-users"/> Upgrade to Plus
|
|
|
|
</DropdownItem>,
|
|
|
|
] : [
|
|
|
|
<DropdownItem key="manage"
|
|
|
|
buttonClass={Link}
|
|
|
|
href="https://insomnia.rest/app/"
|
|
|
|
button={true}>
|
|
|
|
<i className="fa fa-user"/> Manage Account
|
|
|
|
</DropdownItem>,
|
|
|
|
<DropdownItem key="logout"
|
|
|
|
buttonClass={PromptButton}
|
|
|
|
onClick={session.logout}
|
|
|
|
addIcon={true}>
|
|
|
|
<i className="fa fa-sign-out"/> Log Out
|
|
|
|
</DropdownItem>,
|
|
|
|
]}
|
2016-11-16 17:18:39 +00:00
|
|
|
</Dropdown>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkspaceDropdown.propTypes = {
|
|
|
|
isLoading: PropTypes.bool.isRequired,
|
|
|
|
handleImportFile: PropTypes.func.isRequired,
|
|
|
|
handleExportFile: PropTypes.func.isRequired,
|
|
|
|
handleSetActiveWorkspace: PropTypes.func.isRequired,
|
|
|
|
workspaces: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
activeWorkspace: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default WorkspaceDropdown;
|