insomnia/app/ui/components/dropdowns/RequestActionsDropdown.js
Gregory Schier bb57f360e0 Environment Tags and Such (#90)
* Sort of working nunjucks editor

* Some more tweaks

* Lots of stuff

* Gettingn pretty good

* Minor tweaks and test fixes

* Minor bug fixes and stuff

* Some fixes and perf

* Refactoring

* Good for now

* Codemirror URL

* More and more fixes and improvements

* Code single-line CSS perfect!!!

* Better nj editing

* Show preview in nj edit

* Some editor updates

* All inputs now covered

* A bunch of fixes and stuff

* Don't cache node modules because it's not needed

* More stuff

* Tweak

* Style tweaks

* Pull nunjucks mode into own file

* Move codemirror click overlay to own file

* Pull nunjucks tag stuff out

* Fixed key value editor

* raw/endraw and marks improvements

* Some tweaks
2017-02-27 13:00:13 -08:00

87 lines
2.7 KiB
JavaScript

import React, {Component, PropTypes} from 'react';
import PromptButton from '../base/PromptButton';
import {Dropdown, DropdownHint, DropdownButton, DropdownItem} from '../base/dropdown';
import PromptModal from '../modals/PromptModal';
import CopyButton from '../base/CopyButton';
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';
class RequestActionsDropdown extends Component {
_setDropdownRef = n => this._dropdown = n;
_handleDuplicate = () => {
const {request, handleDuplicateRequest} = this.props;
handleDuplicateRequest(request);
trackEvent('Request', 'Duplicate', 'Request Action');
};
_handleGenerateCode = () => {
this.props.handleGenerateCode(this.props.request);
trackEvent('Request', 'Generate Code', 'Request Action');
};
_handlePromptUpdateName = async () => {
const {request} = this.props;
const name = await showModal(PromptModal, {
headerName: 'Rename Request',
defaultValue: request.name,
hint: 'also rename requests by double clicking in the sidebar'
});
models.request.update(request, {name});
trackEvent('Request', 'Rename', 'Request Action');
};
_handleRemove = () => {
const {request} = this.props;
models.request.remove(request);
trackEvent('Request', 'Delete', 'Action');
};
show () {
this._dropdown.show();
}
render () {
const {request, ...other} = this.props;
return (
<Dropdown ref={this._setDropdownRef} {...other}>
<DropdownButton>
<i className="fa fa-caret-down"></i>
</DropdownButton>
<DropdownItem onClick={this._handleDuplicate}>
<i className="fa fa-copy"/> Duplicate
<DropdownHint char="D"/>
</DropdownItem>
<DropdownItem onClick={this._handlePromptUpdateName}>
<i className="fa fa-edit"/> Rename
</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
</DropdownItem>
<DropdownItem buttonClass={PromptButton} onClick={this._handleRemove} addIcon={true}>
<i className="fa fa-trash-o"/> Delete
</DropdownItem>
</Dropdown>
)
}
}
RequestActionsDropdown.propTypes = {
handleDuplicateRequest: PropTypes.func.isRequired,
handleGenerateCode: PropTypes.func.isRequired,
request: PropTypes.object.isRequired,
};
export default RequestActionsDropdown;