Fix message processing issue (#17609)

Signed-off-by: AllForNothing <sshijun@vmware.com>

Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
Shijun Sun 2022-09-29 11:12:11 +08:00 committed by GitHub
parent 303133f695
commit cf5197246a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 37 deletions

View File

@ -23,6 +23,7 @@
"plugin:prettier/recommended" "plugin:prettier/recommended"
], ],
"rules": { "rules": {
"no-console": ["error", { "allow": ["warn", "error"] }]
} }
}, },
{ {

View File

@ -13,6 +13,7 @@ mockApi.get('/', (req, res) => {
mockApi.get(CURRENT_BASE_HREF + '/scanners', Controllers.getScanner); mockApi.get(CURRENT_BASE_HREF + '/scanners', Controllers.getScanner);
mockApi.listen(3000, () => { mockApi.listen(3000, () => {
// eslint-disable-next-line no-console
console.log('Api server listening on port 3000!'); console.log('Api server listening on port 3000!');
}); });

View File

@ -81,12 +81,6 @@ export class ConfigService {
new StringValueItem(fakePass, true); new StringValueItem(fakePass, true);
// Keep the original copy of the data // Keep the original copy of the data
this._originalConfig = clone(this._currentConfig); this._originalConfig = clone(this._currentConfig);
// Handle read only
if (this._originalConfig?.read_only?.value) {
this.msgHandler.handleReadOnly();
} else {
this.msgHandler.clear();
}
}, },
error => { error => {
this.msgHandler.handleError(error); this.msgHandler.handleError(error);

View File

@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SystemSettingsComponent } from './system-settings.component'; import { SystemSettingsComponent } from './system-settings.component';
import { ErrorHandler } from '../../../../shared/units/error-handler'; import { ErrorHandler } from '../../../../shared/units/error-handler';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { Configuration, NumberValueItem, StringValueItem } from '../config'; import { Configuration } from '../config';
import { SharedTestingModule } from '../../../../shared/shared.module'; import { SharedTestingModule } from '../../../../shared/shared.module';
import { ConfigService } from '../config.service'; import { ConfigService } from '../config.service';
import { AppConfigService } from '../../../../services/app-config.service'; import { AppConfigService } from '../../../../services/app-config.service';
@ -10,12 +10,6 @@ import { AppConfigService } from '../../../../services/app-config.service';
describe('SystemSettingsComponent', () => { describe('SystemSettingsComponent', () => {
let component: SystemSettingsComponent; let component: SystemSettingsComponent;
let fixture: ComponentFixture<SystemSettingsComponent>; let fixture: ComponentFixture<SystemSettingsComponent>;
const fakedErrorHandler = {
info() {
return null;
},
};
const fakeConfigService = { const fakeConfigService = {
config: new Configuration(), config: new Configuration(),
getConfig() { getConfig() {
@ -51,7 +45,6 @@ describe('SystemSettingsComponent', () => {
providers: [ providers: [
{ provide: AppConfigService, useValue: fakedAppConfigService }, { provide: AppConfigService, useValue: fakedAppConfigService },
{ provide: ConfigService, useValue: fakeConfigService }, { provide: ConfigService, useValue: fakeConfigService },
{ provide: ErrorHandler, useValue: fakedErrorHandler },
], ],
declarations: [SystemSettingsComponent], declarations: [SystemSettingsComponent],
}); });

View File

@ -6,10 +6,10 @@ import {
getChanges, getChanges,
isEmpty, isEmpty,
} from '../../../../shared/units/utils'; } from '../../../../shared/units/utils';
import { ErrorHandler } from '../../../../shared/units/error-handler';
import { ConfigService } from '../config.service'; import { ConfigService } from '../config.service';
import { AppConfigService } from '../../../../services/app-config.service'; import { AppConfigService } from '../../../../services/app-config.service';
import { finalize } from 'rxjs/operators'; import { finalize } from 'rxjs/operators';
import { MessageHandlerService } from '../../../../shared/services/message-handler.service';
@Component({ @Component({
selector: 'system-settings', selector: 'system-settings',
@ -30,7 +30,7 @@ export class SystemSettingsComponent implements OnInit {
constructor( constructor(
private appConfigService: AppConfigService, private appConfigService: AppConfigService,
private errorHandler: ErrorHandler, private errorHandler: MessageHandlerService,
private conf: ConfigService private conf: ConfigService
) { ) {
this.downloadLink = CURRENT_BASE_HREF + '/systeminfo/getcert'; this.downloadLink = CURRENT_BASE_HREF + '/systeminfo/getcert';
@ -151,23 +151,25 @@ export class SystemSettingsComponent implements OnInit {
.pipe(finalize(() => (this.onGoing = false))) .pipe(finalize(() => (this.onGoing = false)))
.subscribe({ .subscribe({
next: result => { next: result => {
if (!isEmpty(changes)) { // API should return the updated configurations here
// API should return the updated configurations here // Unfortunately API does not do that
// Unfortunately API does not do that // So we need to call update function again
// To refresh the view, we can clone the original data copy this.conf.updateConfig();
// or force refresh by calling service. // Handle read only
// HERE we choose force way if (changes['read_only']) {
this.conf.updateConfig(); this.errorHandler.handleReadOnly();
// Reload bootstrap option } else {
this.appConfigService.load().subscribe( this.errorHandler.clear();
() => {},
error =>
console.error(
'Failed to reload bootstrap option with error: ',
error
)
);
} }
// Reload bootstrap option
this.appConfigService.load().subscribe(
() => {},
error =>
console.error(
'Failed to reload bootstrap option with error: ',
error
)
);
this.errorHandler.info('CONFIG.SAVE_SUCCESS'); this.errorHandler.info('CONFIG.SAVE_SUCCESS');
}, },
error: error => { error: error => {

View File

@ -155,12 +155,12 @@ export class ResultBarChartComponent implements OnInit, OnDestroy {
scanNow(): void { scanNow(): void {
if (this.onSubmitting) { if (this.onSubmitting) {
// Avoid duplicated submitting // Avoid duplicated submitting
console.log('duplicated submit'); console.error('duplicated submit');
return; return;
} }
if (!this.repoName || !this.artifactDigest) { if (!this.repoName || !this.artifactDigest) {
console.log('bad repository or tag'); console.error('bad repository or tag');
return; return;
} }
@ -194,7 +194,7 @@ export class ResultBarChartComponent implements OnInit, OnDestroy {
error => { error => {
this.onSubmitting = false; this.onSubmitting = false;
if (error && error.error && error.error.code === 409) { if (error && error.error && error.error.code === 409) {
console.log(error.error.message); console.error(error.error.message);
} else { } else {
this.errorHandler.error(error); this.errorHandler.error(error);
} }
@ -272,11 +272,11 @@ export class ResultBarChartComponent implements OnInit, OnDestroy {
stopScan() { stopScan() {
if (this.onStopping) { if (this.onStopping) {
// Avoid duplicated stopping command // Avoid duplicated stopping command
console.log('duplicated stopping command'); console.error('duplicated stopping command');
return; return;
} }
if (!this.repoName || !this.artifactDigest) { if (!this.repoName || !this.artifactDigest) {
console.log('bad repository or artifact'); console.error('bad repository or artifact');
return; return;
} }
this.onStopping = true; this.onStopping = true;