2017-06-01 02:04:27 +00:00
|
|
|
import React, {PropTypes, PureComponent} from 'react';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2017-03-08 05:52:17 +00:00
|
|
|
import PromptButton from '../base/prompt-button';
|
2017-06-01 02:04:27 +00:00
|
|
|
import {Dropdown, DropdownButton, DropdownDivider, DropdownHint, DropdownItem} from '../base/dropdown';
|
2017-03-08 05:52:17 +00:00
|
|
|
import EnvironmentEditModal from '../modals/environment-edit-modal';
|
2016-11-16 17:18:39 +00:00
|
|
|
import * as models from '../../../models';
|
|
|
|
import {showModal} from '../modals';
|
2016-11-23 19:33:24 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2017-06-01 02:04:27 +00:00
|
|
|
import {showPrompt} from '../modals/index';
|
2016-04-09 21:41:27 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2017-02-28 21:32:23 +00:00
|
|
|
class RequestGroupActionsDropdown extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
_setDropdownRef (n) {
|
|
|
|
this._dropdown = n;
|
|
|
|
}
|
2017-02-08 00:31:48 +00:00
|
|
|
|
2017-06-01 02:04:27 +00:00
|
|
|
_handleRename () {
|
2016-07-14 22:48:56 +00:00
|
|
|
const {requestGroup} = this.props;
|
|
|
|
|
2017-06-01 02:04:27 +00:00
|
|
|
showPrompt({
|
2017-07-20 01:55:40 +00:00
|
|
|
title: 'Rename Folder',
|
2017-06-01 02:04:27 +00:00
|
|
|
defaultValue: requestGroup.name,
|
|
|
|
onComplete: name => {
|
|
|
|
models.requestGroup.update(requestGroup, {name});
|
|
|
|
trackEvent('Folder', 'Rename', 'Folder Action');
|
|
|
|
}
|
2016-10-02 20:57:00 +00:00
|
|
|
});
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-07-19 16:59:26 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
async _handleRequestCreate () {
|
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');
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-07-19 16:59:26 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleRequestGroupDuplicate () {
|
2016-11-28 07:12:17 +00:00
|
|
|
this.props.handleDuplicateRequestGroup(this.props.requestGroup);
|
2016-11-23 19:33:24 +00:00
|
|
|
trackEvent('Folder', 'Duplicate', 'Folder Action');
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-09-08 06:54:35 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
async _handleRequestGroupCreate () {
|
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');
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-28 07:12:17 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleDeleteFolder () {
|
2016-11-28 07:12:17 +00:00
|
|
|
models.requestGroup.remove(this.props.requestGroup);
|
|
|
|
trackEvent('Folder', 'Delete', 'Folder Action');
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-28 07:12:17 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleEditEnvironment () {
|
2016-11-28 07:12:17 +00:00
|
|
|
showModal(EnvironmentEditModal, this.props.requestGroup);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
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 () {
|
2017-03-03 20:09:08 +00:00
|
|
|
const {
|
|
|
|
requestGroup, // eslint-disable-line no-unused-vars
|
|
|
|
...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>
|
2017-07-25 22:28:53 +00:00
|
|
|
<i className="fa fa-caret-down"/>
|
2016-11-11 22:01:21 +00:00
|
|
|
</DropdownButton>
|
2016-11-28 07:12:17 +00:00
|
|
|
<DropdownItem onClick={this._handleRequestCreate}>
|
2017-07-25 22:28:53 +00:00
|
|
|
<i className="fa fa-plus-circle"/> New Request
|
2016-11-11 22:01:21 +00:00
|
|
|
<DropdownHint char="N"></DropdownHint>
|
|
|
|
</DropdownItem>
|
2016-11-28 07:12:17 +00:00
|
|
|
<DropdownItem onClick={this._handleRequestGroupCreate}>
|
2017-07-25 22:28:53 +00:00
|
|
|
<i className="fa fa-folder"/> New Folder
|
2016-11-16 17:18:39 +00:00
|
|
|
</DropdownItem>
|
2016-11-11 22:01:21 +00:00
|
|
|
<DropdownDivider />
|
2016-11-28 07:12:17 +00:00
|
|
|
<DropdownItem onClick={this._handleRequestGroupDuplicate}>
|
2017-07-25 22:28:53 +00:00
|
|
|
<i className="fa fa-copy"/> Duplicate
|
2016-11-11 22:01:21 +00:00
|
|
|
</DropdownItem>
|
2016-11-28 07:12:17 +00:00
|
|
|
<DropdownItem onClick={this._handleRename}>
|
2017-07-25 22:28:53 +00:00
|
|
|
<i className="fa fa-edit"/> Rename
|
2016-11-11 22:01:21 +00:00
|
|
|
</DropdownItem>
|
2016-11-28 07:12:17 +00:00
|
|
|
<DropdownItem onClick={this._handleEditEnvironment}>
|
2017-07-25 22:28:53 +00:00
|
|
|
<i className="fa fa-code"/> Environment
|
2016-11-11 22:01:21 +00:00
|
|
|
</DropdownItem>
|
2017-03-01 21:15:56 +00:00
|
|
|
<DropdownItem buttonClass={PromptButton} addIcon onClick={this._handleDeleteFolder}>
|
2017-07-25 22:28:53 +00:00
|
|
|
<i className="fa fa-trash-o"/> Delete
|
2016-11-11 22:01:21 +00:00
|
|
|
</DropdownItem>
|
2016-04-09 21:41:27 +00:00
|
|
|
</Dropdown>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2016-04-09 21:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|