From 0a798007b8760ec95453081374b7ec5404e91bd4 Mon Sep 17 00:00:00 2001 From: Sarthak0702 Date: Wed, 16 Feb 2022 18:15:35 +0530 Subject: [PATCH] mgr/dashboard: Contact Info should be visible only when Ident channel is checked Fixes:https://tracker.ceph.com/issues/54133 Signed-off-by: Sarthak0702 (cherry picked from commit 15211a6378a6fee9316f79ba0b27821891527c38) Conflicts: src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts - removed test for perf channel, which doesn't exist in Pacific --- .../telemetry/telemetry.component.html | 13 ++++ .../telemetry/telemetry.component.spec.ts | 24 ++++--- .../cluster/telemetry/telemetry.component.ts | 68 ++++++++++++------- 3 files changed, 70 insertions(+), 35 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.html index 902d9f5bc7676..1348714694273 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.html @@ -163,6 +163,19 @@ i18n-placeholder> +
+ +
+ +
+
Advanced Settings
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts index ba94be7101f0b..2488816494abc 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts @@ -85,22 +85,28 @@ describe('TelemetryComponent', () => { fixture.debugElement.nativeElement.querySelector('input[id=contact]'); const getDescriptionField = () => fixture.debugElement.nativeElement.querySelector('input[id=description]'); + const checkVisibility = () => { + if (component.showContactInfo) { + expect(getContactField()).toBeTruthy(); + expect(getDescriptionField()).toBeTruthy(); + } else { + expect(getContactField()).toBeFalsy(); + expect(getDescriptionField()).toBeFalsy(); + } + }; - // Initially hidden. - expect(getContactField()).toBeFalsy(); - expect(getDescriptionField()).toBeFalsy(); + // Initial check. + checkVisibility(); - // Show fields. + // toggle fields. component.toggleIdent(); fixture.detectChanges(); - expect(getContactField()).toBeTruthy(); - expect(getDescriptionField()).toBeTruthy(); + checkVisibility(); - // Hide fields. + // toggle fields again. component.toggleIdent(); fixture.detectChanges(); - expect(getContactField()).toBeFalsy(); - expect(getDescriptionField()).toBeFalsy(); + checkVisibility(); }); it('should set module enability to true correctly', () => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts index debc7bd53d25a..c2f4523dc7583 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts @@ -25,7 +25,8 @@ export class TelemetryComponent extends CdForm implements OnInit { licenseAgrmt = false; moduleEnabled: boolean; options: Object = {}; - updatedConfig: Object = {}; + newConfig: Object = {}; + configResp: object = {}; previewForm: CdFormGroup; requiredFields = [ 'channel_basic', @@ -35,14 +36,16 @@ export class TelemetryComponent extends CdForm implements OnInit { 'interval', 'proxy', 'contact', - 'description' + 'description', + 'organization' ]; + contactInfofields = ['contact', 'description', 'organization']; report: object = undefined; reportId: number = undefined; sendToUrl = ''; sendToDeviceUrl = ''; step = 1; - showContactInfo = false; + showContactInfo: boolean; constructor( public actionLabels: ActionLabelsI18n, @@ -67,10 +70,11 @@ export class TelemetryComponent extends CdForm implements OnInit { this.moduleEnabled = configResp['enabled']; this.sendToUrl = configResp['url']; this.sendToDeviceUrl = configResp['device_url']; + this.showContactInfo = configResp['channel_ident']; this.options = _.pick(resp[0], this.requiredFields); - const configs = _.pick(configResp, this.requiredFields); + this.configResp = _.pick(configResp, this.requiredFields); this.createConfigForm(); - this.configForm.setValue(configs); + this.configForm.setValue(this.configResp); this.loadingReady(); }, (_error) => { @@ -114,21 +118,21 @@ export class TelemetryComponent extends CdForm implements OnInit { return result; } - private updateChannelsInReport(updatedConfig: Object = {}) { - const channels: string[] = this.report['report']['channels']; + private updateReportFromConfig(updatedConfig: Object = {}) { + // update channels const availableChannels: string[] = this.report['report']['channels_available']; const updatedChannels = []; for (const channel of availableChannels) { const key = `channel_${channel}`; - // channel unchanged or toggled on - if ( - (!updatedConfig.hasOwnProperty(key) && channels.includes(channel)) || - updatedConfig[key] - ) { + if (updatedConfig[key]) { updatedChannels.push(channel); } } this.report['report']['channels'] = updatedChannels; + // update contactInfo + for (const contactInfofield of this.contactInfofields) { + this.report['report'][contactInfofield] = updatedConfig[contactInfofield]; + } } private getReport() { @@ -138,7 +142,7 @@ export class TelemetryComponent extends CdForm implements OnInit { (resp: object) => { this.report = resp; this.reportId = resp['report']['report_id']; - this.updateChannelsInReport(this.updatedConfig); + this.updateReportFromConfig(this.newConfig); this.createPreviewForm(); this.loadingReady(); this.step++; @@ -153,17 +157,22 @@ export class TelemetryComponent extends CdForm implements OnInit { this.showContactInfo = !this.showContactInfo; } - updateConfig() { - this.updatedConfig = {}; + buildReport() { + this.newConfig = {}; for (const option of Object.values(this.options)) { const control = this.configForm.get(option.name); - if (!control.valid) { + // Append the option only if they are valid + if (control.valid) { + this.newConfig[option.name] = control.value; + } else { this.configForm.setErrors({ cdSubmitButton: true }); return; } - // Append the option only if the value has been modified. - if (control.dirty && control.valid) { - this.updatedConfig[option.name] = control.value; + } + // reset contact info field if ident channel is off + if (!this.newConfig['channel_ident']) { + for (const contactInfofield of this.contactInfofields) { + this.newConfig[contactInfofield] = ''; } } this.getReport(); @@ -184,21 +193,28 @@ export class TelemetryComponent extends CdForm implements OnInit { } next() { - if (this.configForm.pristine) { - this.getReport(); - } else { - this.updateConfig(); - } + this.buildReport(); } back() { this.step--; } + getChangedConfig() { + const updatedConfig = {}; + _.forEach(this.requiredFields, (configField) => { + if (!_.isEqual(this.configResp[configField], this.newConfig[configField])) { + updatedConfig[configField] = this.newConfig[configField]; + } + }); + return updatedConfig; + } + onSubmit() { + const updatedConfig = this.getChangedConfig(); const observables = [ this.telemetryService.enable(), - this.mgrModuleService.updateConfig('telemetry', this.updatedConfig) + this.mgrModuleService.updateConfig('telemetry', updatedConfig) ]; observableForkJoin(observables).subscribe( @@ -220,7 +236,7 @@ export class TelemetryComponent extends CdForm implements OnInit { this.previewForm.setErrors({ cdSubmitButton: true }); }, () => { - this.updatedConfig = {}; + this.newConfig = {}; this.router.navigate(['']); } ); -- 2.39.5