From: Stephan Müller Date: Tue, 6 Nov 2018 12:45:29 +0000 (+0100) Subject: mgr/dashboard: Remove _filterValue in CdFormGroup X-Git-Tag: v14.1.0~968^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=56e8bca81f79d536a91e7edfb528d540f6bf2b72;p=ceph.git mgr/dashboard: Remove _filterValue in CdFormGroup It turned out that "_filterValue" wasn't needed for any form. Fixes: http://tracker.ceph.com/issues/26861 Signed-off-by: Stephan Müller --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-form/configuration-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-form/configuration-form.component.ts index b383eaa00270..65972f395dc5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-form/configuration-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-form/configuration-form.component.ts @@ -53,9 +53,6 @@ export class ConfigurationFormComponent implements OnInit { }); this.configForm = new CdFormGroup(formControls); - this.configForm._filterValue = (value) => { - return value; - }; } ngOnInit() { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-form-group.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-form-group.spec.ts index e3acf7136c12..e9d4b204bdc0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-form-group.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-form-group.spec.ts @@ -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', () => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-form-group.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-form-group.ts index 8dfe8c5f90be..9f2c1e633542 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-form-group.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/forms/cd-form-group.ts @@ -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) &&