Fix unable to set tosca function on complex type on input operation
[sdc.git] / catalog-ui / src / app / ng2 / pages / composition / interface-operatons / operation-creator / input-list / input-list-item / input-list-item.component.ts
index 61708ab..21e8363 100644 (file)
@@ -30,6 +30,7 @@ import {ToscaFunctionValidationEvent} from "../../../../../properties-assignment
 import {InstanceFeDetails} from "../../../../../../../models/instance-fe-details";
 import {ToscaTypeHelper} from "app/utils/tosca-type-helper";
 import {CustomToscaFunction} from "../../../../../../../models/default-custom-functions";
+import {SubPropertyToscaFunction} from "../../../../../../../models/sub-property-tosca-function";
 
 @Component({
   selector: 'app-input-list-item',
@@ -49,7 +50,7 @@ export class InputListItemComponent implements OnInit {
   @Input() isMapChild: boolean = false;
   @Input() showToscaFunctionOption: boolean = false;
   @Input() listIndex: number;
-  @Input() subPropertyToscaFunctions: SubPropertyToscaFunctions[];
+  @Input() subPropertyToscaFunctions: SubPropertyToscaFunction[];
   @Input() isViewOnly: boolean;
   @Input() allowDeletion: boolean = false;
   @Input() toscaFunction: ToscaFunction;
@@ -86,6 +87,15 @@ export class InputListItemComponent implements OnInit {
     }
   }
 
+  ngOnChanges(): void {
+    if (this.isToscaFunction) {
+      this.property.toscaFunction = this.toscaFunction;
+      this.valueObjRef = this.toscaFunction.value;
+    } else {
+      this.property.toscaFunction = undefined;
+    }
+  }
+
   private initEmptyPropertyInValueObjRef(property: PropertyBEModel) {
     if (this.valueObjRef[property.name] == undefined) {
       if (this.isTypeComplex(property.type) || this.isTypeMap(property.type)) {
@@ -101,18 +111,12 @@ export class InputListItemComponent implements OnInit {
   getToscaFunction(key: any): any {
     if (this.subPropertyToscaFunctions) {
       for (let subPropertyToscaFunction of this.subPropertyToscaFunctions) {
-        let found = subPropertyToscaFunction.subPropertyPath.find(value => value === key);
+        let found = subPropertyToscaFunction.subPropertyPath ? subPropertyToscaFunction.subPropertyPath.find(value => value === key) : false;
         if (found) {
           return subPropertyToscaFunction.toscaFunction;
         }
       }
     }
-    if ((key && this.valueObjRef[key] && this.valueObjRef[key].type)) {
-      const type = this.valueObjRef[key].type;
-      if (type in ToscaFunctionType) {
-        return <ToscaFunction> this.valueObjRef[key];
-      }
-    }
     return undefined;
   }
 
@@ -347,8 +351,3 @@ export class InputListItemComponent implements OnInit {
   }
 
 }
-
-export interface SubPropertyToscaFunctions {
-  subPropertyPath: string[];
-  toscaFunction: ToscaFunction;
-}