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

92 lines
3.0 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 {
2016-11-28 07:12:17 +00:00
_handleRename = async () => {
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-11-28 07:12:17 +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);
trackEvent('Request', 'Create', 'Folder Action');
2016-11-28 07:12:17 +00:00
};
2016-11-28 07:12:17 +00:00
_handleRequestGroupDuplicate = () => {
this.props.handleDuplicateRequestGroup(this.props.requestGroup);
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);
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-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>
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}>
<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 = {
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;