Browse Source

Improve filter search style

pull/85/head
Thomas 4 years ago
parent
commit
9aeb0d19ca
  1. 3
      apps/client/src/app/components/transactions-table/transactions-table.component.html
  2. 1
      apps/client/src/app/components/transactions-table/transactions-table.component.scss
  3. 20
      apps/client/src/app/components/transactions-table/transactions-table.component.ts

3
apps/client/src/app/components/transactions-table/transactions-table.component.html

@ -3,6 +3,7 @@
<mat-chip-list #chipList aria-label="Search keywords"> <mat-chip-list #chipList aria-label="Search keywords">
<mat-chip <mat-chip
*ngFor="let searchKeyword of searchKeywords" *ngFor="let searchKeyword of searchKeywords"
class="mx-1 my-0 px-2 py-0"
matChipRemove matChipRemove
[removable]="true" [removable]="true"
(removed)="removeKeyword(searchKeyword)" (removed)="removeKeyword(searchKeyword)"
@ -13,7 +14,7 @@
<input <input
#searchInput #searchInput
name="close-outline" name="close-outline"
placeholder="Search for account, currency, symbol or type..." [placeholder]="placeholder"
[formControl]="searchControl" [formControl]="searchControl"
[matAutocomplete]="autocomplete" [matAutocomplete]="autocomplete"
[matChipInputFor]="chipList" [matChipInputFor]="chipList"

1
apps/client/src/app/components/transactions-table/transactions-table.component.scss

@ -11,6 +11,7 @@
.mat-chip { .mat-chip {
cursor: pointer; cursor: pointer;
min-height: 1.5rem !important;
} }
.mat-table { .mat-table {

20
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'; 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 = ','; const SEARCH_STRING_SEPARATOR = ',';
@Component({ @Component({
@ -60,6 +61,7 @@ export class TransactionsTableComponent
string[] string[]
> = this.filteredTransactions$.asObservable(); > = this.filteredTransactions$.asObservable();
public isLoading = true; public isLoading = true;
public placeholder = '';
public routeQueryParams: Subscription; public routeQueryParams: Subscription;
public searchControl = new FormControl(); public searchControl = new FormControl();
public searchKeywords: string[] = []; public searchKeywords: string[] = [];
@ -151,7 +153,7 @@ export class TransactionsTableComponent
if (this.transactions) { if (this.transactions) {
this.dataSource = new MatTableDataSource(this.transactions); this.dataSource = new MatTableDataSource(this.transactions);
this.dataSource.filterPredicate = (data, filter) => { this.dataSource.filterPredicate = (data, filter) => {
const dataString = TransactionsTableComponent.getFilterableValues(data) const dataString = this.getFilterableValues(data)
.join(' ') .join(' ')
.toLowerCase(); .toLowerCase();
let contains = true; let contains = true;
@ -232,26 +234,28 @@ export class TransactionsTableComponent
const lowercaseSearchKeywords = this.searchKeywords.map((keyword) => const lowercaseSearchKeywords = this.searchKeywords.map((keyword) =>
keyword.trim().toLowerCase() keyword.trim().toLowerCase()
); );
this.allFilteredTransactions = TransactionsTableComponent.getSearchableFieldValues( this.allFilteredTransactions = this.getSearchableFieldValues(
this.transactions this.transactions
).filter((item) => { ).filter((item) => {
return !lowercaseSearchKeywords.includes(item.trim().toLowerCase()); return !lowercaseSearchKeywords.includes(item.trim().toLowerCase());
}); });
this.placeholder =
lowercaseSearchKeywords.length <= 0 ? SEARCH_PLACEHOLDER : '';
this.filteredTransactions$.next(this.allFilteredTransactions); this.filteredTransactions$.next(this.allFilteredTransactions);
} }
private static getSearchableFieldValues( private getSearchableFieldValues(transactions: OrderWithAccount[]): string[] {
transactions: OrderWithAccount[]
): string[] {
const fieldValues = new Set<string>(); const fieldValues = new Set<string>();
for (const transaction of transactions) { for (const transaction of transactions) {
this.getFilterableValues(transaction, fieldValues); this.getFilterableValues(transaction, fieldValues);
} }
return [...fieldValues].filter((item) => item != undefined).sort(); return [...fieldValues].filter((item) => item !== undefined).sort();
} }
private static getFilterableValues( private getFilterableValues(
transaction, transaction,
fieldValues: Set<string> = new Set<string>() fieldValues: Set<string> = new Set<string>()
): string[] { ): string[] {
@ -260,6 +264,6 @@ export class TransactionsTableComponent
fieldValues.add(transaction.type); fieldValues.add(transaction.type);
fieldValues.add(transaction.Account?.name); fieldValues.add(transaction.Account?.name);
fieldValues.add(transaction.Account?.Platform?.name); fieldValues.add(transaction.Account?.Platform?.name);
return [...fieldValues].filter((item) => item != undefined); return [...fieldValues].filter((item) => item !== undefined);
} }
} }

Loading…
Cancel
Save