Skip to content

Commit

Permalink
wip ref(core): getProfileGroups create non editable group for built-i…
Browse files Browse the repository at this point in the history
…n profile
  • Loading branch information
Clem-Fern committed Aug 5, 2023
1 parent 951c69b commit 935c981
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 20 additions & 6 deletions tabby-core/src/services/profiles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,13 @@ export class ProfilesService {
})

if (includeNonUserGroup) {
const builtIn: PartialProfileGroup<ProfileGroup> = {
const builtInGroups: PartialProfileGroup<ProfileGroup>[] = []
builtInGroups.push({
id: 'built-in',
name: this.translate.instant('Built-in'),
editable: false,
}
profiles: [],
})

const ungrouped: PartialProfileGroup<ProfileGroup> = {
id: 'ungrouped',
Expand All @@ -423,13 +425,25 @@ export class ProfilesService {
}

if (includeProfiles) {
builtIn.profiles = profiles.filter(p => p.isBuiltin)
profiles = profiles.filter(p => !p.isBuiltin)
for (const profile of profiles.filter(p => p.isBuiltin)) {
let group: PartialProfileGroup<ProfileGroup> | undefined = builtInGroups.find(g => g.id === slugify(profile.group ?? 'built-in'))
if (!group) {
group = {
id: `${slugify(profile.group!)}`,
name: `${profile.group!}`,
editable: false,
profiles: [],
}
builtInGroups.push(group)
}

group.profiles!.push(profile)
}

ungrouped.profiles = profiles
ungrouped.profiles = profiles.filter(p => !p.isBuiltin)
}

groups.push(builtIn)
groups = groups.concat(builtInGroups)
groups.push(ungrouped)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
const profileGroupCollapsed = JSON.parse(window.localStorage.profileGroupCollapsed ?? '{}')
const groups = await this.profilesService.getProfileGroups(true, true)
groups.sort((a, b) => a.name.localeCompare(b.name))
groups.sort((a, b) => (a.id === 'built-in' ? 1 : 0) - (b.id === 'built-in' ? 1 : 0))
groups.sort((a, b) => (a.id === 'built-in' || !a.editable ? 1 : 0) - (b.id === 'built-in' || !b.editable ? 1 : 0))
groups.sort((a, b) => (a.id === 'ungrouped' ? 0 : 1) - (b.id === 'ungrouped' ? 0 : 1))
this.profileGroups = groups.map(g => ProfilesSettingsTabComponent.intoPartialCollapsableProfileGroup(g, profileGroupCollapsed[g.id] ?? false))
}
Expand Down

0 comments on commit 935c981

Please sign in to comment.