2017-08-10 01:56:27 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2017-03-30 18:52:07 +00:00
|
|
|
import {Dropdown, DropdownButton, DropdownDivider, DropdownItem} from '../base/dropdown';
|
|
|
|
import {getPreviewModeName, PREVIEW_MODES} from '../../../common/constants';
|
2016-11-23 19:33:24 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2016-04-30 05:01:57 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2016-11-27 21:42:38 +00:00
|
|
|
class PreviewModeDropdown extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleClick (previewMode) {
|
2016-11-27 21:42:38 +00:00
|
|
|
this.props.updatePreviewMode(previewMode);
|
2016-12-01 01:50:59 +00:00
|
|
|
trackEvent('Response', 'Preview Mode Change', previewMode);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-27 21:42:38 +00:00
|
|
|
|
2017-03-30 18:52:07 +00:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-11-27 21:42:38 +00:00
|
|
|
render () {
|
2017-06-16 22:21:41 +00:00
|
|
|
const {download, fullDownload, previewMode} = this.props;
|
2016-11-27 21:42:38 +00:00
|
|
|
return (
|
2017-06-16 22:21:41 +00:00
|
|
|
<Dropdown beside>
|
2016-11-27 21:42:38 +00:00
|
|
|
<DropdownButton className="tall">
|
2017-06-16 22:21:41 +00:00
|
|
|
{getPreviewModeName(previewMode)}
|
|
|
|
<i className="fa fa-caret-down space-left"/>
|
2016-11-27 21:42:38 +00:00
|
|
|
</DropdownButton>
|
2016-12-21 23:37:48 +00:00
|
|
|
<DropdownDivider>Preview Mode</DropdownDivider>
|
2017-03-30 18:52:07 +00:00
|
|
|
{PREVIEW_MODES.map(this.renderPreviewMode)}
|
2016-12-21 23:37:48 +00:00
|
|
|
<DropdownDivider>Actions</DropdownDivider>
|
2016-11-27 21:42:38 +00:00
|
|
|
<DropdownItem onClick={download}>
|
2017-03-30 18:52:07 +00:00
|
|
|
<i className="fa fa-save"/>
|
2017-05-15 19:44:12 +00:00
|
|
|
Save Response Body
|
|
|
|
</DropdownItem>
|
|
|
|
<DropdownItem onClick={fullDownload}>
|
2017-06-16 22:21:41 +00:00
|
|
|
<i className="fa fa-save"/>
|
2017-05-15 19:44:12 +00:00
|
|
|
Save Full Response
|
2016-11-27 21:42:38 +00:00
|
|
|
</DropdownItem>
|
|
|
|
</Dropdown>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2016-11-27 21:42:38 +00:00
|
|
|
}
|
|
|
|
}
|
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,
|
2017-05-15 19:44:12 +00:00
|
|
|
fullDownload: PropTypes.func.isRequired,
|
2016-07-28 20:10:26 +00:00
|
|
|
|
2016-04-30 05:01:57 +00:00
|
|
|
// Required
|
|
|
|
previewMode: PropTypes.string.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
export default PreviewModeDropdown;
|