From 42b9178d96f72993097938ad54d7a4849c384ded Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Fri, 14 May 2021 21:09:30 +0200 Subject: [PATCH] Feature/improve filter search in transactions table (#85) * Improve filter search style * Update changelog --- CHANGELOG.md | 1 + .../transactions-table.component.html | 3 +- .../transactions-table.component.scss | 1 + .../transactions-table.component.ts | 31 +++++++++++++------ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac499c9e4..acbda8895 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Harmonized the style of various tables - Keep the color per type when switching between _Initial_ and _Current_ in pie charts - Upgraded `chart.js` from version `3.0.2` to `3.2.1` +- Improved the style of the transaction filtering component ### Fixed diff --git a/apps/client/src/app/components/transactions-table/transactions-table.component.html b/apps/client/src/app/components/transactions-table/transactions-table.component.html index da34b315e..4f33485e0 100644 --- a/apps/client/src/app/components/transactions-table/transactions-table.component.html +++ b/apps/client/src/app/components/transactions-table/transactions-table.component.html @@ -3,6 +3,7 @@ diff --git a/apps/client/src/app/components/transactions-table/transactions-table.component.scss b/apps/client/src/app/components/transactions-table/transactions-table.component.scss index 9d32478b8..5984efe27 100644 --- a/apps/client/src/app/components/transactions-table/transactions-table.component.scss +++ b/apps/client/src/app/components/transactions-table/transactions-table.component.scss @@ -11,6 +11,7 @@ .mat-chip { cursor: pointer; + min-height: 1.5rem !important; } .mat-table { diff --git a/apps/client/src/app/components/transactions-table/transactions-table.component.ts b/apps/client/src/app/components/transactions-table/transactions-table.component.ts index 71c70a4cd..0d2583efe 100644 --- a/apps/client/src/app/components/transactions-table/transactions-table.component.ts +++ b/apps/client/src/app/components/transactions-table/transactions-table.component.ts @@ -28,6 +28,7 @@ import { takeUntil } from 'rxjs/operators'; import { PositionDetailDialog } from '../position/position-detail-dialog/position-detail-dialog.component'; +const SEARCH_PLACEHOLDER = 'Search for account, currency, symbol or type...'; const SEARCH_STRING_SEPARATOR = ','; @Component({ @@ -60,6 +61,7 @@ export class TransactionsTableComponent string[] > = this.filteredTransactions$.asObservable(); public isLoading = true; + public placeholder = ''; public routeQueryParams: Subscription; public searchControl = new FormControl(); public searchKeywords: string[] = []; @@ -151,7 +153,7 @@ export class TransactionsTableComponent if (this.transactions) { this.dataSource = new MatTableDataSource(this.transactions); this.dataSource.filterPredicate = (data, filter) => { - const dataString = TransactionsTableComponent.getFilterableValues(data) + const dataString = this.getFilterableValues(data) .join(' ') .toLowerCase(); let contains = true; @@ -232,27 +234,35 @@ export class TransactionsTableComponent const lowercaseSearchKeywords = this.searchKeywords.map((keyword) => keyword.trim().toLowerCase() ); - this.allFilteredTransactions = TransactionsTableComponent.getSearchableFieldValues( + + this.placeholder = + lowercaseSearchKeywords.length <= 0 ? SEARCH_PLACEHOLDER : ''; + + this.allFilteredTransactions = this.getSearchableFieldValues( this.transactions ).filter((item) => { return !lowercaseSearchKeywords.includes(item.trim().toLowerCase()); }); + this.filteredTransactions$.next(this.allFilteredTransactions); } - private static getSearchableFieldValues( - transactions: OrderWithAccount[] - ): string[] { + private getSearchableFieldValues(transactions: OrderWithAccount[]): string[] { const fieldValues = new Set(); + for (const transaction of transactions) { this.getFilterableValues(transaction, fieldValues); } - return [...fieldValues].filter((item) => item != undefined).sort(); + return [...fieldValues] + .filter((item) => { + return item !== undefined; + }) + .sort(); } - private static getFilterableValues( - transaction, + private getFilterableValues( + transaction: OrderWithAccount, fieldValues: Set = new Set() ): string[] { fieldValues.add(transaction.currency); @@ -260,6 +270,9 @@ export class TransactionsTableComponent fieldValues.add(transaction.type); fieldValues.add(transaction.Account?.name); fieldValues.add(transaction.Account?.Platform?.name); - return [...fieldValues].filter((item) => item != undefined); + + return [...fieldValues].filter((item) => { + return item !== undefined; + }); } }