2017-02-28 21:32:23 +00:00
|
|
|
import React, {PureComponent, PropTypes} 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';
|
2016-11-11 22:01:21 +00:00
|
|
|
import {Dropdown, DropdownHint, DropdownButton, DropdownItem} from '../base/dropdown';
|
2017-03-08 05:52:17 +00:00
|
|
|
import PromptModal from '../modals/prompt-modal';
|
2016-11-10 05:56:23 +00:00
|
|
|
import * as models from '../../../models';
|
2016-11-07 20:24:38 +00:00
|
|
|
import {showModal} from '../modals/index';
|
2016-11-23 19:33:24 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2016-07-14 22:48:56 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2017-02-28 21:32:23 +00:00
|
|
|
class RequestActionsDropdown extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
_setDropdownRef (n) {
|
|
|
|
this._dropdown = n;
|
|
|
|
}
|
2017-02-08 00:31:48 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleDuplicate () {
|
2016-11-27 21:42:38 +00:00
|
|
|
const {request, handleDuplicateRequest} = this.props;
|
|
|
|
handleDuplicateRequest(request);
|
|
|
|
trackEvent('Request', 'Duplicate', 'Request Action');
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-27 21:42:38 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleGenerateCode () {
|
2016-11-28 07:12:17 +00:00
|
|
|
this.props.handleGenerateCode(this.props.request);
|
2016-11-27 21:42:38 +00:00
|
|
|
trackEvent('Request', 'Generate Code', 'Request Action');
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-27 21:42:38 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
async _handlePromptUpdateName () {
|
2016-07-14 22:48:56 +00:00
|
|
|
const {request} = this.props;
|
|
|
|
|
2016-11-07 20:24:38 +00:00
|
|
|
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,
|
2016-07-25 22:27:29 +00:00
|
|
|
hint: 'also rename requests by double clicking in the sidebar'
|
2016-10-02 20:57:00 +00:00
|
|
|
});
|
|
|
|
|
2016-11-10 01:15:27 +00:00
|
|
|
models.request.update(request, {name});
|
2016-11-27 21:42:38 +00:00
|
|
|
|
|
|
|
trackEvent('Request', 'Rename', 'Request Action');
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-27 21:42:38 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleRemove () {
|
2016-11-27 21:42:38 +00:00
|
|
|
const {request} = this.props;
|
|
|
|
models.request.remove(request);
|
|
|
|
trackEvent('Request', 'Delete', 'Action');
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-07-14 22:48:56 +00:00
|
|
|
|
2017-02-08 00:31:48 +00:00
|
|
|
show () {
|
|
|
|
this._dropdown.show();
|
|
|
|
}
|
|
|
|
|
2016-04-03 22:54:39 +00:00
|
|
|
render () {
|
2017-03-03 20:09:08 +00:00
|
|
|
const {
|
|
|
|
request, // eslint-disable-line no-unused-vars
|
|
|
|
...other
|
|
|
|
} = this.props;
|
2016-04-03 22:54:39 +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-08-15 17:04:36 +00:00
|
|
|
<i className="fa fa-caret-down"></i>
|
2016-11-11 22:01:21 +00:00
|
|
|
</DropdownButton>
|
2016-11-27 21:42:38 +00:00
|
|
|
<DropdownItem onClick={this._handleDuplicate}>
|
2017-02-27 21:00:13 +00:00
|
|
|
<i className="fa fa-copy"/> Duplicate
|
|
|
|
<DropdownHint char="D"/>
|
2016-11-11 22:01:21 +00:00
|
|
|
</DropdownItem>
|
2016-11-27 21:42:38 +00:00
|
|
|
<DropdownItem onClick={this._handlePromptUpdateName}>
|
2017-02-27 21:00:13 +00:00
|
|
|
<i className="fa fa-edit"/> Rename
|
2016-11-11 22:01:21 +00:00
|
|
|
</DropdownItem>
|
2016-11-27 21:42:38 +00:00
|
|
|
<DropdownItem onClick={this._handleGenerateCode}>
|
2017-02-27 21:00:13 +00:00
|
|
|
<i className="fa fa-code"/> Generate Code
|
|
|
|
</DropdownItem>
|
2017-03-01 21:15:56 +00:00
|
|
|
<DropdownItem buttonClass={PromptButton} onClick={this._handleRemove} addIcon>
|
2017-02-27 21:00:13 +00:00
|
|
|
<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>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2016-04-03 22:54:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RequestActionsDropdown.propTypes = {
|
2016-11-27 21:42:38 +00:00
|
|
|
handleDuplicateRequest: PropTypes.func.isRequired,
|
2016-11-28 07:12:17 +00:00
|
|
|
handleGenerateCode: PropTypes.func.isRequired,
|
2017-03-03 20:09:08 +00:00
|
|
|
request: PropTypes.object.isRequired
|
2016-04-03 22:54:39 +00:00
|
|
|
};
|
|
|
|
|
2016-09-22 20:14:41 +00:00
|
|
|
export default RequestActionsDropdown;
|