Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Task/reuse toggle component on holdings page (#7586)

Thomas Kaul8124b5e591a3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a3714bcdd8..ad6854433b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Extended the toggle component to support a disabled state
- Extended the toggle component to support icons
+- Reused the toggle component on the portfolio holdings page
## 3.46.0 - 2026-08-09
diff --git a/apps/client/src/app/components/home-holdings/home-holdings.component.ts b/apps/client/src/app/components/home-holdings/home-holdings.component.ts
index 2a06f47abe..45dcd1a971 100644
--- a/apps/client/src/app/components/home-holdings/home-holdings.component.ts
+++ b/apps/client/src/app/components/home-holdings/home-holdings.component.ts
@@ -27,11 +27,8 @@ import {
OnInit
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
-import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
-import { MatButtonToggleModule } from '@angular/material/button-toggle';
import { Router, RouterModule } from '@angular/router';
-import { IonIcon } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { gridOutline, reorderFourOutline } from 'ionicons/icons';
import { DeviceDetectorService } from 'ngx-device-detector';
@@ -39,14 +36,10 @@ import { DeviceDetectorService } from 'ngx-device-detector';
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [
- FormsModule,
GfHoldingsTableComponent,
GfToggleComponent,
GfTreemapChartComponent,
- IonIcon,
MatButtonModule,
- MatButtonToggleModule,
- ReactiveFormsModule,
RouterModule
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
@@ -62,17 +55,29 @@ export class GfHomeHoldingsComponent implements OnInit {
protected hasPermissionToAccessHoldingsChart: boolean;
protected hasPermissionToCreateActivity: boolean;
protected holdings: PortfolioPosition[] | undefined;
+ protected holdingsViewMode: HoldingsViewMode =
+ GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE;
+ protected readonly holdingsViewModeOptions: ToggleOption[] = [
+ {
+ iconName: 'reorder-four-outline',
+ title: $localize`Table`,
+ value: 'TABLE'
+ },
+ {
+ iconName: 'grid-outline',
+ title: $localize`Chart`,
+ value: 'CHART'
+ }
+ ];
protected holdingType: HoldingType = 'ACTIVE';
protected readonly holdingTypeOptions: ToggleOption[] = [
{ label: $localize`Active`, value: 'ACTIVE' },
{ label: $localize`Closed`, value: 'CLOSED' }
];
+ protected isHoldingsViewModeToggleDisabled = true;
protected readonly routerLinkPortfolioActivities =
internalRoutes.portfolio.subRoutes.activities.routerLink;
protected user: User;
- protected readonly viewModeFormControl = new FormControl<HoldingsViewMode>(
- GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE
- );
private readonly changeDetectorRef = inject(ChangeDetectorRef);
private readonly dataService = inject(DataService);
@@ -121,26 +126,22 @@ export class GfHomeHoldingsComponent implements OnInit {
this.changeDetectorRef.markForCheck();
});
+ }
- this.viewModeFormControl.valueChanges
- .pipe(takeUntilDestroyed(this.destroyRef))
- .subscribe((holdingsViewMode) => {
- if (!holdingsViewMode) {
- return;
- }
+ protected onChangeHoldingsViewMode(aHoldingsViewMode: HoldingsViewMode) {
+ this.holdingsViewMode = aHoldingsViewMode;
- this.dataService
- .putUserSetting({ holdingsViewMode })
+ this.dataService
+ .putUserSetting({ holdingsViewMode: aHoldingsViewMode })
+ .pipe(takeUntilDestroyed(this.destroyRef))
+ .subscribe(() => {
+ this.userService
+ .get(true)
.pipe(takeUntilDestroyed(this.destroyRef))
- .subscribe(() => {
- this.userService
- .get(true)
- .pipe(takeUntilDestroyed(this.destroyRef))
- .subscribe((user) => {
- this.user = user;
-
- this.changeDetectorRef.markForCheck();
- });
+ .subscribe((user) => {
+ this.user = user;
+
+ this.changeDetectorRef.markForCheck();
});
});
}
@@ -173,26 +174,22 @@ export class GfHomeHoldingsComponent implements OnInit {
}
private initialize() {
- this.viewModeFormControl.disable({ emitEvent: false });
+ this.isHoldingsViewModeToggleDisabled = true;
if (
this.hasPermissionToAccessHoldingsChart &&
this.holdingType === 'ACTIVE'
) {
- this.viewModeFormControl.enable({ emitEvent: false });
+ this.isHoldingsViewModeToggleDisabled = false;
- this.viewModeFormControl.setValue(
+ this.holdingsViewMode =
this.deviceType === 'mobile'
? GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE
: (this.user?.settings?.holdingsViewMode ??
- GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE),
- { emitEvent: false }
- );
- } else if (this.holdingType === 'CLOSED') {
- this.viewModeFormControl.setValue(
- GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE,
- { emitEvent: false }
- );
+ GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE);
+ } else {
+ this.holdingsViewMode =
+ GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE;
}
this.holdings = undefined;
diff --git a/apps/client/src/app/components/home-holdings/home-holdings.html b/apps/client/src/app/components/home-holdings/home-holdings.html
index c44df40b3b..d3b24e7af3 100644
--- a/apps/client/src/app/components/home-holdings/home-holdings.html
+++ b/apps/client/src/app/components/home-holdings/home-holdings.html
@@ -7,32 +7,23 @@
<div class="row">
<div class="col-lg">
<div class="d-flex">
- <div class="d-flex">
- <div class="d-none d-lg-block">
- <mat-button-toggle-group
- [formControl]="viewModeFormControl"
- [hideSingleSelectionIndicator]="true"
- >
- <mat-button-toggle i18n-title title="Table" value="TABLE">
- <ion-icon name="reorder-four-outline" />
- </mat-button-toggle>
- <mat-button-toggle i18n-title title="Chart" value="CHART">
- <ion-icon name="grid-outline" />
- </mat-button-toggle>
- </mat-button-toggle-group>
- </div>
- </div>
+ <gf-toggle
+ class="d-none d-lg-block"
+ [defaultValue]="holdingsViewMode"
+ [isDisabled]="isHoldingsViewModeToggleDisabled"
+ [options]="holdingsViewModeOptions"
+ (valueChange)="onChangeHoldingsViewMode($event.value)"
+ />
<div class="align-items-center d-flex flex-grow-1 justify-content-end">
<gf-toggle
class="d-none d-lg-block"
[defaultValue]="holdingType"
- [isLoading]="false"
[options]="holdingTypeOptions"
(valueChange)="onChangeHoldingType($event.value)"
/>
</div>
</div>
- @if (viewModeFormControl.value === 'CHART') {
+ @if (holdingsViewMode === 'CHART') {
<gf-treemap-chart
class="mt-3"
cursor="pointer"
@@ -44,7 +35,7 @@
(treemapChartClicked)="onHoldingClicked($event)"
/>
}
- <div [class.d-none]="viewModeFormControl.value !== 'TABLE'">
+ <div [class.d-none]="holdingsViewMode !== 'TABLE'">
<gf-holdings-table
[holdings]="holdings"
[locale]="user?.settings?.locale"
diff --git a/apps/client/src/app/components/home-holdings/home-holdings.scss b/apps/client/src/app/components/home-holdings/home-holdings.scss
index a978004a01..5d4e87f30f 100644
--- a/apps/client/src/app/components/home-holdings/home-holdings.scss
+++ b/apps/client/src/app/components/home-holdings/home-holdings.scss
@@ -1,9 +1,3 @@
:host {
display: block;
-
- .mat-button-toggle-group {
- .mat-button-toggle-appearance-standard {
- --mat-button-toggle-height: 1.5rem;
- }
- }
}