diff --git a/app/models/response.js b/app/models/response.js index 78b66d900d..f1cdf7e4c8 100644 --- a/app/models/response.js +++ b/app/models/response.js @@ -43,6 +43,10 @@ export async function removeForRequest (parentId) { db.removeBulkSilently(type, {parentId}); } +export function remove (request) { + return db.remove(request); +} + export function findRecentForRequest (requestId, limit) { return db.findMostRecentlyModified(type, {parentId: requestId}, limit); } diff --git a/app/ui/components/dropdowns/response-history-dropdown.js b/app/ui/components/dropdowns/response-history-dropdown.js index e37535d0c9..b0346ceb46 100644 --- a/app/ui/components/dropdowns/response-history-dropdown.js +++ b/app/ui/components/dropdowns/response-history-dropdown.js @@ -23,6 +23,11 @@ class ResponseHistoryDropdown extends PureComponent { this.props.handleDeleteResponses(this.props.requestId); } + _handleDeleteResponse () { + trackEvent('History', 'Delete Response'); + this.props.handleDeleteResponse(this.props.activeResponseId); + } + _handleSetActiveResponse (responseId) { trackEvent('History', 'Activate Response'); this.props.handleSetActiveResponse(responseId); @@ -80,19 +85,29 @@ class ResponseHistoryDropdown extends PureComponent { activeResponseId, // eslint-disable-line no-unused-vars handleSetActiveResponse, // eslint-disable-line no-unused-vars handleDeleteResponses, // eslint-disable-line no-unused-vars + handleDeleteResponse, // eslint-disable-line no-unused-vars isLatestResponseActive, ...extraProps } = this.props; - const {responses} = this.state; + + const { + responses + } = this.state; return ( - + {isLatestResponseActive ? : } Response History + + + Delete Current Response + @@ -109,6 +124,7 @@ class ResponseHistoryDropdown extends PureComponent { ResponseHistoryDropdown.propTypes = { handleSetActiveResponse: PropTypes.func.isRequired, handleDeleteResponses: PropTypes.func.isRequired, + handleDeleteResponse: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired, requestId: PropTypes.string.isRequired, activeResponseId: PropTypes.string.isRequired, diff --git a/app/ui/components/response-pane.js b/app/ui/components/response-pane.js index c3d6535a40..4b2e665338 100644 --- a/app/ui/components/response-pane.js +++ b/app/ui/components/response-pane.js @@ -141,6 +141,7 @@ class ResponsePane extends PureComponent { handleSetPreviewMode, handleSetActiveResponse, handleDeleteResponses, + handleDeleteResponse, handleSetFilter, loadStartTime, editorLineWrapping, @@ -229,6 +230,7 @@ class ResponsePane extends PureComponent { activeResponseId={response._id} handleSetActiveResponse={handleSetActiveResponse} handleDeleteResponses={handleDeleteResponses} + handleDeleteResponse={handleDeleteResponse} onChange={nullFn} className="tall pane__header__right" right @@ -338,6 +340,7 @@ ResponsePane.propTypes = { handleSetPreviewMode: PropTypes.func.isRequired, handleSetActiveResponse: PropTypes.func.isRequired, handleDeleteResponses: PropTypes.func.isRequired, + handleDeleteResponse: PropTypes.func.isRequired, handleShowRequestSettings: PropTypes.func.isRequired, // Required diff --git a/app/ui/components/wrapper.js b/app/ui/components/wrapper.js index 67098a6d37..fd7eb1a7de 100644 --- a/app/ui/components/wrapper.js +++ b/app/ui/components/wrapper.js @@ -162,6 +162,26 @@ class Wrapper extends PureComponent { this._handleSetActiveResponse(null); } + async _handleDeleteResponse (responseId) { + let response; + if (responseId) { + response = await models.response.getById(responseId); + } else { + const {activeRequest} = this.props; + const requestId = activeRequest ? activeRequest._id : 'n/a'; + response = await models.response.getLatestForRequestId(requestId); + } + + if (response) { + await models.response.remove(response); + } + + // Also unset active response it's the one we're deleting + if (this.props.activeResponseId === response._id) { + this._handleSetActiveResponse(null); + } + } + async _handleRemoveActiveWorkspace () { const {workspaces, activeWorkspace} = this.props; if (workspaces.length <= 1) { @@ -377,6 +397,7 @@ class Wrapper extends PureComponent { handleSetActiveResponse={this._handleSetActiveResponse} handleSetPreviewMode={this._handleSetPreviewMode} handleDeleteResponses={this._handleDeleteResponses} + handleDeleteResponse={this._handleDeleteResponse} handleSetFilter={this._handleSetResponseFilter} />