From cf5197246aced09ff37f2f165281d73f8468536c Mon Sep 17 00:00:00 2001 From: Shijun Sun <30999793+AllForNothing@users.noreply.github.com> Date: Thu, 29 Sep 2022 11:12:11 +0800 Subject: [PATCH] Fix message processing issue (#17609) Signed-off-by: AllForNothing Signed-off-by: AllForNothing --- src/portal/.eslintrc.json | 1 + src/portal/server/src/mock-api.ts | 1 + .../left-side-nav/config/config.service.ts | 6 --- .../system/system-settings.component.spec.ts | 9 +---- .../system/system-settings.component.ts | 38 ++++++++++--------- .../result-bar-chart.component.ts | 10 ++--- 6 files changed, 28 insertions(+), 37 deletions(-) diff --git a/src/portal/.eslintrc.json b/src/portal/.eslintrc.json index ff078b777..519ddb4c7 100644 --- a/src/portal/.eslintrc.json +++ b/src/portal/.eslintrc.json @@ -23,6 +23,7 @@ "plugin:prettier/recommended" ], "rules": { + "no-console": ["error", { "allow": ["warn", "error"] }] } }, { diff --git a/src/portal/server/src/mock-api.ts b/src/portal/server/src/mock-api.ts index ff44047c6..0fa9a2c53 100644 --- a/src/portal/server/src/mock-api.ts +++ b/src/portal/server/src/mock-api.ts @@ -13,6 +13,7 @@ mockApi.get('/', (req, res) => { mockApi.get(CURRENT_BASE_HREF + '/scanners', Controllers.getScanner); mockApi.listen(3000, () => { + // eslint-disable-next-line no-console console.log('Api server listening on port 3000!'); }); diff --git a/src/portal/src/app/base/left-side-nav/config/config.service.ts b/src/portal/src/app/base/left-side-nav/config/config.service.ts index 2ce862b97..26ac30f2f 100644 --- a/src/portal/src/app/base/left-side-nav/config/config.service.ts +++ b/src/portal/src/app/base/left-side-nav/config/config.service.ts @@ -81,12 +81,6 @@ export class ConfigService { new StringValueItem(fakePass, true); // Keep the original copy of the data this._originalConfig = clone(this._currentConfig); - // Handle read only - if (this._originalConfig?.read_only?.value) { - this.msgHandler.handleReadOnly(); - } else { - this.msgHandler.clear(); - } }, error => { this.msgHandler.handleError(error); diff --git a/src/portal/src/app/base/left-side-nav/config/system/system-settings.component.spec.ts b/src/portal/src/app/base/left-side-nav/config/system/system-settings.component.spec.ts index 2e3505cc9..eb709b7d2 100644 --- a/src/portal/src/app/base/left-side-nav/config/system/system-settings.component.spec.ts +++ b/src/portal/src/app/base/left-side-nav/config/system/system-settings.component.spec.ts @@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { SystemSettingsComponent } from './system-settings.component'; import { ErrorHandler } from '../../../../shared/units/error-handler'; import { of } from 'rxjs'; -import { Configuration, NumberValueItem, StringValueItem } from '../config'; +import { Configuration } from '../config'; import { SharedTestingModule } from '../../../../shared/shared.module'; import { ConfigService } from '../config.service'; import { AppConfigService } from '../../../../services/app-config.service'; @@ -10,12 +10,6 @@ import { AppConfigService } from '../../../../services/app-config.service'; describe('SystemSettingsComponent', () => { let component: SystemSettingsComponent; let fixture: ComponentFixture; - const fakedErrorHandler = { - info() { - return null; - }, - }; - const fakeConfigService = { config: new Configuration(), getConfig() { @@ -51,7 +45,6 @@ describe('SystemSettingsComponent', () => { providers: [ { provide: AppConfigService, useValue: fakedAppConfigService }, { provide: ConfigService, useValue: fakeConfigService }, - { provide: ErrorHandler, useValue: fakedErrorHandler }, ], declarations: [SystemSettingsComponent], }); diff --git a/src/portal/src/app/base/left-side-nav/config/system/system-settings.component.ts b/src/portal/src/app/base/left-side-nav/config/system/system-settings.component.ts index 4448ce33e..274aaab8f 100644 --- a/src/portal/src/app/base/left-side-nav/config/system/system-settings.component.ts +++ b/src/portal/src/app/base/left-side-nav/config/system/system-settings.component.ts @@ -6,10 +6,10 @@ import { getChanges, isEmpty, } from '../../../../shared/units/utils'; -import { ErrorHandler } from '../../../../shared/units/error-handler'; import { ConfigService } from '../config.service'; import { AppConfigService } from '../../../../services/app-config.service'; import { finalize } from 'rxjs/operators'; +import { MessageHandlerService } from '../../../../shared/services/message-handler.service'; @Component({ selector: 'system-settings', @@ -30,7 +30,7 @@ export class SystemSettingsComponent implements OnInit { constructor( private appConfigService: AppConfigService, - private errorHandler: ErrorHandler, + private errorHandler: MessageHandlerService, private conf: ConfigService ) { this.downloadLink = CURRENT_BASE_HREF + '/systeminfo/getcert'; @@ -151,23 +151,25 @@ export class SystemSettingsComponent implements OnInit { .pipe(finalize(() => (this.onGoing = false))) .subscribe({ next: result => { - if (!isEmpty(changes)) { - // API should return the updated configurations here - // Unfortunately API does not do that - // To refresh the view, we can clone the original data copy - // or force refresh by calling service. - // HERE we choose force way - this.conf.updateConfig(); - // Reload bootstrap option - this.appConfigService.load().subscribe( - () => {}, - error => - console.error( - 'Failed to reload bootstrap option with error: ', - error - ) - ); + // API should return the updated configurations here + // Unfortunately API does not do that + // So we need to call update function again + this.conf.updateConfig(); + // Handle read only + if (changes['read_only']) { + this.errorHandler.handleReadOnly(); + } else { + this.errorHandler.clear(); } + // Reload bootstrap option + this.appConfigService.load().subscribe( + () => {}, + error => + console.error( + 'Failed to reload bootstrap option with error: ', + error + ) + ); this.errorHandler.info('CONFIG.SAVE_SUCCESS'); }, error: error => { diff --git a/src/portal/src/app/base/project/repository/artifact/vulnerability-scanning/result-bar-chart.component.ts b/src/portal/src/app/base/project/repository/artifact/vulnerability-scanning/result-bar-chart.component.ts index 6dda41dd3..69568d550 100644 --- a/src/portal/src/app/base/project/repository/artifact/vulnerability-scanning/result-bar-chart.component.ts +++ b/src/portal/src/app/base/project/repository/artifact/vulnerability-scanning/result-bar-chart.component.ts @@ -155,12 +155,12 @@ export class ResultBarChartComponent implements OnInit, OnDestroy { scanNow(): void { if (this.onSubmitting) { // Avoid duplicated submitting - console.log('duplicated submit'); + console.error('duplicated submit'); return; } if (!this.repoName || !this.artifactDigest) { - console.log('bad repository or tag'); + console.error('bad repository or tag'); return; } @@ -194,7 +194,7 @@ export class ResultBarChartComponent implements OnInit, OnDestroy { error => { this.onSubmitting = false; if (error && error.error && error.error.code === 409) { - console.log(error.error.message); + console.error(error.error.message); } else { this.errorHandler.error(error); } @@ -272,11 +272,11 @@ export class ResultBarChartComponent implements OnInit, OnDestroy { stopScan() { if (this.onStopping) { // Avoid duplicated stopping command - console.log('duplicated stopping command'); + console.error('duplicated stopping command'); return; } if (!this.repoName || !this.artifactDigest) { - console.log('bad repository or artifact'); + console.error('bad repository or artifact'); return; } this.onStopping = true;