From 5d82a5ec95d5f77ff7b307c5dabafd659990ea04 Mon Sep 17 00:00:00 2001 From: Opender Singh Date: Tue, 4 Jun 2019 06:45:22 +1200 Subject: [PATCH] Download path settings per request (#1544) * Remove from state * Download path to meta * Finished? * Fixed! * Remove props from ResponsePane --- .../insomnia-app/app/models/request-meta.js | 2 ++ .../app/ui/components/request-pane.js | 6 ++++++ .../app/ui/components/request-url-bar.js | 18 +++++++++++------- .../insomnia-app/app/ui/components/wrapper.js | 6 ++++++ packages/insomnia-app/app/ui/containers/app.js | 7 +++++++ 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/packages/insomnia-app/app/models/request-meta.js b/packages/insomnia-app/app/models/request-meta.js index e860847cc0..2c6451733b 100644 --- a/packages/insomnia-app/app/models/request-meta.js +++ b/packages/insomnia-app/app/models/request-meta.js @@ -18,6 +18,7 @@ type BaseRequestMeta = { savedRequestBody: Object, pinned: boolean, lastActive: number, + downloadPath: string | null, }; export type RequestMeta = BaseModel & BaseRequestMeta; @@ -32,6 +33,7 @@ export function init() { savedRequestBody: {}, pinned: false, lastActive: 0, + downloadPath: null, }; } diff --git a/packages/insomnia-app/app/ui/components/request-pane.js b/packages/insomnia-app/app/ui/components/request-pane.js index c5acc71146..04763bd81e 100644 --- a/packages/insomnia-app/app/ui/components/request-pane.js +++ b/packages/insomnia-app/app/ui/components/request-pane.js @@ -42,6 +42,7 @@ type Props = { handleGenerateCode: Function, handleRender: Function, handleGetRenderContext: Function, + handleUpdateDownloadPath: Function, updateRequestUrl: (r: Request, url: string) => Promise, updateRequestMethod: (r: Request, method: string) => Promise, updateRequestBody: (r: Request, body: RequestBody) => Promise, @@ -64,6 +65,7 @@ type Props = { // Optional request: ?Request, + downloadPath: string | null, oAuth2Token: ?OAuth2Token, }; @@ -153,6 +155,7 @@ class RequestPane extends React.PureComponent { handleRender, handleSend, handleSendAndDownload, + handleUpdateDownloadPath, oAuth2Token, request, workspace, @@ -167,6 +170,7 @@ class RequestPane extends React.PureComponent { updateRequestMethod, updateRequestUrl, headerEditorKey, + downloadPath, } = this.props; const paneClasses = 'request-pane theme--pane pane'; @@ -265,6 +269,8 @@ class RequestPane extends React.PureComponent { handleGetRenderContext={handleGetRenderContext} request={request} hotKeyRegistry={settings.hotKeyRegistry} + handleUpdateDownloadPath={handleUpdateDownloadPath} + downloadPath={downloadPath} /> diff --git a/packages/insomnia-app/app/ui/components/request-url-bar.js b/packages/insomnia-app/app/ui/components/request-url-bar.js index 47592cbe59..02ce93af36 100644 --- a/packages/insomnia-app/app/ui/components/request-url-bar.js +++ b/packages/insomnia-app/app/ui/components/request-url-bar.js @@ -28,6 +28,7 @@ type Props = { handleRender: string => Promise, handleSend: () => void, handleSendAndDownload: (filepath?: string) => Promise, + handleUpdateDownloadPath: Function, isVariableUncovered: boolean, nunjucksPowerUserMode: boolean, onMethodChange: (r: Request, method: string) => Promise, @@ -35,12 +36,12 @@ type Props = { request: Request, uniquenessKey: string, hotKeyRegistry: HotKeyRegistry, + downloadPath: string | null, }; type State = { currentInterval: number | null, currentTimeout: number | null, - downloadPath: string | null, }; @autobind @@ -58,7 +59,6 @@ class RequestUrlBar extends React.PureComponent { this.state = { currentInterval: null, currentTimeout: null, - downloadPath: null, }; this._lastPastedText = null; @@ -126,6 +126,8 @@ class RequestUrlBar extends React.PureComponent { } _handleSetDownloadLocation() { + const { request } = this.props; + const options = { title: 'Select Download Location', buttonLabel: 'Select', @@ -137,12 +139,14 @@ class RequestUrlBar extends React.PureComponent { return; } - this.setState({ downloadPath: paths[0] }); + this.props.handleUpdateDownloadPath(request._id, paths[0]); }); } _handleClearDownloadLocation() { - this.setState({ downloadPath: null }); + const { request } = this.props; + + this.props.handleUpdateDownloadPath(request._id, null); } async _handleKeyDown(e: KeyboardEvent) { @@ -170,7 +174,7 @@ class RequestUrlBar extends React.PureComponent { this._handleStopTimeout(); - const { downloadPath } = this.state; + const { downloadPath } = this.props; if (downloadPath) { this.props.handleSendAndDownload(downloadPath); } else { @@ -251,8 +255,8 @@ class RequestUrlBar extends React.PureComponent { } renderSendButton() { - const { hotKeyRegistry } = this.props; - const { currentInterval, currentTimeout, downloadPath } = this.state; + const { hotKeyRegistry, downloadPath } = this.props; + const { currentInterval, currentTimeout } = this.state; let cancelButton = null; if (currentInterval) { diff --git a/packages/insomnia-app/app/ui/components/wrapper.js b/packages/insomnia-app/app/ui/components/wrapper.js index 012c9cafc0..879218a03d 100644 --- a/packages/insomnia-app/app/ui/components/wrapper.js +++ b/packages/insomnia-app/app/ui/components/wrapper.js @@ -105,6 +105,7 @@ type Props = { handleSendRequestWithEnvironment: Function, handleSendAndDownloadRequestWithEnvironment: Function, handleUpdateRequestMimeType: Function, + handleUpdateDownloadPath: Function, // Properties loadStartTime: number, @@ -114,6 +115,7 @@ type Props = { responsePreviewMode: string, responseFilter: string, responseFilterHistory: Array, + responseDownloadPath: string | null, sidebarWidth: number, sidebarHidden: boolean, sidebarFilter: string, @@ -414,6 +416,7 @@ class Wrapper extends React.PureComponent { handleStartDragPaneVertical, handleToggleMenuBar, handleUpdateRequestMimeType, + handleUpdateDownloadPath, headerEditorKey, isLoading, isVariableUncovered, @@ -425,6 +428,7 @@ class Wrapper extends React.PureComponent { responseFilter, responseFilterHistory, responsePreviewMode, + responseDownloadPath, settings, sidebarChildren, sidebarFilter, @@ -714,6 +718,7 @@ class Wrapper extends React.PureComponent { handleImportFile={this._handleImportFile} request={activeRequest} workspace={activeWorkspace} + downloadPath={responseDownloadPath} settings={settings} environmentId={activeEnvironment ? activeEnvironment._id : ''} oAuth2Token={oAuth2Token} @@ -723,6 +728,7 @@ class Wrapper extends React.PureComponent { handleImport={this._handleImport} handleRender={handleRender} handleGetRenderContext={handleGetRenderContext} + handleUpdateDownloadPath={handleUpdateDownloadPath} updateRequestBody={Wrapper._handleUpdateRequestBody} forceUpdateRequestHeaders={this._handleForceUpdateRequestHeaders} updateRequestUrl={Wrapper._handleUpdateRequestUrl} diff --git a/packages/insomnia-app/app/ui/containers/app.js b/packages/insomnia-app/app/ui/containers/app.js index 5e3c9a31d2..4587358433 100644 --- a/packages/insomnia-app/app/ui/containers/app.js +++ b/packages/insomnia-app/app/ui/containers/app.js @@ -477,6 +477,10 @@ class App extends PureComponent { App._updateRequestMetaByParentId(requestId, { previewMode }); } + _handleUpdateDownloadPath(requestId, downloadPath) { + App._updateRequestMetaByParentId(requestId, { downloadPath }); + } + async _handleSetResponseFilter(requestId, responseFilter) { await App._updateRequestMetaByParentId(requestId, { responseFilter }); @@ -1123,6 +1127,7 @@ class App extends PureComponent { handleToggleMenuBar={this._handleToggleMenuBar} handleUpdateRequestMimeType={this._handleUpdateRequestMimeType} handleShowExportRequestsModal={this._handleShowExportRequestsModal} + handleUpdateDownloadPath={this._handleUpdateDownloadPath} isVariableUncovered={isVariableUncovered} headerEditorKey={forceRefreshHeaderCounter + ''} vcs={vcs} @@ -1188,6 +1193,7 @@ function mapStateToProps(state, props) { const responsePreviewMode = requestMeta.previewMode || PREVIEW_MODE_SOURCE; const responseFilter = requestMeta.responseFilter || ''; const responseFilterHistory = requestMeta.responseFilterHistory || []; + const responseDownloadPath = requestMeta.downloadPath || null; // Cookie Jar const activeCookieJar = selectActiveCookieJar(state, props); @@ -1242,6 +1248,7 @@ function mapStateToProps(state, props) { activeEnvironment, workspaceChildren, syncItems, + responseDownloadPath, }); }