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

87 lines
2.7 KiB
JavaScript
Raw Normal View History

import React, {Component, PropTypes} from 'react';
2016-09-22 20:14:41 +00:00
import PromptButton from '../base/PromptButton';
2016-11-11 22:01:21 +00:00
import {Dropdown, DropdownHint, DropdownButton, DropdownItem} from '../base/dropdown';
2016-09-22 20:14:41 +00:00
import PromptModal from '../modals/PromptModal';
import CopyButton from '../base/CopyButton';
2016-11-10 05:56:23 +00:00
import * as models from '../../../models';
import {showModal} from '../modals/index';
import {trackEvent} from '../../../analytics/index';
import AlertModal from '../modals/AlertModal';
import {MOD_SYM} from '../../../common/constants';
2016-07-14 22:48:56 +00:00
2016-04-03 22:54:39 +00:00
class RequestActionsDropdown extends Component {
_setDropdownRef = n => this._dropdown = n;
_handleDuplicate = () => {
const {request, handleDuplicateRequest} = this.props;
handleDuplicateRequest(request);
trackEvent('Request', 'Duplicate', 'Request Action');
};
_handleGenerateCode = () => {
2016-11-28 07:12:17 +00:00
this.props.handleGenerateCode(this.props.request);
trackEvent('Request', 'Generate Code', 'Request Action');
};
_handlePromptUpdateName = async () => {
2016-07-14 22:48:56 +00:00
const {request} = this.props;
const name = await showModal(PromptModal, {
2016-07-14 22:48:56 +00:00
headerName: 'Rename Request',
2016-07-19 20:21:33 +00:00
defaultValue: request.name,
hint: 'also rename requests by double clicking in the sidebar'
});
2016-11-10 01:15:27 +00:00
models.request.update(request, {name});
trackEvent('Request', 'Rename', 'Request Action');
};
_handleRemove = () => {
const {request} = this.props;
models.request.remove(request);
trackEvent('Request', 'Delete', 'Action');
};
2016-07-14 22:48:56 +00:00
show () {
this._dropdown.show();
}
2016-04-03 22:54:39 +00:00
render () {
2016-07-14 22:48:56 +00:00
const {request, ...other} = this.props;
2016-04-03 22:54:39 +00:00
return (
<Dropdown ref={this._setDropdownRef} {...other}>
2016-11-11 22:01:21 +00:00
<DropdownButton>
<i className="fa fa-caret-down"></i>
2016-11-11 22:01:21 +00:00
</DropdownButton>
<DropdownItem onClick={this._handleDuplicate}>
<i className="fa fa-copy"/> Duplicate
<DropdownHint char="D"/>
2016-11-11 22:01:21 +00:00
</DropdownItem>
<DropdownItem onClick={this._handlePromptUpdateName}>
<i className="fa fa-edit"/> Rename
2016-11-11 22:01:21 +00:00
</DropdownItem>
<DropdownItem onClick={this._handleGenerateCode}>
<i className="fa fa-code"/> Generate Code
</DropdownItem>
<DropdownItem buttonClass={CopyButton} content={request._id} stayOpenAfterClick={true}>
<i className="fa fa-copy"/> Copy Id
2016-11-11 22:01:21 +00:00
</DropdownItem>
<DropdownItem buttonClass={PromptButton} onClick={this._handleRemove} addIcon={true}>
<i className="fa fa-trash-o"/> Delete
2016-11-11 22:01:21 +00:00
</DropdownItem>
2016-04-03 22:54:39 +00:00
</Dropdown>
)
}
}
RequestActionsDropdown.propTypes = {
handleDuplicateRequest: PropTypes.func.isRequired,
2016-11-28 07:12:17 +00:00
handleGenerateCode: PropTypes.func.isRequired,
request: PropTypes.object.isRequired,
2016-04-03 22:54:39 +00:00
};
2016-09-22 20:14:41 +00:00
export default RequestActionsDropdown;