Provide validation to the json type property in the operation inputs 26/135726/2
authorimamSidero <imam.hussain@est.tech>
Mon, 14 Aug 2023 16:59:23 +0000 (17:59 +0100)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Tue, 22 Aug 2023 15:35:05 +0000 (15:35 +0000)
Validation for json type properties is provided in operation inputs

Issue-ID: SDC-4593
Signed-off-by: Imam hussain <imam.hussain@est.tech>
Change-Id: Id466b1de26007b77d4bb9093ee37580d312824ea

catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list-item/input-list-item.component.ts
catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/input-list/input-list.component.ts
catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/interface-operation-handler.component.html

index 21e8363..116b9eb 100644 (file)
@@ -85,6 +85,9 @@ export class InputListItemComponent implements OnInit {
       this.valueObjRef = this.toscaFunction.value;
       this.isToscaFunction = true;
     }
+    if (this.property.type == PROPERTY_TYPES.JSON) {
+      this.valueObjRef = JSON.stringify(this.valueObjRef);
+    }
   }
 
   ngOnChanges(): void {
index 62c5e8a..3956fe2 100644 (file)
@@ -137,7 +137,19 @@ export class InputListComponent {
       } else if (this.isTypeComplex(inputOperationParameter.type)) {
         this.setComplexType($event, inputOperationParameter);
       } else {
-        inputOperationParameter.value = $event.value;
+        if (inputOperationParameter.type == PROPERTY_TYPES.JSON) {
+          const parseValue = $event.value;
+          try {
+            JSON.parse(parseValue);
+            inputOperationParameter.value = $event.value;
+          } catch (err) {
+            console.log('invalid json');
+            inputOperationParameter.valid = false;
+            inputOperationParameter.value = null;
+          }
+        } else {
+          inputOperationParameter.value = $event.value;
+        }
         inputOperationParameter.toscaFunction = null;
       }
     }
index 0b42f75..38aed30 100644 (file)
                 [componentInstanceMap]="componentInstanceMap"
                 [showToscaFunctionOption]="true"
                 (onValueChange)="onInputValueChange($event)"
+                (onInputsValidityChange)="implementationPropsValidityChange($event)"
                 (onDelete)="onInputDelete($event)"
             >
             </input-list>