insomnia/app/ui/components/dropdowns/preview-mode-dropdown.js
Edward Andrews-Hodgson a31c9b7c7d Save full response to a file (#207)
* Save full response to a file

* Add a new button on the response preview pane
* Save full response to file when button clicked

* Update after PR comments

* It's a Response, not a Request

* Remove file extension requirement
2017-05-15 12:44:12 -07:00

58 lines
1.7 KiB
JavaScript

import React, {PropTypes, PureComponent} from 'react';
import autobind from 'autobind-decorator';
import {Dropdown, DropdownButton, DropdownDivider, DropdownItem} from '../base/dropdown';
import {getPreviewModeName, PREVIEW_MODES} from '../../../common/constants';
import {trackEvent} from '../../../analytics/index';
@autobind
class PreviewModeDropdown extends PureComponent {
_handleClick (previewMode) {
this.props.updatePreviewMode(previewMode);
trackEvent('Response', 'Preview Mode Change', previewMode);
}
renderPreviewMode (mode) {
const {previewMode} = this.props;
return (
<DropdownItem key={mode} onClick={this._handleClick} value={mode}>
{previewMode === mode ? <i className="fa fa-check"/> : <i className="fa fa-empty"/>}
{getPreviewModeName(mode, true)}
</DropdownItem>
);
}
render () {
const {download, fullDownload} = this.props;
return (
<Dropdown>
<DropdownButton className="tall">
<i className="fa fa-caret-down"/>
</DropdownButton>
<DropdownDivider>Preview Mode</DropdownDivider>
{PREVIEW_MODES.map(this.renderPreviewMode)}
<DropdownDivider>Actions</DropdownDivider>
<DropdownItem onClick={download}>
<i className="fa fa-save"/>
Save Response Body
</DropdownItem>
<DropdownItem onClick={fullDownload}>
<i className="fa fa-save" />
Save Full Response
</DropdownItem>
</Dropdown>
);
}
}
PreviewModeDropdown.propTypes = {
// Functions
updatePreviewMode: PropTypes.func.isRequired,
download: PropTypes.func.isRequired,
fullDownload: PropTypes.func.isRequired,
// Required
previewMode: PropTypes.string.isRequired
};
export default PreviewModeDropdown;