From f3196ac045c085ac3234b45de0b8cf3923c1a7e6 Mon Sep 17 00:00:00 2001 From: Jude Cooray Date: Mon, 9 Oct 2023 21:15:18 +1100 Subject: [PATCH] Refresh default profile selection when profiles are modified --- .../components/profilesSettingsTab.component.pug | 2 +- .../src/components/profilesSettingsTab.component.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tabby-settings/src/components/profilesSettingsTab.component.pug b/tabby-settings/src/components/profilesSettingsTab.component.pug index d883ae49ba..9c8144a8a4 100644 --- a/tabby-settings/src/components/profilesSettingsTab.component.pug +++ b/tabby-settings/src/components/profilesSettingsTab.component.pug @@ -12,7 +12,7 @@ ul.nav-tabs(ngbNav, #nav='ngbNav') [(ngModel)]='config.store.terminal.profile', (ngModelChange)='config.save()', ) - optgroup([label]='"Custom Profiles"|translate', *ngIf='customProfiles?.length > 0') + optgroup([label]='"Custom Profiles"|translate', *ngIf='customProfiles?.length > 0') option( *ngFor='let profile of customProfiles', [ngValue]='profile.id' diff --git a/tabby-settings/src/components/profilesSettingsTab.component.ts b/tabby-settings/src/components/profilesSettingsTab.component.ts index e2c0339270..c1f5406525 100644 --- a/tabby-settings/src/components/profilesSettingsTab.component.ts +++ b/tabby-settings/src/components/profilesSettingsTab.component.ts @@ -20,6 +20,7 @@ interface CollapsableProfileGroup extends ProfileGroup { }) export class ProfilesSettingsTabComponent extends BaseComponent { builtinProfiles: PartialProfile[] = [] + profiles: PartialProfile[] = [] templateProfiles: PartialProfile[] = [] customProfiles: PartialProfile[] = [] profileGroups: PartialProfileGroup[] @@ -41,13 +42,17 @@ export class ProfilesSettingsTabComponent extends BaseComponent { } async ngOnInit (): Promise { - this.refresh() + await this.refreshProfileGroups() + await this.refreshProfiles() + this.subscribeUntilDestroyed(this.config.changed$, () => this.refreshProfileGroups()) + this.subscribeUntilDestroyed(this.config.changed$, () => this.refreshProfiles()) + } + + async refreshProfiles (): Promise { this.builtinProfiles = (await this.profilesService.getProfiles()).filter(x => x.isBuiltin) this.customProfiles = (await this.profilesService.getProfiles()).filter(x => !x.isBuiltin) this.templateProfiles = this.builtinProfiles.filter(x => x.isTemplate) this.builtinProfiles = this.builtinProfiles.filter(x => !x.isTemplate) - this.refresh() - this.subscribeUntilDestroyed(this.config.changed$, () => this.refresh()) } launchProfile (profile: PartialProfile): void { @@ -242,7 +247,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent { } } - async refresh (): Promise { + async refreshProfileGroups (): Promise { const profileGroupCollapsed = JSON.parse(window.localStorage.profileGroupCollapsed ?? '{}') const groups = await this.profilesService.getProfileGroups({ includeNonUserGroup: true, includeProfiles: true }) groups.sort((a, b) => a.name.localeCompare(b.name))