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

58 lines
1.7 KiB
JavaScript
Raw Normal View History

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';
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 () {
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>
);
}
}
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;