2016-07-16 02:06:10 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
2016-11-16 17:18:39 +00:00
|
|
|
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';
|
2016-11-23 19:33:24 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2016-04-09 21:41:27 +00:00
|
|
|
|
|
|
|
class RequestGroupActionsDropdown extends Component {
|
2016-10-02 20:57:00 +00:00
|
|
|
async _promptUpdateName () {
|
2016-07-14 22:48:56 +00:00
|
|
|
const {requestGroup} = this.props;
|
|
|
|
|
2016-11-07 20:24:38 +00:00
|
|
|
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-10-02 20:57:00 +00:00
|
|
|
});
|
|
|
|
|
2016-11-10 01:15:27 +00:00
|
|
|
models.requestGroup.update(requestGroup, {name});
|
2016-11-23 19:33:24 +00:00
|
|
|
|
|
|
|
trackEvent('Folder', 'Rename', 'Folder Action');
|
2016-07-14 22:48:56 +00:00
|
|
|
}
|
2016-07-19 16:59:26 +00:00
|
|
|
|
2016-10-02 20:57:00 +00:00
|
|
|
async _requestCreate () {
|
2016-11-07 20:24:38 +00:00
|
|
|
const name = await showModal(PromptModal, {
|
2016-08-15 17:04:36 +00:00
|
|
|
headerName: 'Create New Request',
|
|
|
|
defaultValue: 'My Request',
|
|
|
|
selectText: true
|
|
|
|
});
|
2016-10-02 20:57:00 +00:00
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
const {workspace, requestGroup} = this.props;
|
2016-10-02 20:57:00 +00:00
|
|
|
const parentId = requestGroup._id;
|
2016-11-10 01:15:27 +00:00
|
|
|
const request = await models.request.create({parentId, name});
|
2016-10-21 17:20:36 +00:00
|
|
|
this.props.actions.global.activateRequest(workspace, request);
|
2016-11-23 19:33:24 +00:00
|
|
|
trackEvent('Request', 'Create', 'Folder Action');
|
2016-07-19 16:59:26 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2016-11-23 19:33:24 +00:00
|
|
|
trackEvent('Folder', 'Duplicate', 'Folder Action');
|
2016-09-08 06:54:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
async _requestGroupCreate () {
|
|
|
|
const name = await showModal(PromptModal, {
|
|
|
|
headerName: 'Create New Folder',
|
|
|
|
defaultValue: 'My Folder',
|
|
|
|
selectText: true
|
|
|
|
});
|
2016-07-19 16:59:26 +00:00
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
const {requestGroup} = this.props;
|
|
|
|
models.requestGroup.create({parentId: requestGroup._id, name});
|
2016-11-23 19:33:24 +00:00
|
|
|
|
|
|
|
trackEvent('Folder', 'Create', 'Folder Action');
|
2016-07-19 16:59:26 +00:00
|
|
|
}
|
|
|
|
|
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>
|
2016-11-16 17:18:39 +00:00
|
|
|
<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>
|
2016-11-23 19:33:24 +00:00
|
|
|
<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 = {
|
2016-11-16 17:18:39 +00:00
|
|
|
workspace: PropTypes.object.isRequired,
|
2016-07-19 16:59:26 +00:00
|
|
|
|
|
|
|
// Optional
|
2016-04-09 21:41:27 +00:00
|
|
|
requestGroup: PropTypes.object
|
|
|
|
};
|
|
|
|
|
2016-11-16 17:18:39 +00:00
|
|
|
export default RequestGroupActionsDropdown;
|