2017-08-10 01:56:27 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
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-03-28 22:45:23 +00:00
|
|
|
import {Dropdown, DropdownButton, DropdownHint, DropdownItem} from '../base/dropdown';
|
2016-11-10 05:56:23 +00:00
|
|
|
import * as models from '../../../models';
|
2016-11-23 19:33:24 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2017-03-28 22:45:23 +00:00
|
|
|
import {DropdownDivider} from '../base/dropdown/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-06-29 18:27:29 +00:00
|
|
|
_handleCopyAsCurl () {
|
|
|
|
trackEvent('Request', 'Copy As Curl', 'Request Action');
|
|
|
|
this.props.handleCopyAsCurl(this.props.request);
|
|
|
|
}
|
|
|
|
|
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
|
2017-06-01 22:58:09 +00:00
|
|
|
handleShowSettings,
|
2017-03-03 20:09:08 +00:00
|
|
|
...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>
|
2017-03-28 22:45:23 +00:00
|
|
|
<i className="fa fa-caret-down"/>
|
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._handleGenerateCode}>
|
2017-02-27 21:00:13 +00:00
|
|
|
<i className="fa fa-code"/> Generate Code
|
|
|
|
</DropdownItem>
|
2017-06-29 18:27:29 +00:00
|
|
|
<DropdownItem onClick={this._handleCopyAsCurl}
|
|
|
|
buttonClass={PromptButton}
|
|
|
|
addIcon
|
|
|
|
confirmMessage="Click Again to Copy">
|
|
|
|
<i className="fa fa-copy"/> Copy as Curl
|
|
|
|
</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>
|
2017-03-28 22:45:23 +00:00
|
|
|
|
|
|
|
<DropdownDivider/>
|
|
|
|
|
2017-06-01 22:58:09 +00:00
|
|
|
<DropdownItem onClick={handleShowSettings}>
|
2017-03-28 22:45:23 +00:00
|
|
|
<i className="fa fa-wrench"/> Settings
|
|
|
|
<DropdownHint alt shift char=","/>
|
|
|
|
</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-06-29 18:27:29 +00:00
|
|
|
handleCopyAsCurl: PropTypes.func.isRequired,
|
2017-06-01 22:58:09 +00:00
|
|
|
handleShowSettings: 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;
|