From 633a94b4755932613ed6227c0d8de737090f78b6 Mon Sep 17 00:00:00 2001 From: Karel De Smet Date: Tue, 20 Jan 2026 16:00:28 +0100 Subject: [PATCH] Fix UI confirmation when adding currency to Market Data table --- .../admin-market-data.component.ts | 48 ++++++++++++------- .../create-asset-profile-dialog.component.ts | 14 ++++-- .../symbol-autocomplete.component.ts | 2 +- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts b/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts index bc3b0d374..8fe2ca1b3 100644 --- a/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts +++ b/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts @@ -10,7 +10,7 @@ import { InfoItem, User } from '@ghostfolio/common/interfaces'; -import { AdminMarketDataItem } from '@ghostfolio/common/interfaces/admin-market-data.interface'; +import { AdminMarketData, AdminMarketDataItem } from '@ghostfolio/common/interfaces/admin-market-data.interface'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { GfSymbolPipe } from '@ghostfolio/common/pipes'; import { GfActivitiesFilterComponent } from '@ghostfolio/ui/activities-filter'; @@ -62,7 +62,7 @@ import { } from 'ionicons/icons'; import { DeviceDetectorService } from 'ngx-device-detector'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; -import { Subject } from 'rxjs'; +import { Observable, Subject } from 'rxjs'; import { distinctUntilChanged, switchMap, takeUntil } from 'rxjs/operators'; import { AdminMarketDataService } from './admin-market-data.service'; @@ -482,31 +482,43 @@ export class GfAdminMarketDataComponent dialogRef .afterClosed() .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(({ dataSource, symbol } = {}) => { - if (dataSource && symbol) { - this.adminService + .subscribe(({ addAssetProfile, dataSource, symbol } = {}) => { + this.isLoading = true; + this.changeDetectorRef.markForCheck(); + + let observable: Observable; + + if (!addAssetProfile) { + this.openAssetProfileDialog({ dataSource, symbol }); + observable = this.adminService.fetchAdminMarketData({ + filters: this.activeFilters, + take: this.pageSize + }); + } + + if (addAssetProfile && dataSource && symbol) { + observable = this.adminService .addAssetProfile({ dataSource, symbol }) .pipe( switchMap(() => { - this.isLoading = true; - this.changeDetectorRef.markForCheck(); - return this.adminService.fetchAdminMarketData({ filters: this.activeFilters, take: this.pageSize }); - }), - takeUntil(this.unsubscribeSubject) - ) - .subscribe(({ marketData }) => { - this.dataSource = new MatTableDataSource(marketData); - this.dataSource.sort = this.sort; - this.isLoading = false; - - this.changeDetectorRef.markForCheck(); - }); + }) + ); } + observable.pipe( + takeUntil(this.unsubscribeSubject) + ).subscribe(({ marketData }) => { + this.dataSource = new MatTableDataSource(marketData); + this.dataSource.sort = this.sort; + this.isLoading = false; + + this.changeDetectorRef.markForCheck(); + }); + this.router.navigate(['.'], { relativeTo: this.route }); }); }); diff --git a/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts b/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts index 6c180b034..f8142f145 100644 --- a/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts +++ b/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts @@ -103,7 +103,8 @@ export class GfCreateAssetProfileDialogComponent implements OnDestroy, OnInit { this.dialogRef.close({ dataSource: this.createAssetProfileForm.get('searchSymbol').value.dataSource, - symbol: this.createAssetProfileForm.get('searchSymbol').value.symbol + symbol: this.createAssetProfileForm.get('searchSymbol').value.symbol, + addAssetProfile: true }); } else if (this.mode === 'currency') { const currency = this.createAssetProfileForm.get('addCurrency') @@ -121,18 +122,23 @@ export class GfCreateAssetProfileDialogComponent implements OnDestroy, OnInit { switchMap(() => { return this.adminService.gatherSymbol({ dataSource: this.dataSourceForExchangeRates, - symbol: `${DEFAULT_CURRENCY}${currency}` + symbol: `${DEFAULT_CURRENCY}${currency}`, }); }), takeUntil(this.unsubscribeSubject) ) .subscribe(() => { - this.dialogRef.close(); + this.dialogRef.close({ + dataSource: this.dataSourceForExchangeRates, + symbol: `${DEFAULT_CURRENCY}${currency}`, + addAssetProfile: false + }); }); } else if (this.mode === 'manual') { this.dialogRef.close({ dataSource: 'MANUAL', - symbol: `${this.ghostfolioPrefix}${this.createAssetProfileForm.get('addSymbol').value}` + symbol: `${this.ghostfolioPrefix}${this.createAssetProfileForm.get('addSymbol').value}`, + addAssetProfile: true }); } } diff --git a/libs/ui/src/lib/symbol-autocomplete/symbol-autocomplete.component.ts b/libs/ui/src/lib/symbol-autocomplete/symbol-autocomplete.component.ts index 11d6f09dc..72c3aa6b1 100644 --- a/libs/ui/src/lib/symbol-autocomplete/symbol-autocomplete.component.ts +++ b/libs/ui/src/lib/symbol-autocomplete/symbol-autocomplete.component.ts @@ -121,7 +121,7 @@ export class GfSymbolAutocompleteComponent this.control.valueChanges .pipe( filter((query) => { - if (query.length === 0) { + if (query && query.length === 0) { this.showDefaultOptions(); return false;