From f369b140c6a0f9cbbf0d2e477f085189654ebd66 Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Sat, 12 Aug 2023 17:30:35 +0200 Subject: [PATCH] feat(settings): Eugeny/tabby#7265 add a button to reset global & groups settings to defaults --- .../editProfileGroupModal.component.pug | 5 ++++- .../editProfileGroupModal.component.ts | 22 ++++++++++++++++++- .../profilesSettingsTab.component.pug | 5 ++++- .../profilesSettingsTab.component.ts | 18 +++++++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/tabby-settings/src/components/editProfileGroupModal.component.pug b/tabby-settings/src/components/editProfileGroupModal.component.pug index 54468a3b..c5864fdd 100644 --- a/tabby-settings/src/components/editProfileGroupModal.component.pug +++ b/tabby-settings/src/components/editProfileGroupModal.component.pug @@ -19,10 +19,13 @@ .description(translate) These apply to all profiles of a given type in this group .list-group.mt-3.mb-3.content-box - a.list-group-item.list-group-item-action( + a.list-group-item.list-group-item-action.d-flex.align-items-center( (click)='editDefaults(provider)', *ngFor='let provider of providers' ) {{provider.name|translate}} + .me-auto + button.btn.btn-link.hover-reveal.ms-1((click)='$event.stopPropagation(); deleteDefaults(provider)') + i.fas.fa-trash-arrow-up .modal-footer button.btn.btn-primary((click)='save()', translate) Save diff --git a/tabby-settings/src/components/editProfileGroupModal.component.ts b/tabby-settings/src/components/editProfileGroupModal.component.ts index fd00b026..e1cec231 100644 --- a/tabby-settings/src/components/editProfileGroupModal.component.ts +++ b/tabby-settings/src/components/editProfileGroupModal.component.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { Component, Input } from '@angular/core' import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' -import { ConfigProxy, ProfileGroup, Profile, ProfileProvider } from 'tabby-core' +import { ConfigProxy, ProfileGroup, Profile, ProfileProvider, PlatformService, TranslateService } from 'tabby-core' /** @hidden */ @Component({ @@ -13,6 +13,8 @@ export class EditProfileGroupModalComponent { constructor ( private modalInstance: NgbActiveModal, + private platform: PlatformService, + private translate: TranslateService, ) {} save () { @@ -26,6 +28,24 @@ export class EditProfileGroupModalComponent { editDefaults (provider: ProfileProvider) { this.modalInstance.close({ group: this.group, provider }) } + + async deleteDefaults (provider: ProfileProvider): Promise { + if ((await this.platform.showMessageBox( + { + type: 'warning', + message: this.translate.instant('Restore settings to inherited defaults ?'), + buttons: [ + this.translate.instant('Delete'), + this.translate.instant('Keep'), + ], + defaultId: 1, + cancelId: 1, + }, + )).response === 0) { + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete + delete this.group.defaults?.[provider.id] + } + } } export interface EditProfileGroupModalComponentResult { diff --git a/tabby-settings/src/components/profilesSettingsTab.component.pug b/tabby-settings/src/components/profilesSettingsTab.component.pug index ed61b23d..f6d60b1a 100644 --- a/tabby-settings/src/components/profilesSettingsTab.component.pug +++ b/tabby-settings/src/components/profilesSettingsTab.component.pug @@ -177,9 +177,12 @@ ul.nav-tabs(ngbNav, #nav='ngbNav') .description(translate) These apply to all profiles of a given type .list-group.mt-3.mb-3.content-box - a.list-group-item.list-group-item-action( + a.list-group-item.list-group-item-action.d-flex.align-items-center( (click)='editDefaults(provider)', *ngFor='let provider of profileProviders' ) {{provider.name|translate}} + .me-auto + button.btn.btn-link.hover-reveal.ms-1((click)='$event.stopPropagation(); deleteDefaults(provider)') + i.fas.fa-trash-arrow-up div([ngbNavOutlet]='nav') diff --git a/tabby-settings/src/components/profilesSettingsTab.component.ts b/tabby-settings/src/components/profilesSettingsTab.component.ts index 41b3e443..7a0b537d 100644 --- a/tabby-settings/src/components/profilesSettingsTab.component.ts +++ b/tabby-settings/src/components/profilesSettingsTab.component.ts @@ -308,6 +308,24 @@ export class ProfilesSettingsTabComponent extends BaseComponent { await this.config.save() } + async deleteDefaults (provider: ProfileProvider): Promise { + if ((await this.platform.showMessageBox( + { + type: 'warning', + message: this.translate.instant('Restore settings to defaults ?'), + buttons: [ + this.translate.instant('Delete'), + this.translate.instant('Keep'), + ], + defaultId: 1, + cancelId: 1, + }, + )).response === 0) { + this.profilesService.setProviderDefaults(provider, {}) + await this.config.save() + } + } + blacklistProfile (profile: PartialProfile): void { this.config.store.profileBlacklist = [...this.config.store.profileBlacklist, profile.id] this.config.save()