From a10d9cb6baa69fe832f389a20a54280130d0231e Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 16 Dec 2023 19:04:08 +0100 Subject: [PATCH] Feature/add lazy loaded activities table to account detail dialog (#2752) * Add lazy-loaded activities table * Update changelog --- CHANGELOG.md | 1 + .../account-detail-dialog.component.ts | 84 ++++++++++++++----- .../account-detail-dialog.html | 18 ++++ .../account-detail-dialog.module.ts | 2 + 4 files changed, 84 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3210ea52..63da0f9bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Introduced the lazy-loaded activities table to the account detail dialog (experimental) - Introduced the lazy-loaded activities table to the position detail dialog (experimental) - Improved the font weight in the value component - Improved the language localization for Türkçe (`tr`) diff --git a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts index aa835b00f..d37defe2f 100644 --- a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts +++ b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts @@ -7,6 +7,8 @@ import { OnInit } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { Sort, SortDirection } from '@angular/material/sort'; +import { MatTableDataSource } from '@angular/material/table'; import { DataService } from '@ghostfolio/client/services/data.service'; import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; import { UserService } from '@ghostfolio/client/services/user/user.service'; @@ -16,6 +18,7 @@ import { HistoricalDataItem, User } from '@ghostfolio/common/interfaces'; +import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { OrderWithAccount } from '@ghostfolio/common/types'; import Big from 'big.js'; import { format, parseISO } from 'date-fns'; @@ -24,7 +27,6 @@ import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { AccountDetailDialogParams } from './interfaces/interfaces'; -import { hasPermission, permissions } from '@ghostfolio/common/permissions'; @Component({ host: { class: 'd-flex flex-column h-100' }, @@ -38,6 +40,7 @@ export class AccountDetailDialog implements OnDestroy, OnInit { public activities: OrderWithAccount[]; public balance: number; public currency: string; + public dataSource: MatTableDataSource; public equity: number; public hasImpersonationId: boolean; public hasPermissionToDeleteAccountBalance: boolean; @@ -46,6 +49,9 @@ export class AccountDetailDialog implements OnDestroy, OnInit { public isLoadingChart: boolean; public name: string; public platformName: string; + public sortColumn = 'date'; + public sortDirection: SortDirection = 'desc'; + public totalItems: number; public transactionCount: number; public user: User; public valueInBaseCurrency: number; @@ -77,8 +83,6 @@ export class AccountDetailDialog implements OnDestroy, OnInit { } public ngOnInit() { - this.isLoadingActivities = true; - this.dataService .fetchAccount(this.data.accountId) .pipe(takeUntil(this.unsubscribeSubject)) @@ -110,19 +114,6 @@ export class AccountDetailDialog implements OnDestroy, OnInit { } ); - this.dataService - .fetchActivities({ - filters: [{ id: this.data.accountId, type: 'ACCOUNT' }] - }) - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(({ activities }) => { - this.activities = activities; - - this.isLoadingActivities = false; - - this.changeDetectorRef.markForCheck(); - }); - this.impersonationStorageService .onChangeHasImpersonation() .pipe(takeUntil(this.unsubscribeSubject)) @@ -131,6 +122,7 @@ export class AccountDetailDialog implements OnDestroy, OnInit { }); this.fetchAccountBalances(); + this.fetchActivities(); this.fetchPortfolioPerformance(); } @@ -151,12 +143,20 @@ export class AccountDetailDialog implements OnDestroy, OnInit { } public onExport() { + let activityIds = []; + + if (this.user?.settings?.isExperimentalFeatures === true) { + activityIds = this.dataSource.data.map(({ id }) => { + return id; + }); + } else { + activityIds = this.activities.map(({ id }) => { + return id; + }); + } + this.dataService - .fetchExport( - this.activities.map(({ id }) => { - return id; - }) - ) + .fetchExport(activityIds) .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((data) => { downloadAsFile({ @@ -172,6 +172,13 @@ export class AccountDetailDialog implements OnDestroy, OnInit { }); } + public onSortChanged({ active, direction }: Sort) { + this.sortColumn = active; + this.sortDirection = direction; + + this.fetchActivities(); + } + private fetchAccountBalances() { this.dataService .fetchAccountBalances(this.data.accountId) @@ -183,6 +190,41 @@ export class AccountDetailDialog implements OnDestroy, OnInit { }); } + private fetchActivities() { + this.isLoadingActivities = true; + + if (this.user?.settings?.isExperimentalFeatures === true) { + this.dataService + .fetchActivities({ + filters: [{ id: this.data.accountId, type: 'ACCOUNT' }], + sortColumn: this.sortColumn, + sortDirection: this.sortDirection + }) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(({ activities, count }) => { + this.dataSource = new MatTableDataSource(activities); + this.totalItems = count; + + this.isLoadingActivities = false; + + this.changeDetectorRef.markForCheck(); + }); + } else { + this.dataService + .fetchActivities({ + filters: [{ id: this.data.accountId, type: 'ACCOUNT' }] + }) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(({ activities }) => { + this.activities = activities; + + this.isLoadingActivities = false; + + this.changeDetectorRef.markForCheck(); + }); + } + } + private fetchPortfolioPerformance() { this.isLoadingChart = true; diff --git a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.html b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.html index 647ba0d6f..1b9ba761b 100644 --- a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.html +++ b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.html @@ -71,7 +71,25 @@ > Activities +