insomnia/app/ui/components/dropdowns/RequestGroupActionsDropdown.js

102 lines
3.2 KiB
JavaScript
Raw Normal View History

import React, {Component, PropTypes} from 'react';
import PromptButton from '../base/PromptButton';
import {Dropdown, DropdownButton, DropdownItem, DropdownDivider, DropdownHint} from '../base/dropdown';
import EnvironmentEditModal from '../modals/EnvironmentEditModal';
import PromptModal from '../modals/PromptModal';
import * as models from '../../../models';
import {showModal} from '../modals';
import {trackEvent} from '../../../analytics/index';
2016-04-09 21:41:27 +00:00
class RequestGroupActionsDropdown extends Component {
async _promptUpdateName () {
2016-07-14 22:48:56 +00:00
const {requestGroup} = this.props;
const name = await showModal(PromptModal, {
2016-07-21 19:15:35 +00:00
headerName: 'Rename Folder',
2016-07-14 22:48:56 +00:00
defaultValue: requestGroup.name
});
2016-11-10 01:15:27 +00:00
models.requestGroup.update(requestGroup, {name});
trackEvent('Folder', 'Rename', 'Folder Action');
2016-07-14 22:48:56 +00:00
}
async _requestCreate () {
const name = await showModal(PromptModal, {
headerName: 'Create New Request',
defaultValue: 'My Request',
selectText: true
});
const {workspace, requestGroup} = this.props;
const parentId = requestGroup._id;
2016-11-10 01:15:27 +00:00
const request = await models.request.create({parentId, 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.activateRequest(workspace, request);
trackEvent('Request', 'Create', 'Folder Action');
}
2016-09-08 06:54:35 +00:00
_requestGroupDuplicate () {
const {requestGroup} = this.props;
2016-11-10 01:15:27 +00:00
models.requestGroup.duplicate(requestGroup);
trackEvent('Folder', 'Duplicate', 'Folder Action');
2016-09-08 06:54:35 +00:00
}
async _requestGroupCreate () {
const name = await showModal(PromptModal, {
headerName: 'Create New Folder',
defaultValue: 'My Folder',
selectText: true
});
const {requestGroup} = this.props;
models.requestGroup.create({parentId: requestGroup._id, name});
trackEvent('Folder', 'Create', 'Folder Action');
}
2016-04-09 21:41:27 +00:00
render () {
2016-07-14 22:48:56 +00:00
const {requestGroup, ...other} = this.props;
2016-04-09 21:41:27 +00:00
return (
<Dropdown {...other}>
2016-11-11 22:01:21 +00:00
<DropdownButton>
2016-04-09 21:41:27 +00:00
<i className="fa fa-caret-down"></i>
2016-11-11 22:01:21 +00:00
</DropdownButton>
<DropdownItem onClick={e => this._requestCreate()}>
<i className="fa fa-plus-circle"></i> New Request
<DropdownHint char="N"></DropdownHint>
</DropdownItem>
<DropdownItem onClick={e => this._requestGroupCreate()}>
<i className="fa fa-folder"></i> New Folder
</DropdownItem>
2016-11-11 22:01:21 +00:00
<DropdownDivider />
<DropdownItem onClick={e => this._requestGroupDuplicate()}>
<i className="fa fa-copy"></i> Duplicate
</DropdownItem>
<DropdownItem onClick={e => this._promptUpdateName()}>
<i className="fa fa-edit"></i> Rename
</DropdownItem>
<DropdownItem
onClick={e => showModal(EnvironmentEditModal, requestGroup)}>
<i className="fa fa-code"></i> Environment
</DropdownItem>
<DropdownItem buttonClass={PromptButton} addIcon={true} onClick={e => {
models.requestGroup.remove(requestGroup);
trackEvent('Folder', 'Delete', 'Folder Action');
}}>
2016-11-11 22:01:21 +00:00
<i className="fa fa-trash-o"></i> Delete
</DropdownItem>
2016-04-09 21:41:27 +00:00
</Dropdown>
)
}
}
RequestGroupActionsDropdown.propTypes = {
workspace: PropTypes.object.isRequired,
// Optional
2016-04-09 21:41:27 +00:00
requestGroup: PropTypes.object
};
export default RequestGroupActionsDropdown;