automatically clean up defaults from the config file

This commit is contained in:
Eugene Pankov
2021-07-11 00:06:52 +02:00
parent 67bbbd7f65
commit 908f90cd52
11 changed files with 155 additions and 44 deletions

View File

@@ -2,7 +2,7 @@
import { Observable, OperatorFunction, debounceTime, map, distinctUntilChanged } from 'rxjs'
import { Component, Input, ViewChild, ViewContainerRef, ComponentFactoryResolver, Injector } from '@angular/core'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { ConfigService, Profile, ProfileProvider, ProfileSettingsComponent } from 'tabby-core'
import { ConfigProxy, ConfigService, Profile, ProfileProvider, ProfileSettingsComponent, ProfilesService } from 'tabby-core'
const iconsData = require('../../../tabby-core/src/icons.json')
const iconsClassList = Object.keys(iconsData).map(
@@ -16,17 +16,19 @@ const iconsClassList = Object.keys(iconsData).map(
template: require('./editProfileModal.component.pug'),
})
export class EditProfileModalComponent {
@Input() profile: Profile
@Input() profile: Profile|ConfigProxy
@Input() profileProvider: ProfileProvider
@Input() settingsComponent: new () => ProfileSettingsComponent
groupNames: string[]
@ViewChild('placeholder', { read: ViewContainerRef }) placeholder: ViewContainerRef
private _profile: Profile
private settingsComponentInstance: ProfileSettingsComponent
constructor (
private injector: Injector,
private componentFactoryResolver: ComponentFactoryResolver,
private profilesService: ProfilesService,
config: ConfigService,
private modalInstance: NgbActiveModal,
) {
@@ -37,6 +39,11 @@ export class EditProfileModalComponent {
)].sort() as string[]
}
ngOnInit () {
this._profile = this.profile
this.profile = this.profilesService.getConfigProxyForProfile(this.profile)
}
ngAfterViewInit () {
setTimeout(() => {
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.profileProvider.settingsComponent)
@@ -63,7 +70,8 @@ export class EditProfileModalComponent {
save () {
this.profile.group ||= undefined
this.settingsComponentInstance.save?.()
this.modalInstance.close(this.profile)
this.profile.__cleanup()
this.modalInstance.close(this._profile)
}
cancel () {

View File

@@ -82,7 +82,14 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
modal.componentInstance.profile = Object.assign({}, profile)
modal.componentInstance.profileProvider = this.profilesService.providerForProfile(profile)
const result = await modal.result
// Fully replace the config
for (const k in profile) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete profile[k]
}
Object.assign(profile, result)
await this.config.save()
}