insomnia/app/ui/components/dropdowns/request-group-actions-dropdown.js

105 lines
3.2 KiB
JavaScript
Raw Normal View History

import React, {PropTypes, PureComponent} from 'react';
import autobind from 'autobind-decorator';
import PromptButton from '../base/prompt-button';
import {Dropdown, DropdownButton, DropdownDivider, DropdownHint, DropdownItem} from '../base/dropdown';
import EnvironmentEditModal from '../modals/environment-edit-modal';
import * as models from '../../../models';
import {showModal} from '../modals';
import {trackEvent} from '../../../analytics/index';
import {showPrompt} from '../modals/index';
2016-04-09 21:41:27 +00:00
@autobind
class RequestGroupActionsDropdown extends PureComponent {
_setDropdownRef (n) {
this._dropdown = n;
}
_handleRename () {
2016-07-14 22:48:56 +00:00
const {requestGroup} = this.props;
showPrompt({
title: 'Rename Folder',
defaultValue: requestGroup.name,
onComplete: name => {
models.requestGroup.update(requestGroup, {name});
trackEvent('Folder', 'Rename', 'Folder Action');
}
});
}
async _handleRequestCreate () {
2016-11-25 23:09:17 +00:00
this.props.handleCreateRequest(this.props.requestGroup._id);
trackEvent('Request', 'Create', 'Folder Action');
}
_handleRequestGroupDuplicate () {
2016-11-28 07:12:17 +00:00
this.props.handleDuplicateRequestGroup(this.props.requestGroup);
trackEvent('Folder', 'Duplicate', 'Folder Action');
}
2016-09-08 06:54:35 +00:00
async _handleRequestGroupCreate () {
2016-11-25 23:09:17 +00:00
this.props.handleCreateRequestGroup(this.props.requestGroup._id);
trackEvent('Folder', 'Create', 'Folder Action');
}
2016-11-28 07:12:17 +00:00
_handleDeleteFolder () {
2016-11-28 07:12:17 +00:00
models.requestGroup.remove(this.props.requestGroup);
trackEvent('Folder', 'Delete', 'Folder Action');
}
2016-11-28 07:12:17 +00:00
_handleEditEnvironment () {
2016-11-28 07:12:17 +00:00
showModal(EnvironmentEditModal, this.props.requestGroup);
}
show () {
this._dropdown.show();
}
2016-04-09 21:41:27 +00:00
render () {
const {
requestGroup, // eslint-disable-line no-unused-vars
...other
} = this.props;
2016-04-09 21:41:27 +00:00
return (
<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
</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>
<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>
);
2016-04-09 21:41:27 +00:00
}
}
RequestGroupActionsDropdown.propTypes = {
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,
// Optional
2016-04-09 21:41:27 +00:00
requestGroup: PropTypes.object
};
export default RequestGroupActionsDropdown;