import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; 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}) { const hasDescription = !!request.description; this.setState({ request, showDescription: forceEditMode || hasDescription, defaultPreviewMode: hasDescription && !forceEditMode }); this.modal.show(); 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 (