mirror of
https://github.com/Kong/insomnia.git
synced 2026-10-27 00:59:18 -04:00
Add ability to delete current response
This commit is contained in:
1 parent
5597d331ed
commit
ff58ff7e51
4 files changed
+46
-2
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<Dropdown {...extraProps}>
|
||||
<Dropdown key={activeResponseId} {...extraProps}>
|
||||
<DropdownButton className="btn btn--super-compact tall">
|
||||
{isLatestResponseActive
|
||||
? <i className="fa fa-history"/>
|
||||
: <i className="fa fa-thumb-tack"/>}
|
||||
</DropdownButton>
|
||||
<DropdownDivider>Response History</DropdownDivider>
|
||||
<DropdownItem buttonClass={PromptButton}
|
||||
addIcon
|
||||
onClick={this._handleDeleteResponse}>
|
||||
<i className="fa fa-trash-o"/>
|
||||
Delete Current Response
|
||||
</DropdownItem>
|
||||
<DropdownItem buttonClass={PromptButton}
|
||||
addIcon
|
||||
onClick={this._handleDeleteResponses}>
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
|
||||
|
||||
Reference in new issue
Block a user