mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Configurable response history length
This commit is contained in:
parent
e145ca8146
commit
a472443b0c
@ -130,8 +130,6 @@ export async function create(patch: Object = {}, maxResponses: number = 20) {
|
||||
|
||||
const { parentId } = patch;
|
||||
|
||||
const settings = await models.settings.getOrCreate();
|
||||
|
||||
// Create request version snapshot
|
||||
const request = await models.request.getById(parentId);
|
||||
const requestVersion = request ? await models.requestVersion.create(request) : null;
|
||||
@ -141,7 +139,7 @@ export async function create(patch: Object = {}, maxResponses: number = 20) {
|
||||
const allResponses = await db.findMostRecentlyModified(
|
||||
type,
|
||||
{ parentId },
|
||||
settings.maxHistoryResponses,
|
||||
Math.max(1, maxResponses),
|
||||
);
|
||||
const recentIds = allResponses.map(r => r._id);
|
||||
await db.removeWhere(type, { parentId, _id: { $nin: recentIds } });
|
||||
|
@ -68,7 +68,6 @@ class GraphQLEditor extends React.PureComponent<Props, State> {
|
||||
_isMounted: boolean;
|
||||
_queryEditor: null | CodeMirror;
|
||||
_schemaFetchTimeout: TimeoutID;
|
||||
_highlightTimeout: TimeoutID;
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
@ -559,23 +558,22 @@ class GraphQLEditor extends React.PureComponent<Props, State> {
|
||||
/>
|
||||
</div>
|
||||
<div className="graphql-editor__schema-error">
|
||||
{!hideSchemaFetchErrors &&
|
||||
schemaFetchError && (
|
||||
<div className="notice error margin no-margin-top margin-bottom-sm">
|
||||
<div className="pull-right">
|
||||
<Tooltip position="top" message="View introspection request/response timeline">
|
||||
<button className="icon icon--success" onClick={this._handleViewResponse}>
|
||||
<i className="fa fa-bug" />
|
||||
</button>
|
||||
</Tooltip>{' '}
|
||||
<button className="icon" onClick={this._hideSchemaFetchError}>
|
||||
<i className="fa fa-times" />
|
||||
{!hideSchemaFetchErrors && schemaFetchError && (
|
||||
<div className="notice error margin no-margin-top margin-bottom-sm">
|
||||
<div className="pull-right">
|
||||
<Tooltip position="top" message="View introspection request/response timeline">
|
||||
<button className="icon icon--success" onClick={this._handleViewResponse}>
|
||||
<i className="fa fa-bug" />
|
||||
</button>
|
||||
</div>
|
||||
{schemaFetchError.message}
|
||||
<br />
|
||||
</Tooltip>{' '}
|
||||
<button className="icon" onClick={this._hideSchemaFetchError}>
|
||||
<i className="fa fa-times" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{schemaFetchError.message}
|
||||
<br />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="graphql-editor__meta">
|
||||
{this.renderSchemaFetchMessage()}
|
||||
@ -584,7 +582,8 @@ class GraphQLEditor extends React.PureComponent<Props, State> {
|
||||
<h2 className="no-margin pad-left-sm pad-top-sm pad-bottom-sm">
|
||||
Query Variables
|
||||
<HelpTooltip className="space-left">
|
||||
Variables to use in GraphQL query <br />(JSON format)
|
||||
Variables to use in GraphQL query <br />
|
||||
(JSON format)
|
||||
</HelpTooltip>
|
||||
{variablesSyntaxError && (
|
||||
<span className="text-danger italic pull-right">{variablesSyntaxError}</span>
|
||||
|
@ -222,19 +222,6 @@ class General extends React.PureComponent<Props, State> {
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="form-control form-control--outlined">
|
||||
<label className="inline-block">
|
||||
Max history responses
|
||||
<input
|
||||
type="number"
|
||||
name="maxHistoryResponses"
|
||||
min={1}
|
||||
defaultValue={settings.maxHistoryResponses}
|
||||
onChange={this._handleUpdateSetting}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="form-row">
|
||||
<div className="form-control form-control--outlined pad-top-sm">
|
||||
<label>
|
||||
@ -370,14 +357,7 @@ class General extends React.PureComponent<Props, State> {
|
||||
|
||||
<hr className="pad-top" />
|
||||
|
||||
<h2>
|
||||
HTTP Network Proxy
|
||||
<HelpTooltip
|
||||
className="space-left txt-md"
|
||||
style={{ maxWidth: '20rem', lineWrap: 'word' }}>
|
||||
Enable global network proxy. Supports authentication via Basic Auth, digest, or NTLM
|
||||
</HelpTooltip>
|
||||
</h2>
|
||||
<h2>Request Settings</h2>
|
||||
|
||||
<div className="form-row">
|
||||
<div className="form-control form-control--outlined">
|
||||
@ -411,6 +391,22 @@ class General extends React.PureComponent<Props, State> {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-control form-control--outlined">
|
||||
<label>
|
||||
Response History Limit
|
||||
<HelpTooltip className="space-left">
|
||||
Number of responses to keep for each request
|
||||
</HelpTooltip>
|
||||
<input
|
||||
type="number"
|
||||
name="maxHistoryResponses"
|
||||
min={1}
|
||||
defaultValue={settings.maxHistoryResponses}
|
||||
onChange={this._handleUpdateSetting}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<hr className="pad-top" />
|
||||
|
||||
<h2>
|
||||
|
@ -493,6 +493,8 @@ class App extends PureComponent {
|
||||
}
|
||||
|
||||
async _handleSendAndDownloadRequestWithEnvironment(requestId, environmentId, dir) {
|
||||
const { settings, handleStartLoading, handleStopLoading } = this.props;
|
||||
|
||||
const request = await models.request.getById(requestId);
|
||||
if (!request) {
|
||||
return;
|
||||
@ -506,7 +508,7 @@ class App extends PureComponent {
|
||||
}
|
||||
|
||||
// Start loading
|
||||
this.props.handleStartLoading(requestId);
|
||||
handleStartLoading(requestId);
|
||||
|
||||
try {
|
||||
const responsePatch = await network.send(requestId, environmentId);
|
||||
@ -541,12 +543,12 @@ class App extends PureComponent {
|
||||
|
||||
readStream.on('end', async () => {
|
||||
responsePatch.error = `Saved to ${filename}`;
|
||||
await models.response.create(responsePatch);
|
||||
await models.response.create(responsePatch, settings.maxHistoryResponses);
|
||||
});
|
||||
|
||||
readStream.on('error', async err => {
|
||||
console.warn('Failed to download request after sending', responsePatch.bodyPath, err);
|
||||
await models.response.create(responsePatch);
|
||||
await models.response.create(responsePatch, settings.maxHistoryResponses);
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
@ -569,10 +571,11 @@ class App extends PureComponent {
|
||||
});
|
||||
|
||||
// Stop loading
|
||||
this.props.handleStopLoading(requestId);
|
||||
handleStopLoading(requestId);
|
||||
}
|
||||
|
||||
async _handleSendRequestWithEnvironment(requestId, environmentId) {
|
||||
const { handleStartLoading, handleStopLoading, settings } = this.props;
|
||||
const request = await models.request.getById(requestId);
|
||||
if (!request) {
|
||||
return;
|
||||
@ -585,11 +588,11 @@ class App extends PureComponent {
|
||||
this._sendRequestTrackingKey = key;
|
||||
}
|
||||
|
||||
this.props.handleStartLoading(requestId);
|
||||
handleStartLoading(requestId);
|
||||
|
||||
try {
|
||||
const responsePatch = await network.send(requestId, environmentId);
|
||||
await models.response.create(responsePatch);
|
||||
await models.response.create(responsePatch, settings.maxHistoryResponses);
|
||||
} catch (err) {
|
||||
if (err.type === 'render') {
|
||||
showModal(RequestRenderErrorModal, { request, error: err });
|
||||
@ -614,7 +617,7 @@ class App extends PureComponent {
|
||||
});
|
||||
|
||||
// Stop loading
|
||||
this.props.handleStopLoading(requestId);
|
||||
handleStopLoading(requestId);
|
||||
}
|
||||
|
||||
async _handleSetActiveResponse(requestId, activeResponse = null) {
|
||||
|
Loading…
Reference in New Issue
Block a user