]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: Remove _filterValue in CdFormGroup
authorStephan Müller <smueller@suse.com>
Tue, 6 Nov 2018 12:45:29 +0000 (13:45 +0100)
committerStephan Müller <smueller@suse.com>
Tue, 6 Nov 2018 12:49:21 +0000 (13:49 +0100)
It turned out that "_filterValue" wasn't needed for any form.

Fixes: http://tracker.ceph.com/issues/26861
Signed-off-by: Stephan Müller <smueller@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-form/configuration-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-form-group.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-form-group.ts

index b383eaa00270ae9fa8f3739fc9956db00776a022..65972f395dc592a87be2fa3d57933e3593f1e8d8 100644 (file)
@@ -53,9 +53,6 @@ export class ConfigurationFormComponent implements OnInit {
     });
 
     this.configForm = new CdFormGroup(formControls);
-    this.configForm._filterValue = (value) => {
-      return value;
-    };
   }
 
   ngOnInit() {
index e3acf7136c129586438ae7a43b2d076d78b57cdf..e9d4b204bdc0c4c236150bee1274513fcc169f80 100644 (file)
@@ -118,7 +118,8 @@ describe('CdFormGroup', () => {
       expect(form.getValue('floating')).toBe(0.1);
     });
 
-    it('returns strings that are not empty', () => {
+    it('returns strings', () => {
+      expect(form.getValue('emptyString')).toBe('');
       expect(form.getValue('someString1')).toBe('s');
       expect(form.getValue('someString2')).toBe('sth');
     });
@@ -132,19 +133,11 @@ describe('CdFormGroup', () => {
       expect(form.getValue('undefined')).toBe(null);
     });
 
-    it('returns a falsy value for empty string, null, undefined, false and 0', () => {
-      expect(form.getValue('emptyString')).toBe(false);
+    it('returns a falsy value for null, undefined, false and 0', () => {
       expect(form.getValue('false')).toBeFalsy();
       expect(form.getValue('null')).toBeFalsy();
       expect(form.getValue('number0')).toBeFalsy();
     });
-
-    it('test _filterValue', () => {
-      expect(form._filterValue(0)).toBe(true);
-      expect(form._filterValue(null)).toBe(true);
-      expect(form._filterValue(false)).toBe(true);
-      expect(form._filterValue('')).toBe(false);
-    });
   });
 
   describe('should test showError', () => {
index 8dfe8c5f90be63329c6e014348446300757174c9..9f2c1e633542d639e531c7248f2a5bf302332de5 100644 (file)
@@ -21,9 +21,6 @@ export class CdFormGroup extends FormGroup {
 
   /**
    * Get a control out of any control even if its nested in other CdFormGroups or a FormGroup
-   *
-   * @param {string} controlName
-   * @returns {AbstractControl}
    */
   get(controlName: string): AbstractControl {
     const control = this._get(controlName);
@@ -49,19 +46,10 @@ export class CdFormGroup extends FormGroup {
   }
 
   /**
-   * Get the value of a control if it has none it will return false
-   *
-   * @param {string} controlName
-   * @returns {any} false or the value of the control
+   * Get the value of a control
    */
   getValue(controlName: string): any {
-    const value = this.get(controlName).value;
-    return this._filterValue(value) && value;
-  }
-
-  // Overwrite this if needed.
-  _filterValue(value) {
-    return value !== '';
+    return this.get(controlName).value;
   }
 
   /**
@@ -69,9 +57,6 @@ export class CdFormGroup extends FormGroup {
    *
    * Very useful if a function is called through a value changes event but the value
    * should be changed within the call.
-   *
-   * @param {string} controlName
-   * @param value
    */
   silentSet(controlName: string, value: any) {
     this.get(controlName).setValue(value, { emitEvent: false });
@@ -79,13 +64,8 @@ export class CdFormGroup extends FormGroup {
 
   /**
    * Indicates errors of the control in templates
-   *
-   * @param {string} controlName
-   * @param {NgForm} form
-   * @param {string} errorName
-   * @returns {boolean}
    */
-  showError(controlName: string, form: NgForm, errorName?: string) {
+  showError(controlName: string, form: NgForm, errorName?: string): boolean {
     const control = this.get(controlName);
     return (
       (form.submitted || control.dirty) &&