Import in url now uses onPaste to preserve newlines

This commit is contained in:
Gregory Schier
2017-01-27 22:09:01 -08:00
parent d6b88d64e6
commit ef95e32577
4 changed files with 29 additions and 33 deletions

View File

@@ -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 {
/>
<div className="pad pull-right">
{showPasswords ? (
<button className="btn btn--clicky" onClick={this._handleHidePasswords}>
Hide Password
</button>
) : (
<button className="btn btn--clicky" onClick={this._handleShowPasswords}>
Show Password
</button>
)}
<button className="btn btn--clicky" onClick={this._handleHidePasswords}>
Hide Password
</button>
) : (
<button className="btn btn--clicky" onClick={this._handleShowPasswords}>
Show Password
</button>
)}
</div>
</div>
</TabPanel>
@@ -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

View File

@@ -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 {
<form onSubmit={this._handleFormSubmit}>
<input
ref={n => 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,

View File

@@ -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}

View File

@@ -37,7 +37,7 @@ class ContentTypeDropdown extends Component {
<DropdownDivider><span><i className="fa fa-bars"></i> Form Data</span></DropdownDivider>
{this._renderDropdownItem(constants.CONTENT_TYPE_FORM_DATA)}
{this._renderDropdownItem(constants.CONTENT_TYPE_FORM_URLENCODED)}
<DropdownDivider><span><i className="fa fa-code"></i> Raw Text</span></DropdownDivider>
<DropdownDivider><span><i className="fa fa-code"></i> Text</span></DropdownDivider>
{this._renderDropdownItem(constants.CONTENT_TYPE_JSON)}
{this._renderDropdownItem(constants.CONTENT_TYPE_XML)}
{this._renderDropdownItem(constants.CONTENT_TYPE_OTHER)}