From bf9ebdb84e01ad71819135d8b9d7b93c1e25fadc Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 22 Nov 2024 20:59:08 +0100 Subject: [PATCH] Refactoring --- .../allocations/allocations-page.html | 2 +- .../top-holdings/top-holdings.component.html | 117 ++++++++---------- .../top-holdings/top-holdings.component.scss | 73 +++-------- .../top-holdings/top-holdings.component.ts | 76 +----------- 4 files changed, 74 insertions(+), 194 deletions(-) diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.html b/apps/client/src/app/pages/portfolio/allocations/allocations-page.html index ea5fafa13..f2dff76f3 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.html +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.html @@ -347,7 +347,7 @@ [locale]="user?.settings?.locale" [pageSize]="10" [topHoldings]="topHoldings" - (proportionChartClicked)="onSymbolChartClicked($event)" + (holdingClicked)="onSymbolChartClicked($event)" /> diff --git a/libs/ui/src/lib/top-holdings/top-holdings.component.html b/libs/ui/src/lib/top-holdings/top-holdings.component.html index 481ed1584..71e15b8c1 100644 --- a/libs/ui/src/lib/top-holdings/top-holdings.component.html +++ b/libs/ui/src/lib/top-holdings/top-holdings.component.html @@ -2,14 +2,18 @@ + + + + + + - @@ -61,6 +55,7 @@ td { + font-weight: bold; } } - .colorBadge { - width: 0.75em; - height: 0.75em; - border-radius: 100%; - display: inline-block; + &.holding-detail { + height: 0; } - table, - tr, - th, - td { - background-color: transparent; - } + .holding-parents-table { + --table-padding: 0.5em; + + tr { + height: auto; - tr { - height: auto; - &:hover { - background-color: var(--mat-table-background-color-hover); + td { + padding: var(--table-padding); + } } } - th, - td { - padding: var(--table-padding); - } } } } diff --git a/libs/ui/src/lib/top-holdings/top-holdings.component.ts b/libs/ui/src/lib/top-holdings/top-holdings.component.ts index 7bb1ff889..400c68da5 100644 --- a/libs/ui/src/lib/top-holdings/top-holdings.component.ts +++ b/libs/ui/src/lib/top-holdings/top-holdings.component.ts @@ -27,29 +27,11 @@ import { } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; import { MatPaginator, MatPaginatorModule } from '@angular/material/paginator'; -import { MatSort, MatSortModule } from '@angular/material/sort'; import { MatTableDataSource, MatTableModule } from '@angular/material/table'; -import { MatTooltipModule } from '@angular/material/tooltip'; import { DataSource } from '@prisma/client'; -import { get } from 'lodash'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { Subject } from 'rxjs'; -const { - blue, - cyan, - grape, - green, - indigo, - lime, - orange, - pink, - red, - teal, - violet, - yellow -} = require('open-color'); - @Component({ animations: [ trigger('detailExpand', [ @@ -67,9 +49,7 @@ const { GfValueComponent, MatButtonModule, MatPaginatorModule, - MatSortModule, MatTableModule, - MatTooltipModule, NgxSkeletonLoaderModule ], schemas: [CUSTOM_ELEMENTS_SCHEMA], @@ -91,14 +71,9 @@ export class GfTopHoldingsComponent implements OnChanges, OnDestroy { }; } = {}; - @Output() proportionChartClicked = new EventEmitter(); + @Output() holdingClicked = new EventEmitter(); @ViewChild(MatPaginator) paginator: MatPaginator; - @ViewChild(MatSort) sort: MatSort; - - private colorMap: { - [symbol: string]: string; - } = {}; public dataSource = new MatTableDataSource(); public displayedColumns: string[] = [ @@ -106,66 +81,25 @@ export class GfTopHoldingsComponent implements OnChanges, OnDestroy { 'valueInBaseCurrency', 'allocationInPercentage' ]; - public displayedHoldingParentColumns: string[] = [ - 'name', - 'symbol', - 'valueInBaseCurrency', - 'allocationInPercentage' - ]; public isLoading = true; private unsubscribeSubject = new Subject(); - private colorPaletteIndex = 0; - private colorPalette = [ - blue[5], - teal[5], - lime[5], - orange[5], - pink[5], - violet[5], - indigo[5], - cyan[5], - green[5], - yellow[5], - red[5], - grape[5] - ]; - - public getColor(symbol) { - if (this.colorMap[symbol]) { - // Reuse color - return this.colorMap[symbol]; - } else { - const color = this.colorPalette[this.colorPaletteIndex]; - this.colorPaletteIndex = - this.colorPaletteIndex < this.colorPalette.length - ? this.colorPaletteIndex + 1 - : 0; - this.colorMap[symbol] = color; - return color; - } - } - - public onClickOpenPositionModal(holding: AssetProfileIdentifier) { - try { - this.proportionChartClicked.emit(holding); - } catch {} - } - public ngOnChanges() { this.isLoading = true; this.dataSource = new MatTableDataSource(this.topHoldings); this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; - this.dataSource.sortingDataAccessor = get; if (this.topHoldings) { this.isLoading = false; } } + public onClickHolding(assetProfileIdentifier: AssetProfileIdentifier) { + this.holdingClicked.emit(assetProfileIdentifier); + } + public onShowAllHoldings() { this.pageSize = Number.MAX_SAFE_INTEGER;
+ Name @@ -18,12 +22,7 @@ - + Value @@ -38,12 +37,7 @@ - + Allocation % @@ -68,71 +63,61 @@ [@detailExpand]="element.expand ? 'expanded' : 'collapsed'" class="allocationByParent" > -
-
- @for ( - parentHolding of element.parents?.slice(0, 10); - track parentHolding; - let i = $index - ) { -
- {{ parentHolding?.symbol }} -
- } -
- +
+ + + + + + - - - - - - + - +
Name - {{ parentHolding?.name }} Symbol - {{ parentHolding?.symbol }} + + Name Value - +
+ +
+
+ Value Allocation - +
+ +
+
+ Allocation + %
@@ -144,8 +129,10 @@