Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added post request scripts.
- Loading branch information
Showing
35 changed files
with
1,524 additions
and
971 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
### Fixes # | ||
|
||
... | ||
<!-- Mention the issues this PR addresses --> | ||
|
||
### Checks | ||
|
||
- [ ] Ran `yarn test-build` | ||
- [ ] Updated relevant documentations | ||
|
||
### Changes proposed in this pull request: | ||
|
||
- | ||
- | ||
- | ||
<!-- Describe the changes being introduced in this PR --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...pp/components/post-request-editor/__snapshots__/pre-request-editor.component.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`PreRequestEditorComponent should render correctly 1`] = ` | ||
<app-pre-request-editor> | ||
<div | ||
class="pre-request-editor" | ||
> | ||
<div | ||
class="pre-request-editor__toggle-wrapper" | ||
> | ||
<label | ||
nz-checkbox="" | ||
> | ||
</label> | ||
</div> | ||
<ngx-codemirror | ||
class="pre-request-textarea mousetrap" | ||
/> | ||
<small> | ||
<a | ||
href="https://altair.sirmuel.design/docs/features/prerequest-scripts.html" | ||
target="_blank" | ||
> | ||
<app-icon | ||
name="info" | ||
/> | ||
</a> | ||
</small> | ||
</div> | ||
</app-pre-request-editor> | ||
`; |
23 changes: 23 additions & 0 deletions
23
...ages/altair-app/src/app/components/post-request-editor/post-request-editor.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div class="post-request-editor"> | ||
<div class="post-request-editor__toggle-wrapper spacer--small"> | ||
<label | ||
nz-checkbox | ||
[ngModel]="postRequest?.enabled" | ||
(ngModelChange)="postRequestEnabledChange.next($event)" | ||
>{{ 'REQUEST_SCRIPT_ENABLE_TEXT' | translate }}</label> | ||
</div> | ||
<ngx-codemirror | ||
#editor | ||
class="post-request-textarea mousetrap" | ||
[options]="postRequestEditorConfig" | ||
[ngModel]="postRequest?.script" | ||
(ngModelChange)="postRequestScriptChange.emit($event)" | ||
></ngx-codemirror> | ||
|
||
<small> | ||
<a href="https://altair.sirmuel.design/docs/features/prerequest-scripts.html" target="_blank"> | ||
<app-icon name="info"></app-icon> | ||
{{ 'LEARN_MORE_TEXT' | translate }} | ||
</a> | ||
</small> | ||
</div> |
35 changes: 35 additions & 0 deletions
35
...s/altair-app/src/app/components/post-request-editor/post-request-editor.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { expect, describe, it } from '@jest/globals'; | ||
|
||
import { PostRequestEditorComponent } from './post-request-editor.component'; | ||
import { SharedModule } from 'app/modules/shared/shared.module'; | ||
import { NO_ERRORS_SCHEMA } from '@angular/core'; | ||
import { NgxTestWrapper, mount } from '../../../testing'; | ||
import { MockModule } from 'ng-mocks'; | ||
|
||
describe('PostRequestEditorComponent', () => { | ||
let wrapper: NgxTestWrapper<PostRequestEditorComponent>; | ||
|
||
beforeEach(async() => { | ||
wrapper = await mount({ | ||
component: PostRequestEditorComponent, | ||
imports: [ | ||
MockModule(SharedModule), | ||
], | ||
schemas: [ NO_ERRORS_SCHEMA ], | ||
propsData: { | ||
preRequest: { | ||
enabled: true, | ||
script: '', | ||
} | ||
}, | ||
}); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(wrapper.componentInstance).toBeTruthy(); | ||
}); | ||
|
||
it('should render correctly', () => { | ||
expect(wrapper.element).toMatchSnapshot(); | ||
}); | ||
}); |
119 changes: 119 additions & 0 deletions
119
packages/altair-app/src/app/components/post-request-editor/post-request-editor.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { | ||
Component, | ||
OnChanges, | ||
EventEmitter, | ||
Input, | ||
Output, | ||
ViewChild, | ||
ElementRef, | ||
DoCheck, | ||
AfterViewInit | ||
} from '@angular/core'; | ||
|
||
// Import the codemirror packages | ||
import * as Codemirror from 'codemirror'; | ||
import 'codemirror/addon/hint/show-hint'; | ||
import 'codemirror/addon/hint/javascript-hint'; | ||
import 'codemirror/addon/lint/lint'; | ||
import 'codemirror/addon/fold/foldcode'; | ||
import 'codemirror/addon/fold/foldgutter'; | ||
import 'codemirror/addon/fold/brace-fold'; | ||
import 'codemirror/addon/fold/indent-fold'; | ||
// import 'codemirror/addon/display/autorefresh'; | ||
import 'codemirror/keymap/sublime'; | ||
import 'codemirror/mode/javascript/javascript'; | ||
import { handleEditorRefresh } from 'app/utils/codemirror/refresh-editor'; | ||
|
||
const AUTOCOMPLETE_CHARS = /^[a-zA-Z0-9_]$/; | ||
|
||
@Component({ | ||
selector: 'app-post-request-editor', | ||
templateUrl: './post-request-editor.component.html', | ||
styles: [] | ||
}) | ||
export class PostRequestEditorComponent implements AfterViewInit, OnChanges, DoCheck { | ||
|
||
@Input() postRequest: any = {}; | ||
@Output() postRequestScriptChange = new EventEmitter(); | ||
@Output() postRequestEnabledChange = new EventEmitter(); | ||
|
||
@ViewChild('editor', { static: true }) editor: ElementRef & { codeMirror: CodeMirror.Editor }; | ||
|
||
postRequestEditorConfig = { | ||
mode: 'javascript', | ||
lineWrapping: true, | ||
lineNumbers: true, | ||
foldGutter: true, | ||
autoRefresh: true, | ||
dragDrop: false, | ||
autoCloseBrackets: true, | ||
keyMap: 'sublime', | ||
theme: 'default request-script-editor mousetrap', | ||
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'], | ||
extraKeys: { | ||
'Ctrl-Space': 'autocomplete', | ||
'Cmd-/': (cm: CodeMirror.Editor) => cm.execCommand('toggleComment'), | ||
'Ctrl-/': (cm: CodeMirror.Editor) => cm.execCommand('toggleComment'), | ||
}, | ||
hintOptions: { | ||
completeSingle: false, | ||
globalScope: this.createGlobalScope(), | ||
}, | ||
}; | ||
|
||
constructor() {} | ||
|
||
ngAfterViewInit() { | ||
if (this.editor?.codeMirror) { | ||
(this.editor.codeMirror as any).on('keyup', (cm: CodeMirror.Editor, event: KeyboardEvent) => this.onKeyUp(cm, event)); | ||
} | ||
} | ||
|
||
ngOnChanges() { | ||
} | ||
|
||
ngDoCheck() { | ||
// Refresh the query result editor view when there are any changes | ||
// to fix any broken UI issues in it | ||
handleEditorRefresh(this.editor && this.editor.codeMirror); | ||
} | ||
|
||
/** | ||
* Handles the keyup event on the query editor | ||
* @param cm | ||
* @param event | ||
*/ | ||
onKeyUp(cm: CodeMirror.Editor, event: KeyboardEvent) { | ||
if (AUTOCOMPLETE_CHARS.test(event.key)) { | ||
this.editor.codeMirror.execCommand('autocomplete'); | ||
} | ||
} | ||
|
||
private createGlobalScope() { | ||
const xy = { | ||
altair: { | ||
helpers: { | ||
getEnvironment: null, | ||
setEnvironment: null, | ||
getCookie: null, | ||
request: null | ||
}, | ||
importModule: null, | ||
response: { | ||
requestType: null, | ||
responseTime: null, | ||
statusCode: null, | ||
body: null, | ||
headers: null, | ||
}, | ||
} | ||
}; | ||
|
||
return JSON.parse(JSON.stringify(xy), (k, v) => { | ||
if (v && typeof v === 'object' && !Array.isArray(v)) { | ||
return Object.assign(Object.create(null), v); | ||
} | ||
return v; | ||
}); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/altair-app/src/app/components/pre-request-editor/pre-request-editor.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.