Revert "wip ref(core): update profileDefaults in view of Eugeny/tabby#3999"

This reverts commit 272b9ee5dc.
This commit is contained in:
Clem Fern 2023-07-22 19:43:52 +02:00
parent 272b9ee5dc
commit ee4487a517
5 changed files with 11 additions and 101 deletions

View file

@ -21,11 +21,6 @@ export interface Profile {
isTemplate: boolean
}
export interface ProfileDefaults {
id: string
//[provider]:
}
export type PartialProfile<T extends Profile> = Omit<Omit<Omit<{
[K in keyof T]?: T[K]
}, 'options'>, 'type'>, 'name'> & {

View file

@ -10,7 +10,6 @@ import { PlatformService } from '../api/platform'
import { HostAppService } from '../api/hostApp'
import { Vault, VaultService } from './vault.service'
import { serializeFunction } from '../utils'
import { ProfileDefaults } from '../api/profileProvider'
const deepmerge = require('deepmerge')
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
@ -365,16 +364,6 @@ export class ConfigService {
}
config.version = 4
}
if (config.version < 5) {
const oldDefaults = config.profileDefaults
const globalDefaults: ProfileDefaults = {
id: 'global',
...oldDefaults
}
config.profileDefaults = []
config.profileDefaults.push(globalDefaults)
config.version = 5
}
}
private async maybeDecryptConfig (store) {

View file

@ -2,7 +2,7 @@ import { Injectable, Inject } from '@angular/core'
import { TranslateService } from '@ngx-translate/core'
import { NewTabParameters } from './tabs.service'
import { BaseTabComponent } from '../components/baseTab.component'
import { PartialProfile, Profile, ProfileDefaults, ProfileProvider } from '../api/profileProvider'
import { PartialProfile, Profile, ProfileProvider } from '../api/profileProvider'
import { SelectorOption } from '../api/selector'
import { AppService } from './app.service'
import { configMerge, ConfigProxy, ConfigService } from './config.service'
@ -212,7 +212,12 @@ export class ProfilesService {
}
getConfigProxyForProfile <T extends Profile> (profile: PartialProfile<T>, skipUserDefaults = false): T {
const defaults = this.getProfileDefaults(profile).reduce(configMerge, {})
const provider = this.providerForProfile(profile)
const defaults = [
this.profileDefaults,
provider?.configDefaults ?? {},
!provider || skipUserDefaults ? {} : this.config.store.profileDefaults[provider.id] ?? {},
].reduce(configMerge, {})
return new ConfigProxy(profile, defaults) as unknown as T
}
@ -229,72 +234,4 @@ export class ProfilesService {
}
window.localStorage['recentProfiles'] = JSON.stringify(recentProfiles)
}
/*
* Methods used to interract with Profile/ProfileGroup/Global defaults
*/
/**
* Return ProfileDefaults Array from config
*/
private getAllDefaults (): ProfileDefaults[] {
return this.config.store.profileDefaults
}
/**
* Return ProfileDefaults for a given defaultsId (ex. 'global', 'profileId' or 'groupId')
*/
private getDefaults (defaultsId: string): ProfileDefaults {
return this.getAllDefaults().find(x => x.id == defaultsId) ?? { id: defaultsId }
}
/**
* Replace or insert ProfileDefaults in config
*/
private setDefaults (defaults: ProfileDefaults) {
let allDefaults = this.getAllDefaults().filter(x => x.id !== defaults.id)
allDefaults.push(defaults)
this.config.store.profileDefaults = allDefaults
}
/**
* Replace or insert ProfileDefaults in config
*/
/*private deleteDefaults (defaults: ProfileDefaults) {
if (defaults.id === 'global') {
throw new Error('Unable to delete \'global\' profile Defaults')
}
this.config.store.profileDefaults = this.getAllDefaults().filter(x => x.id !== defaults.id)
}*/
/**
* Return global defaults for a given profile provider
*/
getProviderDefaults (defaultsId: string, provider: ProfileProvider<Profile>): any {
const defaults = this.getDefaults(defaultsId)
return defaults[provider.id] ?? {}
}
/**
* Set global defaults for a given profile provider
*/
setProviderDefaults (defaultsId: string, provider: ProfileProvider<Profile>, pdefaults: any) {
const defaults = this.getDefaults(defaultsId)
defaults[provider.id] = pdefaults
this.setDefaults(defaults)
}
/**
* Return defaults for a given profile
*/
getProfileDefaults (profile: PartialProfile<Profile>, skipUserDefaults = false): any {
const provider = this.providerForProfile(profile)
return [
this.profileDefaults,
provider?.configDefaults ?? {},
!provider || skipUserDefaults ? {} : this.getProviderDefaults('global', provider),
]
}
}

View file

@ -170,7 +170,7 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
.list-group.mt-3.mb-3.content-box
a.list-group-item.list-group-item-action(
(click)='editGlobalDefaults(provider)',
(click)='editDefaults(provider)',
*ngFor='let provider of profileProviders'
) {{provider.name|translate}}

View file

@ -277,16 +277,12 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
window.localStorage.profileGroupCollapsed = JSON.stringify(profileGroupCollapsed)
}
/**
* Edit Defaults for a given profile provider
* defaultsId: used to identify defaults stored in config (ex. value: group ID)
*/
async editDefaults (defaultsId: string, provider: ProfileProvider<Profile>): Promise<void> {
async editDefaults (provider: ProfileProvider<Profile>): Promise<void> {
const modal = this.ngbModal.open(
EditProfileModalComponent,
{ size: 'lg' },
)
const model = this.profilesService.getProviderDefaults(defaultsId, provider)
const model = this.config.store.profileDefaults[provider.id] ?? {}
model.type = provider.id
modal.componentInstance.profile = Object.assign({}, model)
modal.componentInstance.profileProvider = provider
@ -299,17 +295,10 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
delete model[k]
}
Object.assign(model, result)
this.profilesService.setProviderDefaults(defaultsId, provider, model)
this.config.store.profileDefaults[provider.id] = model
await this.config.save()
}
/**
* Edit global Defaults for a given profile provider
*/
async editGlobalDefaults (provider: ProfileProvider<Profile>): Promise<void> {
return this.editDefaults('global', provider)
}
blacklistProfile (profile: PartialProfile<Profile>): void {
this.config.store.profileBlacklist = [...this.config.store.profileBlacklist, profile.id]
this.config.save()