insomnia/app/ui/containers/WorkspaceDropdown.js

193 lines
5.8 KiB
JavaScript
Raw Normal View History

import React, {Component, PropTypes} from 'react';
import {ipcRenderer} from 'electron';
import {bindActionCreators} from 'redux';
2016-04-04 07:15:30 +00:00
import {connect} from 'react-redux'
2016-08-25 17:06:01 +00:00
import {shell} from 'electron';
2016-04-23 06:53:22 +00:00
2016-09-09 18:28:57 +00:00
import PromptButton from '../components/base/PromptButton';
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';
import PromptModal from '../components/modals/PromptModal';
import AlertModal from '../components/modals/AlertModal';
import SettingsModal from '../components/modals/SettingsModal';
import ChangelogModal from '../components/modals/ChangelogModal';
import * as GlobalActions from '../redux/modules/global';
2016-11-10 01:15:27 +00:00
import * as models from '../../backend/models';
import {getAppVersion} from '../../backend/appInfo';
import {showModal} from '../components/modals/index';
2016-04-04 07:15:30 +00:00
class WorkspaceDropdown extends Component {
async _promptUpdateName () {
2016-07-14 22:48:56 +00:00
const workspace = this._getActiveWorkspace(this.props);
const name = await showModal(PromptModal, {
2016-07-14 22:48:56 +00:00
headerName: 'Rename Workspace',
defaultValue: workspace.name
});
2016-11-10 01:15:27 +00:00
models.workspace.update(workspace, {name});
2016-07-14 22:48:56 +00:00
}
async _workspaceCreate () {
const name = await showModal(PromptModal, {
headerName: 'Create New Workspace',
defaultValue: 'My Workspace',
submitName: 'Create',
selectText: true
});
2016-11-10 01:15:27 +00:00
const workspace = await models.workspace.create({name});
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
this.props.actions.global.activateWorkspace(workspace);
}
async _workspaceRemove () {
2016-11-10 01:15:27 +00:00
const count = await models.workspace.count();
if (count <= 1) {
showModal(AlertModal, {
title: 'Delete Unsuccessful',
message: 'You cannot delete your last workspace.'
});
} else {
const workspace = this._getActiveWorkspace(this.props);
2016-11-10 01:15:27 +00:00
models.workspace.remove(workspace);
}
}
2016-07-14 22:48:56 +00:00
_getActiveWorkspace (props) {
// TODO: Factor this out into a selector
2016-07-14 22:48:56 +00:00
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
const {entities, global} = props || this.props;
let workspace = entities.workspaces[global.activeWorkspaceId];
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 () {
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
const {className, actions, global, entities, ...other} = this.props;
2016-07-14 22:48:56 +00:00
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 (
<Dropdown key={workspace._id}
className={className + ' wide workspace-dropdown'}
{...other}>
2016-05-01 19:56:30 +00:00
<button className="btn wide">
<h1 className="no-pad text-left">
<div className="pull-right">
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
{global.loading ?
<i className="fa fa-refresh fa-spin txt-lg"></i> : ''}&nbsp;
<i className="fa fa-caret-down"></i>
2016-04-04 07:15:30 +00:00
</div>
2016-05-01 19:56:30 +00:00
{workspace.name}
</h1>
2016-04-04 07:15:30 +00:00
</button>
<ul>
<DropdownDivider name="Current Workspace"/>
2016-04-23 06:53:22 +00:00
<li>
2016-07-14 22:48:56 +00:00
<button onClick={e => this._promptUpdateName()}>
<i className="fa fa-pencil-square-o"></i> Rename
{" "}
<strong>{workspace.name}</strong>
2016-04-23 06:53:22 +00:00
</button>
</li>
<li>
2016-09-09 18:28:57 +00:00
<PromptButton onClick={e => this._workspaceRemove()} addIcon={true}>
<i className="fa fa-trash-o"></i> Delete
{" "}
<strong>{workspace.name}</strong>
2016-09-09 18:28:57 +00:00
</PromptButton>
2016-04-23 06:53:22 +00:00
</li>
<DropdownDivider name="Workspaces"/>
{allWorkspaces.map(w => {
return w._id === workspace._id ? null : (
<li key={w._id}>
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
<button onClick={() => actions.global.activateWorkspace(w)}>
<i className="fa fa-random"></i> Switch to
{" "}
<strong>{w.name}</strong>
</button>
</li>
)
})}
2016-04-23 06:53:22 +00:00
<li>
<button onClick={e => this._workspaceCreate()}>
<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>
<button onClick={e => showModal(SettingsModal, 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>
<button onClick={e => showModal(SettingsModal, 2)}>
<i className="fa fa-refresh"></i> Cloud Sync
</button>
</li>
<li>
<button onClick={e => showModal(SettingsModal)}>
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>
<button onClick={e => showModal(ChangelogModal)}>
2016-07-20 00:34:47 +00:00
<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 = {
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
global: PropTypes.shape({
loading: PropTypes.bool.isRequired,
activeWorkspaceId: PropTypes.string.isRequired
}),
entities: PropTypes.shape({
workspaces: PropTypes.object.isRequired
}).isRequired,
2016-04-04 07:15:30 +00:00
actions: PropTypes.shape({
2016-07-07 20:10:55 +00:00
global: PropTypes.shape({
importFile: PropTypes.func.isRequired,
exportFile: PropTypes.func.isRequired,
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
activateWorkspace: PropTypes.func.isRequired,
})
2016-04-04 07:15:30 +00:00
})
};
function mapStateToProps (state) {
return {
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
global: state.global,
entities: state.entities,
Sync Proof of Concept (#33) * Maybe working POC * Change to use remote url * Other URL too * Some logic * Got the push part working * Made some updates * Fix * Update * Add status code check * Stuff * Implemented new sync api * A bit more robust * Debounce changes * Change timeout * Some fixes * Remove .less * Better error handling * Fix base url * Support for created vs updated docs * Try silent * Silence removal too * Small fix after merge * Fix test * Stuff * Implement key generation algorithm * Tidy * stuff * A bunch of stuff for the new API * Integrated the session stuff * Stuff * Just started on encryption * Lots of updates to encryption * Finished createResourceGroup function * Full encryption/decryption working (I think) * Encrypt localstorage with sessionID * Some more * Some extra checks * Now uses separate DB. Still needs to be simplified a LOT * Fix deletion bug * Fixed unicode bug with encryption * Simplified and working * A bunch of polish * Some stuff * Removed some workspace meta properties * Migrated a few more meta properties * Small changes * Fix body scrolling and url cursor jumping * Removed duplication of webpack port * Remove workspaces reduces * Some small fixes * Added sync modal and opt-in setting * Good start to sync flow * Refactored modal footer css * Update sync status * Sync logger * A bit better logging * Fixed a bunch of sync-related bugs * Fixed signup form button * Gravatar component * Split sync modal into tabs * Tidying * Some more error handling * start sending 'user agent * Login/signup error handling * Use real UUIDs * Fixed tests * Remove unused function * Some extra checks * Moved cloud sync setting to about page * Some small changes * Some things
2016-10-21 17:20:36 +00:00
actions: state.actions
2016-04-04 07:15:30 +00:00
};
}
function mapDispatchToProps (dispatch) {
return {
actions: {
2016-07-07 20:10:55 +00:00
global: bindActionCreators(GlobalActions, dispatch)
}
2016-04-04 07:15:30 +00:00
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(WorkspaceDropdown);