Skip to content

Commit

Permalink
feat(settings): #7265 add a button to reset global & groups settings …
Browse files Browse the repository at this point in the history
…to defaults
  • Loading branch information
Clem-Fern committed Aug 12, 2023
1 parent c108476 commit f369b14
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion tabby-settings/src/components/editProfileGroupModal.component.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -13,6 +13,8 @@ export class EditProfileGroupModalComponent<G extends ProfileGroup> {

constructor (
private modalInstance: NgbActiveModal,
private platform: PlatformService,
private translate: TranslateService,
) {}

save () {
Expand All @@ -26,6 +28,24 @@ export class EditProfileGroupModalComponent<G extends ProfileGroup> {
editDefaults (provider: ProfileProvider<Profile>) {
this.modalInstance.close({ group: this.group, provider })
}

async deleteDefaults (provider: ProfileProvider<Profile>): Promise<void> {
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<G extends ProfileGroup> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
18 changes: 18 additions & 0 deletions tabby-settings/src/components/profilesSettingsTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,24 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
await this.config.save()
}

async deleteDefaults (provider: ProfileProvider<Profile>): Promise<void> {
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<Profile>): void {
this.config.store.profileBlacklist = [...this.config.store.profileBlacklist, profile.id]
this.config.save()
Expand Down

0 comments on commit f369b14

Please sign in to comment.