From d1ec42ed5b98c837434f13c19e65de19f0ce37ba Mon Sep 17 00:00:00 2001 From: Kevin Lien Date: Wed, 4 Oct 2023 22:19:25 +0200 Subject: [PATCH] review changes - remove Platform interface and use existing one in prisma/client - several small adjustments - bugfix: on item select, check if value is string --- ...eate-or-update-account-dialog.component.ts | 37 ++++++++++--------- .../create-or-update-account-dialog.html | 2 +- .../create-or-update-account-dialog.module.ts | 2 +- .../interfaces/interfaces.ts | 5 --- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts index 788c96ac6..504cc72b8 100644 --- a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts +++ b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts @@ -18,10 +18,8 @@ import { DataService } from '@ghostfolio/client/services/data.service'; import { Observable, Subject } from 'rxjs'; import { map, startWith } from 'rxjs/operators'; -import { - CreateOrUpdateAccountDialogParams, - Platform -} from './interfaces/interfaces'; +import { CreateOrUpdateAccountDialogParams } from './interfaces/interfaces'; +import { Platform } from '@prisma/client'; @Component({ host: { class: 'h-100' }, @@ -33,8 +31,8 @@ import { export class CreateOrUpdateAccountDialog implements OnDestroy { public accountForm: FormGroup; public currencies: string[] = []; - public platforms: Platform[]; public filteredPlatforms: Observable; + public platforms: Platform[]; private unsubscribeSubject = new Subject(); @@ -49,7 +47,9 @@ export class CreateOrUpdateAccountDialog implements OnDestroy { const { currencies, platforms } = this.dataService.fetchInfo(); this.currencies = currencies; - this.platforms = platforms; + this.platforms = platforms.map((platform) => { + return { ...platform, url: '' }; + }); this.accountForm = this.formBuilder.group({ accountId: [{ disabled: true, value: this.data.account.id }], @@ -59,9 +59,9 @@ export class CreateOrUpdateAccountDialog implements OnDestroy { isExcluded: [this.data.account.isExcluded], name: [this.data.account.name, Validators.required], platformId: [ - this.platforms.find( - (platform) => platform.id === this.data.account.platformId - ), + this.platforms.find(({ id }) => { + return id === this.data.account.platformId; + }), this._autocompleteObjectValidator() ] }); @@ -106,22 +106,23 @@ export class CreateOrUpdateAccountDialog implements OnDestroy { public autoCompleteCheck() { const inputValue = this.accountForm.controls['platformId'].value; - const matchingEntry = this.platforms.find( - (platform) => platform.name === inputValue - ); - this.accountForm.controls['platformId'].setValue(matchingEntry); + if (typeof inputValue === 'string') { + const matchingEntry = this.platforms.find(({ name }) => { + return name === inputValue; + }); + this.accountForm.controls['platformId'].setValue(matchingEntry); + } } displayFn(platform: Platform) { - return platform && platform.name ? platform.name : ''; + return platform?.name ? platform.name : ''; } private _filter(value: string): Platform[] { const filterValue = value.toLowerCase(); - - return this.platforms.filter((platformEntry) => - platformEntry.name.toLowerCase().includes(filterValue) - ); + return this.platforms.filter(({ name }) => { + return name.toLowerCase().includes(filterValue); + }); } private _autocompleteObjectValidator(): ValidatorFn { diff --git a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html index 5774faa6b..77c909074 100644 --- a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html +++ b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html @@ -56,7 +56,7 @@ *ngFor="let platformEntry of filteredPlatforms | async" [value]="platformEntry" > - {{platformEntry.name}} + {{ platformEntry.name }} diff --git a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.module.ts b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.module.ts index b5c3984a1..9d65a6d6b 100644 --- a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.module.ts +++ b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.module.ts @@ -16,13 +16,13 @@ import { CreateOrUpdateAccountDialog } from './create-or-update-account-dialog.c imports: [ CommonModule, FormsModule, + MatAutocompleteModule, MatButtonModule, MatCheckboxModule, MatDialogModule, MatFormFieldModule, MatInputModule, MatSelectModule, - MatAutocompleteModule, ReactiveFormsModule ] }) diff --git a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/interfaces/interfaces.ts b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/interfaces/interfaces.ts index 6252fcfd5..ffe4f14f6 100644 --- a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/interfaces/interfaces.ts +++ b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/interfaces/interfaces.ts @@ -3,8 +3,3 @@ import { Account } from '@prisma/client'; export interface CreateOrUpdateAccountDialogParams { account: Account; } - -export interface Platform { - id: string; - name: string; -}