From 8bd22fc9066dcd472707f9648ef6c7f65e6b9ba2 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Tue, 9 Apr 2024 18:50:17 +0300 Subject: [PATCH] RED-8692 - Automatic code validation in the rule editor --- .../rules/rules-screen/rules-screen.component.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen/rules-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen/rules-screen.component.ts index 174fdaea8..7ee016d00 100644 --- a/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen/rules-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen/rules-screen.component.ts @@ -17,7 +17,7 @@ interface SyntaxError { line: number; column: number; message: string; - warning: boolean; + warning?: boolean; } interface UploadResponse { @@ -43,6 +43,7 @@ export class RulesScreenComponent implements OnInit, ComponentCanDeactivate { automaticLayout: true, readOnly: !this.permissionsService.canEditRules(), glyphMargin: true, + fixedOverflowWidgets: true, }; initialLines: string[] = []; currentLines: string[] = []; @@ -151,10 +152,18 @@ export class RulesScreenComponent implements OnInit, ComponentCanDeactivate { } }, error => { - const errors = this.#mapErrors(error.error); + let errors: SyntaxError[]; + if (error.error?.syntaxErrorMessages) { + errors = this.#mapErrors(error.error); + } else { + const syntaxError: SyntaxError = { message: error.error.message, line: 1, column: 0 }; + errors = this.#mapErrors({ blacklistErrorMessages: [], syntaxErrorMessages: [syntaxError], deprecatedWarnings: [] }); + } this.#drawErrorMarkers(errors); this._loadingService.stop(); - this._toaster.error(rulesScreenTranslations[this.type]['error.generic']); + if (!dryRun) { + this._toaster.error(rulesScreenTranslations[this.type]['error.generic']); + } }, ); } @@ -252,6 +261,7 @@ export class RulesScreenComponent implements OnInit, ComponentCanDeactivate { }, }); }); + this.#errors.set(errors); this.#errorGlyphs.set(this.#codeEditor.deltaDecorations(this.#errorGlyphs(), glyphs)); (window as any).monaco.editor.setModelMarkers(model, model.id, markers);