import React, {PropTypes, PureComponent} from 'react'; import autobind from 'autobind-decorator'; import Modal from '../base/modal'; import ModalBody from '../base/modal-body'; import ModalHeader from '../base/modal-header'; import HelpTooltip from '../help-tooltip'; import * as models from '../../../models'; import {trackEvent} from '../../../analytics/index'; import DebouncedInput from '../base/debounced-input'; import MarkdownEditor from '../markdown-editor'; @autobind class RequestSettingsModal extends PureComponent { constructor (props) { super(props); this.state = { request: null, showDescription: false, defaultPreviewMode: false }; } _setModalRef (n) { this.modal = n; } _setEditorRef (n) { this._editor = n; } async _updateRequestSettingBoolean (e) { const value = e.target.checked; const setting = e.target.name; const request = await models.request.update(this.state.request, {[setting]: value}); this.setState({request}); trackEvent('Request Settings', setting, value ? 'Enable' : 'Disable'); } async _handleNameChange (name) { const request = await models.request.update(this.state.request, {name}); this.setState({request}); } async _handleDescriptionChange (description) { const request = await models.request.update(this.state.request, {description}); this.setState({request, defaultPreviewMode: false}); } _handleAddDescription () { trackEvent('Request', 'Add Description'); this.setState({showDescription: true}); } show ({request, forceEditMode}) { this.modal.show(); const hasDescription = !!request.description; this.setState({ request, showDescription: forceEditMode || hasDescription, defaultPreviewMode: hasDescription && !forceEditMode }); if (forceEditMode) { setTimeout(() => { this._editor.focus(); }, 400); } } hide () { this.modal.hide(); } renderCheckboxInput (setting) { return ( ); } renderModalBody (request) { const { editorLineWrapping, editorFontSize, editorIndentSize, editorKeyMap, handleRender, handleGetRenderContext } = this.props; const {showDescription, defaultPreviewMode} = this.state; return (
{showDescription ? ( ) : ( )}
); } render () { const {request} = this.state; return ( Request Settings {' '} {request ? request._id : ''} {request ? this.renderModalBody(request) : null} ); } } RequestSettingsModal.propTypes = { editorFontSize: PropTypes.number.isRequired, editorIndentSize: PropTypes.number.isRequired, editorKeyMap: PropTypes.string.isRequired, editorLineWrapping: PropTypes.bool.isRequired, handleRender: PropTypes.func.isRequired, handleGetRenderContext: PropTypes.func.isRequired }; export default RequestSettingsModal;