From ef95e32577b9d349a008eec2bb3be67bf0d3138f Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 27 Jan 2017 22:09:01 -0800 Subject: [PATCH] Import in url now uses onPaste to preserve newlines --- app/ui/components/RequestPane.js | 19 ++++++----- app/ui/components/RequestUrlBar.js | 34 +++++++------------ app/ui/components/Wrapper.js | 7 ++-- .../dropdowns/ContentTypeDropdown.js | 2 +- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/app/ui/components/RequestPane.js b/app/ui/components/RequestPane.js index 274f5e902c..103baa848e 100644 --- a/app/ui/components/RequestPane.js +++ b/app/ui/components/RequestPane.js @@ -74,6 +74,7 @@ class RequestPane extends PureComponent { forceRefreshCounter, useBulkHeaderEditor, handleGenerateCode, + importRequest, updateRequestUrl, updateRequestMethod, updateRequestBody, @@ -148,6 +149,7 @@ class RequestPane extends PureComponent { method={request.method} onMethodChange={updateRequestMethod} onUrlChange={debounce(updateRequestUrl)} + onUrlPaste={importRequest} handleGenerateCode={handleGenerateCode} handleSend={handleSend} url={request.url} @@ -205,14 +207,14 @@ class RequestPane extends PureComponent { />
{showPasswords ? ( - - ) : ( - - )} + + ) : ( + + )}
@@ -289,6 +291,7 @@ RequestPane.propTypes = { updateRequestMimeType: PropTypes.func.isRequired, updateSettingsShowPasswords: PropTypes.func.isRequired, updateSettingsUseBulkHeaderEditor: PropTypes.func.isRequired, + importRequest: PropTypes.func.isRequired, handleImportFile: PropTypes.func.isRequired, // Other diff --git a/app/ui/components/RequestUrlBar.js b/app/ui/components/RequestUrlBar.js index 55cb7d822a..f2564c4e20 100644 --- a/app/ui/components/RequestUrlBar.js +++ b/app/ui/components/RequestUrlBar.js @@ -10,7 +10,6 @@ import {showModal} from './modals/index'; class RequestUrlBar extends Component { state = { - showAdvanced: false, currentInterval: null, currentTimeout: null, }; @@ -35,6 +34,15 @@ class RequestUrlBar extends Component { }, DEBOUNCE_MILLIS); }; + _handleUrlPaste = e => { + e.preventDefault(); + const text = e.clipboardData.getData('text/plain'); + this.props.onUrlPaste(text); + + // Set the input anyway in case nothing is able to import + e.target.value = text; + }; + _handleGenerateCode = () => { this.props.handleGenerateCode(); trackEvent('Request', 'Generate Code', 'Send Action'); @@ -52,31 +60,11 @@ class RequestUrlBar extends Component { this._input.focus(); this._input.select(); } - - if (!this.state.showAdvanced && metaPressed) { - clearTimeout(this._metaTimeout); - this._metaTimeout = setTimeout(() => { - this.setState({showAdvanced: true}); - }, 400); - } - }; - - _handleKeyUp = e => { - const metaPressed = isMac() ? e.metaKey : e.ctrlKey; - - // First, clear the meta timeout if it hasn't triggered yet - if (!metaPressed) { - clearTimeout(this._metaTimeout); - } - - if (!metaPressed && this.state.showAdvanced) { - this.setState({showAdvanced: false}); - } }; _handleSend = () => { // Don't stop interval because duh, it needs to keep going! - // this._handleStopInterval(); + // XXX this._handleStopInterval(); XXX this._handleStopTimeout(); this.props.handleSend(); @@ -222,6 +210,7 @@ class RequestUrlBar extends Component {
this._input = n} + onPaste={this._handleUrlPaste} type="text" placeholder="https://api.myproduct.com/v1/users" defaultValue={url} @@ -236,6 +225,7 @@ class RequestUrlBar extends Component { RequestUrlBar.propTypes = { handleSend: PropTypes.func.isRequired, onUrlChange: PropTypes.func.isRequired, + onUrlPaste: PropTypes.func.isRequired, onMethodChange: PropTypes.func.isRequired, handleGenerateCode: PropTypes.func.isRequired, url: PropTypes.string.isRequired, diff --git a/app/ui/components/Wrapper.js b/app/ui/components/Wrapper.js index ae730f939f..9fa0bd7214 100644 --- a/app/ui/components/Wrapper.js +++ b/app/ui/components/Wrapper.js @@ -41,16 +41,17 @@ class Wrapper extends Component { _handleUpdateRequestParameters = parameters => rUpdate(this.props.activeRequest, {parameters}); _handleUpdateRequestAuthentication = authentication => rUpdate(this.props.activeRequest, {authentication}); _handleUpdateRequestHeaders = headers => rUpdate(this.props.activeRequest, {headers}); + _handleUpdateRequestUrl = url => rUpdate(this.props.activeRequest, {url}); // Special request updaters _handleUpdateRequestMimeType = mimeType => updateMimeType(this.props.activeRequest, mimeType); - _handleUpdateRequestUrl = async url => { + _handleImportRequest = async text => { // Allow user to paste any import file into the url. If it results in // only one item, it will overwrite the current request. const {activeRequest} = this.props; try { - const {data} = importers.convert(url); + const {data} = importers.convert(text); const {resources} = data; const r = resources[0]; @@ -77,6 +78,7 @@ class Wrapper extends Component { models.request.update(activeRequest, {url}); }; + // Settings updaters _handleUpdateSettingsShowPasswords = showPasswords => sUpdate(this.props.settings, {showPasswords}); _handleUpdateSettingsUseBulkHeaderEditor = useBulkHeaderEditor => sUpdate(this.props.settings, {useBulkHeaderEditor}); @@ -239,6 +241,7 @@ class Wrapper extends Component { updateRequest={this._handleUpdateRequest} updateRequestBody={this._handleUpdateRequestBody} updateRequestUrl={this._handleUpdateRequestUrl} + importRequest={this._handleImportRequest} updateRequestMethod={this._handleUpdateRequestMethod} updateRequestParameters={this._handleUpdateRequestParameters} updateRequestAuthentication={this._handleUpdateRequestAuthentication} diff --git a/app/ui/components/dropdowns/ContentTypeDropdown.js b/app/ui/components/dropdowns/ContentTypeDropdown.js index 4532eb3d23..b968c751c0 100644 --- a/app/ui/components/dropdowns/ContentTypeDropdown.js +++ b/app/ui/components/dropdowns/ContentTypeDropdown.js @@ -37,7 +37,7 @@ class ContentTypeDropdown extends Component { Form Data {this._renderDropdownItem(constants.CONTENT_TYPE_FORM_DATA)} {this._renderDropdownItem(constants.CONTENT_TYPE_FORM_URLENCODED)} - Raw Text + Text {this._renderDropdownItem(constants.CONTENT_TYPE_JSON)} {this._renderDropdownItem(constants.CONTENT_TYPE_XML)} {this._renderDropdownItem(constants.CONTENT_TYPE_OTHER)}