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

91 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-08-10 01:56:27 +00:00
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import autobind from 'autobind-decorator';
import PromptButton from '../base/prompt-button';
import {Dropdown, DropdownButton, DropdownHint, DropdownItem} from '../base/dropdown';
2016-11-10 05:56:23 +00:00
import * as models from '../../../models';
import {trackEvent} from '../../../analytics/index';
import {DropdownDivider} from '../base/dropdown/index';
2016-07-14 22:48:56 +00:00
@autobind
class RequestActionsDropdown extends PureComponent {
_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');
}
_handleCopyAsCurl () {
trackEvent('Request', 'Copy As Curl', 'Request Action');
this.props.handleCopyAsCurl(this.props.request);
}
_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 () {
const {
request, // eslint-disable-line no-unused-vars
handleShowSettings,
...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"/>
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._handleGenerateCode}>
<i className="fa fa-code"/> Generate Code
</DropdownItem>
<DropdownItem onClick={this._handleCopyAsCurl}
buttonClass={PromptButton}
addIcon
confirmMessage="Click Again to Copy">
<i className="fa fa-copy"/> Copy as Curl
</DropdownItem>
<DropdownItem buttonClass={PromptButton} onClick={this._handleRemove} addIcon>
<i className="fa fa-trash-o"/> Delete
2016-11-11 22:01:21 +00:00
</DropdownItem>
<DropdownDivider/>
<DropdownItem onClick={handleShowSettings}>
<i className="fa fa-wrench"/> Settings
<DropdownHint alt shift char=","/>
</DropdownItem>
2016-04-03 22:54:39 +00:00
</Dropdown>
);
2016-04-03 22:54:39 +00:00
}
}
RequestActionsDropdown.propTypes = {
handleDuplicateRequest: PropTypes.func.isRequired,
2016-11-28 07:12:17 +00:00
handleGenerateCode: PropTypes.func.isRequired,
handleCopyAsCurl: PropTypes.func.isRequired,
handleShowSettings: 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;