Disable save for invalid TOSCA function 97/129597/2
authorandre.schmid <andre.schmid@est.tech>
Fri, 10 Jun 2022 14:22:58 +0000 (15:22 +0100)
committerMichael Morris <michael.morris@est.tech>
Mon, 13 Jun 2022 14:21:46 +0000 (14:21 +0000)
Disable save button for invalid TOSCA functions in the TOSCA function
modal.

Change-Id: I322f59b20faec17ba0edaa412273ee41c0c2675c
Issue-ID: SDC-4047
Signed-off-by: andre.schmid <andre.schmid@est.tech>
catalog-ui/src/app/models/tosca-get-function.ts
catalog-ui/src/app/ng2/pages/properties-assignment/properties-assignment.page.component.ts
catalog-ui/src/app/ng2/pages/properties-assignment/tosca-function/tosca-function.component.ts

index 6d5642e..97497fc 100644 (file)
@@ -31,7 +31,7 @@ export class ToscaGetFunction {
     functionType: ToscaGetFunctionType;
     propertyPathFromSource: Array<string>;
 
-    constructor(toscaGetFunction: ToscaGetFunction) {
+    constructor(toscaGetFunction?: ToscaGetFunction) {
         if (!toscaGetFunction) {
             return;
         }
index 7feea50..ab67b0c 100644 (file)
@@ -538,6 +538,7 @@ export class PropertiesAssignmentComponent {
     private openToscaGetFunctionModal() {
         const modalTitle = this.translateService.translate('TOSCA_FUNCTION_MODAL_TITLE');
         const modalButtons = [];
+        let disableSaveButtonFlag = true;
         modalButtons.push(new ButtonModel(this.translateService.translate('MODAL_SAVE'), 'blue',
             () => {
                 const toscaGetFunction: ToscaGetFunction = modal.instance.dynamicContent.instance.toscaGetFunction;
@@ -547,7 +548,8 @@ export class PropertiesAssignmentComponent {
                     this.clearCheckedInstancePropertyValue();
                 }
                 modal.instance.close();
-            }
+            },
+            (): boolean => { return disableSaveButtonFlag }
         ));
         const checkedInstanceProperty = this.buildCheckedInstanceProperty();
         modalButtons.push(new ButtonModel(this.translateService.translate('MODAL_CANCEL'), 'outline grey', () => {
@@ -565,6 +567,9 @@ export class PropertiesAssignmentComponent {
             'property': checkedInstanceProperty,
             'componentInstanceMap': this.componentInstanceMap
         });
+        modal.instance.dynamicContent.instance.onValidityChange.subscribe(isValid => {
+            disableSaveButtonFlag = !isValid;
+        });
         modal.instance.open();
     }
 
index 81e5b47..8c983b6 100644 (file)
@@ -48,6 +48,10 @@ export class ToscaFunctionComponent implements OnInit {
 
     toscaGetFunctionValidator: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {
         const toscaGetFunction: ToscaGetFunction = control.value;
+        const hasAnyValue = Object.keys(toscaGetFunction).find(key => toscaGetFunction[key]);
+        if (!hasAnyValue) {
+            return null;
+        }
         const errors: ValidationErrors = {};
         if (!toscaGetFunction.sourceName) {
             errors.sourceName = { required: true };
@@ -105,15 +109,15 @@ export class ToscaFunctionComponent implements OnInit {
         this.loadToscaFunctions();
         this.loadPropertySourceDropdown();
         this.initToscaGetFunction();
+    }
+
+    private initToscaGetFunction(): void {
         this.toscaGetFunctionForm.valueChanges.subscribe(toscaGetFunction => {
             this.onValidityChange.emit(this.toscaGetFunctionForm.valid);
             if (this.toscaGetFunctionForm.valid) {
                 this.onValidFunction.emit(toscaGetFunction);
             }
-        })
-    }
-
-    private initToscaGetFunction(): void {
+        });
         if (!this.property.isToscaGetFunction()) {
             return;
         }
@@ -177,8 +181,8 @@ export class ToscaFunctionComponent implements OnInit {
     }
 
     private resetForm(): void {
-        this.toscaGetFunction = new ToscaGetFunction(undefined);
-        this.toscaGetFunctionForm.setValue(new ToscaGetFunction(undefined));
+        this.toscaGetFunction = new ToscaGetFunction();
+        this.toscaGetFunctionForm.setValue(new ToscaGetFunction());
         this.propertySource = undefined;
         this.selectedProperty = undefined;
     }