Skip to content

Commit

Permalink
Revert "wip ref(core): update profileDefaults in view of Eugeny#3999"
Browse files Browse the repository at this point in the history
This reverts commit 272b9ee.
  • Loading branch information
Clem-Fern committed Jul 22, 2023
1 parent 272b9ee commit ee4487a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 101 deletions.
5 changes: 0 additions & 5 deletions tabby-core/src/api/profileProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'> & {
Expand Down
11 changes: 0 additions & 11 deletions tabby-core/src/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
77 changes: 7 additions & 70 deletions tabby-core/src/services/profiles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}

Expand All @@ -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),
]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down
17 changes: 3 additions & 14 deletions tabby-settings/src/components/profilesSettingsTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit ee4487a

Please sign in to comment.