Refresh config every time entering the configuration page (#17600)

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

Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
Shijun Sun 2022-09-27 16:04:02 +08:00 committed by GitHub
parent c1c1aaf612
commit 90fe39684b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 17 deletions

View File

@ -19,7 +19,6 @@ describe('ConfigurationComponent', () => {
return false;
},
updateConfig() {},
initConfig() {},
};
let initSpy: jasmine.Spy;
beforeEach(() => {
@ -34,7 +33,7 @@ describe('ConfigurationComponent', () => {
});
beforeEach(() => {
initSpy = spyOn(fakeConfigService, 'initConfig').and.returnValue(
initSpy = spyOn(fakeConfigService, 'updateConfig').and.returnValue(
undefined
);
fixture = TestBed.createComponent(ConfigurationComponent);

View File

@ -27,7 +27,7 @@ export class ConfigurationComponent implements OnInit {
constructor(private conf: ConfigService) {}
ngOnInit(): void {
// First load
this.conf.initConfig();
// Refresh config every time when entering the configuration page
this.conf.updateConfig();
}
}

View File

@ -33,15 +33,15 @@ describe('ConfigService', () => {
}
));
it('should init config', inject(
it('should update config', inject(
[ConfigService],
(service: ConfigService) => {
expect(getConfigSpy.calls.count()).toEqual(0);
service.initConfig();
expect(getConfigSpy.calls.count()).toEqual(1);
// only init once
service.initConfig();
service.updateConfig();
expect(getConfigSpy.calls.count()).toEqual(1);
// update again
service.updateConfig();
expect(getConfigSpy.calls.count()).toEqual(2);
expect(service).toBeTruthy();
}
));

View File

@ -17,7 +17,6 @@ const fakePass = 'aWpLOSYkIzJTTU4wMDkx';
@Injectable()
export class ConfigService {
private _loadingConfig: boolean = false;
private _hasInit: boolean = false;
private _confirmSub: Subscription;
private _currentConfig: Configuration = new Configuration();
private _originalConfig: Configuration;
@ -59,13 +58,6 @@ export class ConfigService {
return this._loadingConfig;
}
initConfig() {
if (!this._hasInit) {
this.updateConfig();
this._hasInit = true;
}
}
updateConfig() {
this._loadingConfig = true;
this.configureService
@ -92,6 +84,8 @@ export class ConfigService {
// Handle read only
if (this._originalConfig?.read_only?.value) {
this.msgHandler.handleReadOnly();
} else {
this.msgHandler.clear();
}
},
error => {