mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-21 14:47:46 -04:00
feat: update data model and request-pane to support post-req-script
This commit is contained in:
@@ -576,6 +576,7 @@ export async function getRenderedRequestAndContext(
|
||||
type: renderedRequest.type,
|
||||
url: renderedRequest.url,
|
||||
preRequestScript: renderedRequest.preRequestScript,
|
||||
postRequestScript: renderedRequest.postRequestScript,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ describe('init()', () => {
|
||||
parameters: [],
|
||||
pathParameters: [],
|
||||
preRequestScript: '',
|
||||
postRequestScript: '',
|
||||
url: '',
|
||||
settingStoreCookies: true,
|
||||
settingSendCookies: true,
|
||||
@@ -60,6 +61,7 @@ describe('create()', () => {
|
||||
parameters: [],
|
||||
pathParameters: [],
|
||||
preRequestScript: '',
|
||||
postRequestScript: '',
|
||||
url: '',
|
||||
settingStoreCookies: true,
|
||||
settingSendCookies: true,
|
||||
@@ -394,6 +396,7 @@ describe('migrate()', () => {
|
||||
parameters: [],
|
||||
pathParameters: [],
|
||||
preRequestScript: '',
|
||||
postRequestScript: '',
|
||||
parentId: null,
|
||||
body: {
|
||||
mimeType: '',
|
||||
|
||||
@@ -252,6 +252,7 @@ export interface BaseRequest {
|
||||
method: string;
|
||||
body: RequestBody;
|
||||
preRequestScript: string;
|
||||
postRequestScript: string;
|
||||
parameters: RequestParameter[];
|
||||
pathParameters: RequestPathParameter[];
|
||||
headers: RequestHeader[];
|
||||
@@ -289,6 +290,7 @@ export function init(): BaseRequest {
|
||||
method: METHOD_GET,
|
||||
body: {},
|
||||
preRequestScript: '',
|
||||
postRequestScript: '',
|
||||
parameters: [],
|
||||
headers: [],
|
||||
authentication: {},
|
||||
|
||||
@@ -197,6 +197,7 @@ describe('app.export.*', () => {
|
||||
parameters: [],
|
||||
pathParameters: [],
|
||||
preRequestScript: '',
|
||||
postRequestScript: '',
|
||||
parentId: 'wrk_1',
|
||||
settingDisableRenderRequestBody: false,
|
||||
settingEncodeUrl: true,
|
||||
|
||||
@@ -2,8 +2,8 @@ import { Snippet } from 'codemirror';
|
||||
import { CookieObject, Environment, InsomniaObject, Request as ScriptRequest, RequestInfo, Url, Variables } from 'insomnia-sdk';
|
||||
import React, { FC, Fragment, useRef } from 'react';
|
||||
|
||||
import { translateHandlersInScript } from '../../../../src/utils/importers/importers/postman';
|
||||
import { Settings } from '../../../models/settings';
|
||||
import { translateHandlersInScript } from '../../../utils/importers/importers/postman';
|
||||
import { Dropdown, DropdownButton, DropdownItem, DropdownSection, ItemContent } from '../base/dropdown';
|
||||
import { CodeEditor, CodeEditorHandle } from '../codemirror/code-editor';
|
||||
|
||||
@@ -80,7 +80,7 @@ const lintOptions = {
|
||||
// TODO: introduce this functionality for other objects, such as Url, UrlMatchPattern and so on
|
||||
// TODO: introduce function arguments
|
||||
// TODO: provide snippets for environment keys if possible
|
||||
function getPreRequestScriptSnippets(insomniaObject: InsomniaObject, path: string): Snippet[] {
|
||||
function getRequestScriptSnippets(insomniaObject: InsomniaObject, path: string): Snippet[] {
|
||||
let snippets: Snippet[] = [];
|
||||
|
||||
const refs = new Set();
|
||||
@@ -117,17 +117,17 @@ function getPreRequestScriptSnippets(insomniaObject: InsomniaObject, path: strin
|
||||
});
|
||||
} else if (Array.isArray(value)) {
|
||||
for (const item of value) {
|
||||
snippets = snippets.concat(getPreRequestScriptSnippets(item, `${path}.${key}`));
|
||||
snippets = snippets.concat(getRequestScriptSnippets(item, `${path}.${key}`));
|
||||
}
|
||||
} else {
|
||||
snippets = snippets.concat(getPreRequestScriptSnippets(value, `${path}.${key}`));
|
||||
snippets = snippets.concat(getRequestScriptSnippets(value, `${path}.${key}`));
|
||||
}
|
||||
}
|
||||
|
||||
return snippets;
|
||||
}
|
||||
|
||||
export const PreRequestScriptEditor: FC<Props> = ({
|
||||
export const RequestScriptEditor: FC<Props> = ({
|
||||
className,
|
||||
defaultValue,
|
||||
onChange,
|
||||
@@ -154,7 +154,7 @@ export const PreRequestScriptEditor: FC<Props> = ({
|
||||
};
|
||||
|
||||
// TODO(george): Add more to this object to provide improved autocomplete
|
||||
const preRequestScriptSnippets = getPreRequestScriptSnippets(
|
||||
const requestScriptSnippets = getRequestScriptSnippets(
|
||||
new InsomniaObject({
|
||||
globals: new Environment('globals', {}),
|
||||
iterationData: new Environment('iterationData', {}),
|
||||
@@ -199,8 +199,8 @@ export const PreRequestScriptEditor: FC<Props> = ({
|
||||
<Fragment>
|
||||
<div className="h-[calc(100%-var(--line-height-xs))]">
|
||||
<CodeEditor
|
||||
id={`script-editor-${uniquenessKey}`}
|
||||
key={uniquenessKey}
|
||||
id="pre-request-script-editor"
|
||||
showPrettifyButton={true}
|
||||
uniquenessKey={uniquenessKey}
|
||||
defaultValue={defaultValue}
|
||||
@@ -211,7 +211,7 @@ export const PreRequestScriptEditor: FC<Props> = ({
|
||||
placeholder="..."
|
||||
lintOptions={lintOptions}
|
||||
ref={editorRef}
|
||||
getAutocompleteSnippets={() => preRequestScriptSnippets}
|
||||
getAutocompleteSnippets={() => requestScriptSnippets}
|
||||
onPaste={translateHandlersInScript}
|
||||
/>
|
||||
</div>
|
||||
@@ -20,9 +20,9 @@ import { AuthDropdown } from '../dropdowns/auth-dropdown';
|
||||
import { ContentTypeDropdown } from '../dropdowns/content-type-dropdown';
|
||||
import { AuthWrapper } from '../editors/auth/auth-wrapper';
|
||||
import { BodyEditor } from '../editors/body/body-editor';
|
||||
import { PreRequestScriptEditor } from '../editors/pre-request-script-editor';
|
||||
import { RequestHeadersEditor } from '../editors/request-headers-editor';
|
||||
import { RequestParametersEditor } from '../editors/request-parameters-editor';
|
||||
import { RequestScriptEditor } from '../editors/request-script-editor';
|
||||
import { ErrorBoundary } from '../error-boundary';
|
||||
import { Icon } from '../icon';
|
||||
import { MarkdownPreview } from '../markdown-preview';
|
||||
@@ -318,7 +318,7 @@ export const RequestPane: FC<Props> = ({
|
||||
key={uniqueKey}
|
||||
errorClassName="tall wide vertically-align font-error pad text-center"
|
||||
>
|
||||
<PreRequestScriptEditor
|
||||
<RequestScriptEditor
|
||||
uniquenessKey={uniqueKey}
|
||||
defaultValue={activeRequest.preRequestScript || ''}
|
||||
onChange={preRequestScript => patchRequest(requestId, { preRequestScript })}
|
||||
@@ -326,6 +326,33 @@ export const RequestPane: FC<Props> = ({
|
||||
/>
|
||||
</ErrorBoundary>
|
||||
</TabItem>
|
||||
<TabItem
|
||||
key="post-request-script"
|
||||
data-testid="post-request-script-tab"
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
Post-request Script{' '}
|
||||
{activeRequest.postRequestScript && (
|
||||
<span className="ml-2 p-2 border-solid border border-[--hl-md] rounded-lg">
|
||||
<span className="flex w-2 h-2 bg-green-500 rounded-full" />
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
aria-label={'experimental'}
|
||||
>
|
||||
<ErrorBoundary
|
||||
key={uniqueKey}
|
||||
errorClassName="tall wide vertically-align font-error pad text-center"
|
||||
>
|
||||
<RequestScriptEditor
|
||||
uniquenessKey={uniqueKey}
|
||||
defaultValue={activeRequest.postRequestScript || ''}
|
||||
onChange={postRequestScript => patchRequest(requestId, { postRequestScript })}
|
||||
settings={settings}
|
||||
/>
|
||||
</ErrorBoundary>
|
||||
</TabItem>
|
||||
<TabItem
|
||||
key="docs"
|
||||
title={
|
||||
|
||||
@@ -78,6 +78,7 @@ export interface ImportRequest<T extends {} = {}> extends Comment {
|
||||
queryString?: QueryString[];
|
||||
url?: string;
|
||||
preRequestScript?: string;
|
||||
postRequestScript?: string;
|
||||
metaSortKey?: number;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user