insomnia/app/ui/components/dropdowns/preview-mode-dropdown.js

60 lines
1.8 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 {Dropdown, DropdownButton, DropdownDivider, DropdownItem} from '../base/dropdown';
import {getPreviewModeName, PREVIEW_MODES} from '../../../common/constants';
import {trackEvent} from '../../../analytics/index';
2016-04-30 05:01:57 +00:00
@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 () {
2017-06-16 22:21:41 +00:00
const {download, fullDownload, previewMode} = this.props;
return (
2017-06-16 22:21:41 +00:00
<Dropdown beside>
<DropdownButton className="tall">
2017-06-16 22:21:41 +00:00
{getPreviewModeName(previewMode)}
<i className="fa fa-caret-down space-left"/>
</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}>
2017-06-16 22:21:41 +00:00
<i className="fa fa-save"/>
Save Full Response
</DropdownItem>
</Dropdown>
);
}
}
2016-04-30 05:01:57 +00:00
PreviewModeDropdown.propTypes = {
// Functions
updatePreviewMode: PropTypes.func.isRequired,
2016-10-28 17:51:08 +00:00
download: PropTypes.func.isRequired,
fullDownload: PropTypes.func.isRequired,
2016-04-30 05:01:57 +00:00
// Required
previewMode: PropTypes.string.isRequired
};
export default PreviewModeDropdown;