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"
],
"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.listen(3000, () => {
// eslint-disable-next-line no-console
console.log('Api server listening on port 3000!');
});

View File

@ -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);

View File

@ -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<SystemSettingsComponent>;
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],
});

View File

@ -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 => {

View File

@ -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;