2016-07-16 02:06:10 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-07-21 21:34:38 +00:00
|
|
|
import {ipcRenderer} from 'electron';
|
2016-07-16 02:06:10 +00:00
|
|
|
import {bindActionCreators} from 'redux';
|
2016-04-04 07:15:30 +00:00
|
|
|
import {connect} from 'react-redux'
|
2016-04-23 06:53:22 +00:00
|
|
|
|
2016-07-16 02:06:10 +00:00
|
|
|
import Dropdown from '../components/base/Dropdown';
|
|
|
|
import DropdownDivider from '../components/base/DropdownDivider';
|
2016-07-21 21:55:03 +00:00
|
|
|
import DropdownHint from '../components/base/DropdownHint';
|
2016-07-22 22:27:04 +00:00
|
|
|
import PromptModal from '../components/modals/PromptModal';
|
|
|
|
import AlertModal from '../components/modals/AlertModal';
|
|
|
|
import SettingsModal from '../components/modals/SettingsModal';
|
|
|
|
import ChangelogModal from '../components/modals/ChangelogModal';
|
2016-07-16 02:06:10 +00:00
|
|
|
import * as WorkspaceActions from '../redux/modules/workspaces';
|
|
|
|
import * as GlobalActions from '../redux/modules/global';
|
|
|
|
import * as db from '../database';
|
2016-07-21 22:26:51 +00:00
|
|
|
import {getAppVersion} from '../lib/appInfo';
|
2016-04-04 07:15:30 +00:00
|
|
|
|
|
|
|
class WorkspaceDropdown extends Component {
|
2016-07-14 22:48:56 +00:00
|
|
|
_promptUpdateName () {
|
|
|
|
const workspace = this._getActiveWorkspace(this.props);
|
|
|
|
|
|
|
|
PromptModal.show({
|
|
|
|
headerName: 'Rename Workspace',
|
|
|
|
defaultValue: workspace.name
|
|
|
|
}).then(name => {
|
|
|
|
db.workspaceUpdate(workspace, {name});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-04-26 07:29:24 +00:00
|
|
|
_workspaceCreate () {
|
2016-07-19 16:59:26 +00:00
|
|
|
PromptModal.show({
|
|
|
|
headerName: 'Create New Workspace',
|
|
|
|
defaultValue: 'New Workspace',
|
|
|
|
submitName: 'Create',
|
|
|
|
selectText: true
|
|
|
|
}).then(name => {
|
|
|
|
db.workspaceCreate({name}).then(workspace => {
|
|
|
|
this.props.actions.workspaces.activate(workspace);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_workspaceRemove () {
|
|
|
|
db.workspaceCount().then(count => {
|
|
|
|
if (count <= 1) {
|
|
|
|
AlertModal.show({
|
|
|
|
message: 'You cannot delete your last workspace'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const workspace = this._getActiveWorkspace(this.props);
|
|
|
|
db.workspaceRemove(workspace);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
_requestGroupCreate () {
|
|
|
|
PromptModal.show({
|
2016-07-21 19:15:35 +00:00
|
|
|
headerName: 'Create New Folder',
|
2016-07-25 22:27:29 +00:00
|
|
|
defaultValue: 'New Folder',
|
2016-07-19 16:59:26 +00:00
|
|
|
submitName: 'Create',
|
|
|
|
selectText: true
|
|
|
|
}).then(name => {
|
|
|
|
const workspace = this._getActiveWorkspace(this.props);
|
|
|
|
db.requestGroupCreate({name, parentId: workspace._id}).then(requestGroup => {
|
|
|
|
// Nothing yet
|
|
|
|
});
|
2016-04-26 07:29:24 +00:00
|
|
|
});
|
|
|
|
}
|
2016-04-17 01:52:10 +00:00
|
|
|
|
2016-07-19 16:59:26 +00:00
|
|
|
_requestCreate () {
|
|
|
|
const workspace = this._getActiveWorkspace(this.props);
|
|
|
|
db.requestCreateAndActivate(workspace, {parentId: workspace._id});
|
|
|
|
}
|
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
_getActiveWorkspace (props) {
|
2016-04-26 07:29:24 +00:00
|
|
|
// TODO: Factor this out into a selector
|
2016-07-14 22:48:56 +00:00
|
|
|
|
|
|
|
const {entities, workspaces} = props || this.props;
|
2016-04-26 07:29:24 +00:00
|
|
|
let workspace = entities.workspaces[workspaces.activeId];
|
|
|
|
if (!workspace) {
|
|
|
|
workspace = entities.workspaces[Object.keys(entities.workspaces)[0]];
|
|
|
|
}
|
2016-04-04 07:15:30 +00:00
|
|
|
|
2016-07-14 22:48:56 +00:00
|
|
|
return workspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {actions, loading, entities, ...other} = this.props;
|
|
|
|
|
|
|
|
const allWorkspaces = Object.keys(entities.workspaces).map(id => entities.workspaces[id]);
|
|
|
|
const workspace = this._getActiveWorkspace(this.props);
|
|
|
|
|
2016-04-04 07:15:30 +00:00
|
|
|
return (
|
2016-05-01 19:56:30 +00:00
|
|
|
<Dropdown right={true} {...other} className="wide">
|
|
|
|
<button className="btn wide">
|
|
|
|
<h1 className="no-pad text-left">
|
|
|
|
<div className="pull-right">
|
2016-04-04 07:15:30 +00:00
|
|
|
{loading ? <i className="fa fa-refresh fa-spin txt-lg"></i> : ''}
|
|
|
|
<i className="fa fa-caret-down txt-lg"></i>
|
|
|
|
</div>
|
2016-05-01 19:56:30 +00:00
|
|
|
{workspace.name}
|
|
|
|
</h1>
|
2016-04-04 07:15:30 +00:00
|
|
|
</button>
|
|
|
|
<ul>
|
2016-04-26 07:29:24 +00:00
|
|
|
|
|
|
|
<DropdownDivider name="Current Workspace"/>
|
|
|
|
|
2016-07-21 03:58:52 +00:00
|
|
|
<li>
|
|
|
|
<button
|
|
|
|
onClick={e => db.requestCreateAndActivate(workspace, {parentId: workspace._id})}>
|
|
|
|
<i className="fa fa-plus-circle"></i> New Request
|
2016-07-21 21:55:03 +00:00
|
|
|
<DropdownHint char="N"></DropdownHint>
|
2016-07-21 03:58:52 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
2016-07-19 16:59:26 +00:00
|
|
|
|
2016-04-17 01:52:10 +00:00
|
|
|
<li>
|
2016-07-19 16:59:26 +00:00
|
|
|
<button onClick={e => this._requestGroupCreate() }>
|
2016-07-21 19:15:35 +00:00
|
|
|
<i className="fa fa-folder"></i> New Folder
|
2016-04-17 01:52:10 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
2016-04-23 06:53:22 +00:00
|
|
|
<li>
|
2016-07-14 22:48:56 +00:00
|
|
|
<button onClick={e => this._promptUpdateName()}>
|
2016-04-26 07:29:24 +00:00
|
|
|
<i className="fa fa-empty"></i> Rename <strong>{workspace.name}</strong>
|
2016-04-23 06:53:22 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li>
|
2016-07-19 16:59:26 +00:00
|
|
|
<button onClick={e => this._workspaceRemove()}>
|
2016-04-26 07:29:24 +00:00
|
|
|
<i className="fa fa-empty"></i> Delete <strong>{workspace.name}</strong>
|
2016-04-23 06:53:22 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
2016-04-26 07:29:24 +00:00
|
|
|
|
|
|
|
<DropdownDivider name="Workspaces"/>
|
|
|
|
|
|
|
|
{allWorkspaces.map(w => {
|
|
|
|
return w._id === workspace._id ? null : (
|
|
|
|
<li key={w._id}>
|
|
|
|
<button onClick={() => actions.workspaces.activate(w)}>
|
|
|
|
<i className="fa fa-random"></i> Switch to <strong>{w.name}</strong>
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
})}
|
2016-04-23 06:53:22 +00:00
|
|
|
<li>
|
2016-04-26 07:29:24 +00:00
|
|
|
<button onClick={e => this._workspaceCreate()}>
|
2016-07-19 16:59:26 +00:00
|
|
|
<i className="fa fa-blank"></i> New Workspace
|
2016-04-23 06:53:22 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
|
2016-07-21 22:26:51 +00:00
|
|
|
<DropdownDivider name={`Insomnia Version ${getAppVersion()}`}/>
|
2016-04-23 06:53:22 +00:00
|
|
|
|
2016-07-19 16:15:03 +00:00
|
|
|
<li>
|
2016-07-21 16:33:35 +00:00
|
|
|
<button onClick={e => SettingsModal.show(1)}>
|
2016-07-19 16:15:03 +00:00
|
|
|
<i className="fa fa-share"></i> Import/Export
|
|
|
|
</button>
|
|
|
|
</li>
|
2016-05-07 17:29:24 +00:00
|
|
|
<li>
|
2016-07-15 00:26:04 +00:00
|
|
|
<button onClick={e => SettingsModal.show()}>
|
2016-05-07 17:29:24 +00:00
|
|
|
<i className="fa fa-cog"></i> Settings
|
2016-07-21 21:55:03 +00:00
|
|
|
<DropdownHint char=","></DropdownHint>
|
2016-05-07 17:29:24 +00:00
|
|
|
</button>
|
|
|
|
</li>
|
2016-07-14 22:48:56 +00:00
|
|
|
<li>
|
2016-07-20 00:34:47 +00:00
|
|
|
<button onClick={e => ChangelogModal.show()}>
|
|
|
|
<i className="fa fa-blank"></i> Changelog
|
|
|
|
</button>
|
2016-07-14 22:48:56 +00:00
|
|
|
</li>
|
2016-04-04 07:15:30 +00:00
|
|
|
</ul>
|
|
|
|
</Dropdown>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkspaceDropdown.propTypes = {
|
|
|
|
loading: PropTypes.bool.isRequired,
|
2016-04-26 07:29:24 +00:00
|
|
|
workspaces: PropTypes.shape({
|
|
|
|
activeId: PropTypes.string
|
|
|
|
}),
|
|
|
|
entities: PropTypes.shape({
|
|
|
|
workspaces: PropTypes.object.isRequired
|
|
|
|
}).isRequired,
|
2016-04-04 07:15:30 +00:00
|
|
|
actions: PropTypes.shape({
|
2016-04-26 07:29:24 +00:00
|
|
|
workspaces: PropTypes.shape({
|
|
|
|
activate: PropTypes.func.isRequired,
|
2016-07-07 20:10:55 +00:00
|
|
|
}),
|
|
|
|
global: PropTypes.shape({
|
2016-07-19 04:01:31 +00:00
|
|
|
importFile: PropTypes.func.isRequired,
|
|
|
|
exportFile: PropTypes.func.isRequired,
|
2016-04-26 07:29:24 +00:00
|
|
|
})
|
2016-04-04 07:15:30 +00:00
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
2016-04-26 07:29:24 +00:00
|
|
|
workspaces: state.workspaces,
|
|
|
|
entities: state.entities,
|
2016-04-04 07:15:30 +00:00
|
|
|
actions: state.actions,
|
2016-04-23 06:08:52 +00:00
|
|
|
loading: state.global.loading
|
2016-04-04 07:15:30 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
2016-04-26 07:29:24 +00:00
|
|
|
actions: {
|
2016-05-07 17:29:24 +00:00
|
|
|
workspaces: bindActionCreators(WorkspaceActions, dispatch),
|
2016-07-07 20:10:55 +00:00
|
|
|
global: bindActionCreators(GlobalActions, dispatch)
|
2016-04-26 07:29:24 +00:00
|
|
|
}
|
2016-04-04 07:15:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(WorkspaceDropdown);
|