Skip to content

Commit

Permalink
NAS-130629: Add "Reset" to configure dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
denysbutenko committed Aug 29, 2024
1 parent 7b977a5 commit f15344e
Show file tree
Hide file tree
Showing 91 changed files with 234 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@

@if (isEditing()) {
<div class="edit-mode-buttons">
@if (customLayout()) {
<button
mat-button
type="button"
ixTest="reset"
[disabled]="isLoading()"
(click)="onReset()"
>
{{ 'Reset' | translate }}
</button>
}

<button
mat-button
class="add-button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { provideMockStore } from '@ngrx/store/testing';
import { MockComponent, MockDirective } from 'ng-mocks';
import { NgxSkeletonLoaderComponent } from 'ngx-skeleton-loader';
import { BehaviorSubject, of } from 'rxjs';
import { DialogService } from 'app/modules/dialog/dialog.service';
import { IxDropGridDirective } from 'app/modules/ix-drop-grid/ix-drop-grid.directive';
import { IxIconHarness } from 'app/modules/ix-icon/ix-icon.harness';
import { PageHeaderComponent } from 'app/modules/page-header/page-title-header/page-header.component';
Expand All @@ -16,6 +17,7 @@ import {
import { WidgetGroupComponent } from 'app/pages/dashboard/components/widget-group/widget-group.component';
import { WidgetGroupFormComponent } from 'app/pages/dashboard/components/widget-group-form/widget-group-form.component';
import { DashboardStore } from 'app/pages/dashboard/services/dashboard.store';
import { defaultWidgets } from 'app/pages/dashboard/services/default-widgets.constant';
import { WidgetGroup, WidgetGroupLayout } from 'app/pages/dashboard/types/widget-group.interface';
import { ChainedComponentResponse, IxChainedSlideInService } from 'app/services/ix-chained-slide-in.service';

Expand All @@ -40,6 +42,9 @@ describe('DashboardComponent', () => {
MockDirective(IxDropGridDirective),
],
providers: [
mockProvider(DialogService, {
confirm: jest.fn(() => of(true)),
}),
mockProvider(DashboardStore, {
groups$,
isLoading$,
Expand Down Expand Up @@ -144,6 +149,21 @@ describe('DashboardComponent', () => {
.toHaveBeenCalledWith(WidgetGroupFormComponent, true);
});

it('resets configuration to defaults when Reset is pressed', async () => {
const resetButton = await loader.getHarness(MatButtonHarness.with({ text: 'Reset' }));
await resetButton.click();

expect(spectator.inject(DialogService).confirm).toHaveBeenCalledWith({
buttonText: 'Reset',
cancelText: 'Cancel',
hideCheckbox: true,
message: 'Are you sure you want to reset your dashboard to the default layout?',
title: 'Reset Dashboard',
});

expect(spectator.inject(DashboardStore).save).toHaveBeenCalledWith(defaultWidgets);
});

it('saves new configuration when Save is pressed', async () => {
const deleteIcon = await loader.getHarness(IxIconHarness.with({ name: 'delete' }));
await deleteIcon.click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import {
import { toSignal } from '@angular/core/rxjs-interop';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateService } from '@ngx-translate/core';
import { isEqual } from 'lodash-es';
import { filter, switchMap } from 'rxjs';
import { EmptyType } from 'app/enums/empty-type.enum';
import { EmptyConfig } from 'app/interfaces/empty-config.interface';
import { DialogService } from 'app/modules/dialog/dialog.service';
import { SnackbarService } from 'app/modules/snackbar/services/snackbar.service';
import { dashboardElements } from 'app/pages/dashboard/components/dashboard/dashboard.elements';
import { WidgetGroupFormComponent } from 'app/pages/dashboard/components/widget-group-form/widget-group-form.component';
import { DashboardStore } from 'app/pages/dashboard/services/dashboard.store';
import { defaultWidgets } from 'app/pages/dashboard/services/default-widgets.constant';
import { WidgetGroup } from 'app/pages/dashboard/types/widget-group.interface';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { ChainedComponentResponse, IxChainedSlideInService } from 'app/services/ix-chained-slide-in.service';
Expand Down Expand Up @@ -46,6 +50,9 @@ export class DashboardComponent implements OnInit {
key: 'dashboardConfigure',
message: this.translate.instant('New widgets and layouts.'),
};
readonly customLayout = computed(() => {
return !isEqual(this.savedGroups(), defaultWidgets);
});

emptyDashboardConf: EmptyConfig = {
type: EmptyType.NoPageData,
Expand All @@ -61,6 +68,7 @@ export class DashboardComponent implements OnInit {
private errorHandler: ErrorHandlerService,
private translate: TranslateService,
private snackbar: SnackbarService,
private dialog: DialogService,
) {}

ngOnInit(): void {
Expand Down Expand Up @@ -136,6 +144,24 @@ export class DashboardComponent implements OnInit {
});
}

protected onReset(): void {
this.dialog.confirm({
title: this.translate.instant('Reset Dashboard'),
message: this.translate.instant('Are you sure you want to reset your dashboard to the default layout?'),
hideCheckbox: true,
buttonText: this.translate.instant('Reset'),
cancelText: this.translate.instant('Cancel'),
}).pipe(
filter(Boolean),
switchMap(() => this.dashboardStore.save(defaultWidgets)),
this.errorHandler.catchError(),
untilDestroyed(this),
).subscribe(() => {
this.isEditing.set(false);
this.snackbar.success(this.translate.instant('Dashboard settings saved'));
});
}

private loadGroups(): void {
this.dashboardStore.groups$
.pipe(untilDestroyed(this))
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/af.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/az.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/be.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/br.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3001,6 +3002,7 @@
"Reserved space for this dataset and all children": "",
"Reset": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -2353,6 +2354,7 @@
"Reserved for Dataset": "",
"Reserved for Dataset & Children": "",
"Reset": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/dsb.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/en-au.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@
"Are you sure you want to delete this task?": "",
"Are you sure you want to delete user <b>\"{user}\"</b>?": "",
"Are you sure you want to deregister TrueCommand Cloud Service?": "",
"Are you sure you want to reset your dashboard to the default layout?": "",
"Are you sure you want to start over?": "",
"Are you sure you want to stop connecting to the TrueCommand Cloud Service?": "",
"Are you sure you want to sync from peer?": "",
Expand Down Expand Up @@ -3325,6 +3326,7 @@
"Reset": "",
"Reset Config": "",
"Reset Configuration": "",
"Reset Dashboard": "",
"Reset Default Config": "",
"Reset Defaults": "",
"Reset Search": "",
Expand Down
Loading

0 comments on commit f15344e

Please sign in to comment.