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 {
|
2017-02-08 00:31:48 +00:00
|
|
|
_setDropdownRef = n => this._dropdown = n;
|
|
|
|
|
2016-11-28 07:12:17 +00:00
|
|
|
_handleRename = async () => {
|
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-11-28 07:12:17 +00:00
|
|
|
};
|
2016-07-19 16:59:26 +00:00
|
|
|
|
2016-11-28 07:12:17 +00:00
|
|
|
_handleRequestCreate = async () => {
|
2016-11-25 23:09:17 +00:00
|
|
|
this.props.handleCreateRequest(this.props.requestGroup._id);
|
2016-11-23 19:33:24 +00:00
|
|
|
trackEvent('Request', 'Create', 'Folder Action');
|
2016-11-28 07:12:17 +00:00
|
|
|
};
|
2016-07-19 16:59:26 +00:00
|
|
|
|
2016-11-28 07:12:17 +00:00
|
|
|
_handleRequestGroupDuplicate = () => {
|
|
|
|
this.props.handleDuplicateRequestGroup(this.props.requestGroup);
|
2016-11-23 19:33:24 +00:00
|
|
|
trackEvent('Folder', 'Duplicate', 'Folder Action');
|
2016-11-28 07:12:17 +00:00
|
|
|
};
|
2016-09-08 06:54:35 +00:00
|
|
|
|
2016-11-28 07:12:17 +00:00
|
|
|
_handleRequestGroupCreate = async () => {
|
2016-11-25 23:09:17 +00:00
|
|
|
this.props.handleCreateRequestGroup(this.props.requestGroup._id);
|
2016-11-23 19:33:24 +00:00
|
|
|
trackEvent('Folder', 'Create', 'Folder Action');
|
2016-11-28 07:12:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_handleDeleteFolder = () => {
|
|
|
|
models.requestGroup.remove(this.props.requestGroup);
|
|
|
|
trackEvent('Folder', 'Delete', 'Folder Action');
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleEditEnvironment = () => {
|
|
|
|
showModal(EnvironmentEditModal, this.props.requestGroup);
|
|
|
|
};
|
2016-07-19 16:59:26 +00:00
|
|
|
|
2017-02-08 00:31:48 +00:00
|
|
|
show () {
|
|
|
|
this._dropdown.show();
|
|
|
|
}
|
|
|
|
|
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 (
|
2017-02-08 00:31:48 +00:00
|
|
|
<Dropdown ref={this._setDropdownRef} {...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>
|
2016-11-28 07:12:17 +00:00
|
|
|
<DropdownItem onClick={this._handleRequestCreate}>
|
2016-11-11 22:01:21 +00:00
|
|
|
<i className="fa fa-plus-circle"></i> New Request
|
|
|
|
<DropdownHint char="N"></DropdownHint>
|
|
|
|
</DropdownItem>
|
2016-11-28 07:12:17 +00:00
|
|
|
<DropdownItem onClick={this._handleRequestGroupCreate}>
|
2016-11-16 17:18:39 +00:00
|
|
|
<i className="fa fa-folder"></i> New Folder
|
|
|
|
</DropdownItem>
|
2016-11-11 22:01:21 +00:00
|
|
|
<DropdownDivider />
|
2016-11-28 07:12:17 +00:00
|
|
|
<DropdownItem onClick={this._handleRequestGroupDuplicate}>
|
2016-11-11 22:01:21 +00:00
|
|
|
<i className="fa fa-copy"></i> Duplicate
|
|
|
|
</DropdownItem>
|
2016-11-28 07:12:17 +00:00
|
|
|
<DropdownItem onClick={this._handleRename}>
|
2016-11-11 22:01:21 +00:00
|
|
|
<i className="fa fa-edit"></i> Rename
|
|
|
|
</DropdownItem>
|
2016-11-28 07:12:17 +00:00
|
|
|
<DropdownItem onClick={this._handleEditEnvironment}>
|
2016-11-11 22:01:21 +00:00
|
|
|
<i className="fa fa-code"></i> Environment
|
|
|
|
</DropdownItem>
|
2016-11-28 07:12:17 +00:00
|
|
|
<DropdownItem buttonClass={PromptButton} addIcon={true} onClick={this._handleDeleteFolder}>
|
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-11-23 20:44:46 +00:00
|
|
|
handleCreateRequest: PropTypes.func.isRequired,
|
|
|
|
handleCreateRequestGroup: PropTypes.func.isRequired,
|
2016-11-28 07:12:17 +00:00
|
|
|
handleDuplicateRequestGroup: PropTypes.func.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;
|