feat(core/settings): Eugeny/tabby#3999 Allow groups to specify settings that hosts inherit

This commit is contained in:
Clem Fern
2023-08-11 23:38:16 +02:00
parent 0ef24ddf1d
commit 695c5ba670
8 changed files with 190 additions and 47 deletions

View File

@@ -65,8 +65,8 @@ export class ProfilesService {
* Return ConfigProxy for a given Profile
* arg: skipUserDefaults -> do not merge global provider defaults in ConfigProxy
*/
getConfigProxyForProfile <T extends Profile> (profile: PartialProfile<T>, skipUserDefaults = false): T {
const defaults = this.getProfileDefaults(profile, skipUserDefaults).reduce(configMerge, {})
getConfigProxyForProfile <T extends Profile> (profile: PartialProfile<T>, skipGlobalDefaults = false, skipGroupDefaults = false): T {
const defaults = this.getProfileDefaults(profile, skipGlobalDefaults, skipGroupDefaults).reduce(configMerge, {})
return new ConfigProxy(profile, defaults) as unknown as T
}
@@ -373,12 +373,14 @@ export class ProfilesService {
* Always return something, empty object if no defaults found
* arg: skipUserDefaults -> do not merge global provider defaults in ConfigProxy
*/
getProfileDefaults (profile: PartialProfile<Profile>, skipUserDefaults = false): any {
getProfileDefaults (profile: PartialProfile<Profile>, skipGlobalDefaults = false, skipGroupDefaults = false): any[] {
const provider = this.providerForProfile(profile)
return [
this.profileDefaults,
provider?.configDefaults ?? {},
!provider || skipUserDefaults ? {} : this.getProviderDefaults(provider),
provider && !skipGlobalDefaults ? this.getProviderDefaults(provider) : {},
provider && !skipGlobalDefaults && !skipGroupDefaults ? this.getProviderProfileGroupDefaults(profile.group ?? '', provider) : {},
]
}
@@ -386,6 +388,14 @@ export class ProfilesService {
* Methods used to interract with ProfileGroup
*/
/**
* Synchronously return an Array of the existing ProfileGroups
* Does not return builtin groups
*/
getSyncProfileGroups (): PartialProfileGroup<ProfileGroup>[] {
return deepClone(this.config.store.groups ?? [])
}
/**
* Return an Array of the existing ProfileGroups
* arg: includeProfiles (default: false) -> if false, does not fill up the profiles field of ProfileGroup
@@ -397,7 +407,7 @@ export class ProfilesService {
profiles = await this.getProfiles(includeNonUserGroup, true)
}
let groups: PartialProfileGroup<ProfileGroup>[] = deepClone(this.config.store.groups ?? [])
let groups: PartialProfileGroup<ProfileGroup>[] = this.getSyncProfileGroups()
groups = groups.map(x => {
x.editable = true
@@ -516,4 +526,13 @@ export class ProfilesService {
return this.config.store.groups.find(g => g.id === groupId)?.name ?? groupId
}
/**
* Return defaults for a given group ID and provider
* Always return something, empty object if no defaults found
* arg: skipUserDefaults -> do not merge global provider defaults in ConfigProxy
*/
getProviderProfileGroupDefaults (groupId: string, provider: ProfileProvider<Profile>): any {
return this.getSyncProfileGroups().find(g => g.id === groupId)?.defaults?.[provider.id] ?? {}
}
}