Download path settings per request (#1544)

* Remove from state

* Download path to meta

* Finished?

* Fixed!

* Remove props from ResponsePane
This commit is contained in:
Opender Singh
2019-06-04 06:45:22 +12:00
committed by Gregory Schier
parent 45c1936fa8
commit 5d82a5ec95
5 changed files with 32 additions and 7 deletions

View File

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

View File

@@ -42,6 +42,7 @@ type Props = {
handleGenerateCode: Function,
handleRender: Function,
handleGetRenderContext: Function,
handleUpdateDownloadPath: Function,
updateRequestUrl: (r: Request, url: string) => Promise<Request>,
updateRequestMethod: (r: Request, method: string) => Promise<Request>,
updateRequestBody: (r: Request, body: RequestBody) => Promise<Request>,
@@ -64,6 +65,7 @@ type Props = {
// Optional
request: ?Request,
downloadPath: string | null,
oAuth2Token: ?OAuth2Token,
};
@@ -153,6 +155,7 @@ class RequestPane extends React.PureComponent<Props> {
handleRender,
handleSend,
handleSendAndDownload,
handleUpdateDownloadPath,
oAuth2Token,
request,
workspace,
@@ -167,6 +170,7 @@ class RequestPane extends React.PureComponent<Props> {
updateRequestMethod,
updateRequestUrl,
headerEditorKey,
downloadPath,
} = this.props;
const paneClasses = 'request-pane theme--pane pane';
@@ -265,6 +269,8 @@ class RequestPane extends React.PureComponent<Props> {
handleGetRenderContext={handleGetRenderContext}
request={request}
hotKeyRegistry={settings.hotKeyRegistry}
handleUpdateDownloadPath={handleUpdateDownloadPath}
downloadPath={downloadPath}
/>
</ErrorBoundary>
</header>

View File

@@ -28,6 +28,7 @@ type Props = {
handleRender: string => Promise<string>,
handleSend: () => void,
handleSendAndDownload: (filepath?: string) => Promise<void>,
handleUpdateDownloadPath: Function,
isVariableUncovered: boolean,
nunjucksPowerUserMode: boolean,
onMethodChange: (r: Request, method: string) => Promise<Request>,
@@ -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<Props, State> {
this.state = {
currentInterval: null,
currentTimeout: null,
downloadPath: null,
};
this._lastPastedText = null;
@@ -126,6 +126,8 @@ class RequestUrlBar extends React.PureComponent<Props, State> {
}
_handleSetDownloadLocation() {
const { request } = this.props;
const options = {
title: 'Select Download Location',
buttonLabel: 'Select',
@@ -137,12 +139,14 @@ class RequestUrlBar extends React.PureComponent<Props, State> {
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<Props, State> {
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<Props, State> {
}
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) {

View File

@@ -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<string>,
responseDownloadPath: string | null,
sidebarWidth: number,
sidebarHidden: boolean,
sidebarFilter: string,
@@ -414,6 +416,7 @@ class Wrapper extends React.PureComponent<Props, State> {
handleStartDragPaneVertical,
handleToggleMenuBar,
handleUpdateRequestMimeType,
handleUpdateDownloadPath,
headerEditorKey,
isLoading,
isVariableUncovered,
@@ -425,6 +428,7 @@ class Wrapper extends React.PureComponent<Props, State> {
responseFilter,
responseFilterHistory,
responsePreviewMode,
responseDownloadPath,
settings,
sidebarChildren,
sidebarFilter,
@@ -714,6 +718,7 @@ class Wrapper extends React.PureComponent<Props, State> {
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<Props, State> {
handleImport={this._handleImport}
handleRender={handleRender}
handleGetRenderContext={handleGetRenderContext}
handleUpdateDownloadPath={handleUpdateDownloadPath}
updateRequestBody={Wrapper._handleUpdateRequestBody}
forceUpdateRequestHeaders={this._handleForceUpdateRequestHeaders}
updateRequestUrl={Wrapper._handleUpdateRequestUrl}

View File

@@ -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,
});
}