From 5706041f468c0c445288a34c596bbdc9d87f9c34 Mon Sep 17 00:00:00 2001 From: kalutkaz Date: Mon, 18 Apr 2022 11:50:26 +0300 Subject: [PATCH 1/5] Changed validation logic for JSON editor --- .../src/app/shared/components/json-object-edit.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/shared/components/json-object-edit.component.ts b/ui-ngx/src/app/shared/components/json-object-edit.component.ts index e7a1b97cad..35f9e1e623 100644 --- a/ui-ngx/src/app/shared/components/json-object-edit.component.ts +++ b/ui-ngx/src/app/shared/components/json-object-edit.component.ts @@ -22,7 +22,7 @@ import { ActionNotificationHide, ActionNotificationShow } from '@core/notificati import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { CancelAnimationFrame, RafService } from '@core/services/raf.service'; -import { guid, isDefinedAndNotNull, isLiteralObject, isUndefined } from '@core/utils'; +import { guid, isDefinedAndNotNull, isUndefined } from '@core/utils'; import { ResizeObserver } from '@juggle/resize-observer'; import { getAce } from '@shared/models/ace/ace.models'; @@ -259,7 +259,7 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va if (this.contentValue && this.contentValue.length > 0) { try { data = JSON.parse(this.contentValue); - if (!isLiteralObject(data)) { + if (typeof data !== 'object') { throw new TypeError(`Value is not a valid JSON`); } this.objectValid = true; From 22a8cc624502a9d3c00fa155a05b5171e5f2b238 Mon Sep 17 00:00:00 2001 From: kalutkaz Date: Tue, 19 Apr 2022 13:46:40 +0300 Subject: [PATCH 2/5] Refactoring --- .../src/app/shared/components/json-object-edit.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/shared/components/json-object-edit.component.ts b/ui-ngx/src/app/shared/components/json-object-edit.component.ts index 35f9e1e623..7d829115af 100644 --- a/ui-ngx/src/app/shared/components/json-object-edit.component.ts +++ b/ui-ngx/src/app/shared/components/json-object-edit.component.ts @@ -22,7 +22,7 @@ import { ActionNotificationHide, ActionNotificationShow } from '@core/notificati import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { CancelAnimationFrame, RafService } from '@core/services/raf.service'; -import { guid, isDefinedAndNotNull, isUndefined } from '@core/utils'; +import {guid, isDefinedAndNotNull, isObject, isUndefined} from '@core/utils'; import { ResizeObserver } from '@juggle/resize-observer'; import { getAce } from '@shared/models/ace/ace.models'; @@ -259,7 +259,7 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va if (this.contentValue && this.contentValue.length > 0) { try { data = JSON.parse(this.contentValue); - if (typeof data !== 'object') { + if (!isObject(data)) { throw new TypeError(`Value is not a valid JSON`); } this.objectValid = true; From 2860c914e10ba5ab4745a63d4b2b31991d1464c2 Mon Sep 17 00:00:00 2001 From: kalutkaz Date: Tue, 19 Apr 2022 13:47:37 +0300 Subject: [PATCH 3/5] Refactoring --- ui-ngx/src/app/shared/components/json-object-edit.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ngx/src/app/shared/components/json-object-edit.component.ts b/ui-ngx/src/app/shared/components/json-object-edit.component.ts index 7d829115af..919dbace34 100644 --- a/ui-ngx/src/app/shared/components/json-object-edit.component.ts +++ b/ui-ngx/src/app/shared/components/json-object-edit.component.ts @@ -22,7 +22,7 @@ import { ActionNotificationHide, ActionNotificationShow } from '@core/notificati import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { CancelAnimationFrame, RafService } from '@core/services/raf.service'; -import {guid, isDefinedAndNotNull, isObject, isUndefined} from '@core/utils'; +import { guid, isDefinedAndNotNull, isObject, isUndefined } from '@core/utils'; import { ResizeObserver } from '@juggle/resize-observer'; import { getAce } from '@shared/models/ace/ace.models'; From 21599386df69ca363ec9fefbd969429292edb4b3 Mon Sep 17 00:00:00 2001 From: kalutkaz Date: Tue, 19 Apr 2022 16:21:10 +0300 Subject: [PATCH 4/5] Added icon to the JSON field + change validation logic in JSON directive --- .../components/directives/tb-json-to-string.directive.ts | 7 ++++++- ui-ngx/src/app/shared/models/constants.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts b/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts index ff8d2adead..dd2b79a044 100644 --- a/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts +++ b/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts @@ -26,6 +26,7 @@ import { Validator } from '@angular/forms'; import { ErrorStateMatcher } from '@angular/material/core'; +import {isObject} from "@core/utils"; @Directive({ selector: '[tb-json-to-string]', @@ -53,7 +54,11 @@ export class TbJsonToStringDirective implements ControlValueAccessor, Validator, @HostListener('input', ['$event.target.value']) input(newValue: any): void { try { this.data = JSON.parse(newValue); - this.parseError = false; + if (isObject(this.data)) { + this.parseError = false; + } else { + this.parseError = true; + } } catch (e) { this.parseError = true; } diff --git a/ui-ngx/src/app/shared/models/constants.ts b/ui-ngx/src/app/shared/models/constants.ts index 4bfce6414a..7eab516ef2 100644 --- a/ui-ngx/src/app/shared/models/constants.ts +++ b/ui-ngx/src/app/shared/models/constants.ts @@ -200,7 +200,7 @@ export const valueTypesMap = new Map( ValueType.JSON, { name: 'value.json', - icon: 'mdi:json' + icon: 'mdi:code-json' } ] ] From 607f3cd1969b4ac501dde9d9ce98a0bbb02dde1e Mon Sep 17 00:00:00 2001 From: kalutkaz Date: Tue, 19 Apr 2022 16:39:56 +0300 Subject: [PATCH 5/5] Refactoring --- .../shared/components/directives/tb-json-to-string.directive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts b/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts index dd2b79a044..7ef523e7d0 100644 --- a/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts +++ b/ui-ngx/src/app/shared/components/directives/tb-json-to-string.directive.ts @@ -26,7 +26,7 @@ import { Validator } from '@angular/forms'; import { ErrorStateMatcher } from '@angular/material/core'; -import {isObject} from "@core/utils"; +import { isObject } from "@core/utils"; @Directive({ selector: '[tb-json-to-string]',