Browse Source

Fix UI confirmation when adding currency to Market Data table

pull/6225/head
Karel De Smet 2 weeks ago
parent
commit
633a94b475
  1. 48
      apps/client/src/app/components/admin-market-data/admin-market-data.component.ts
  2. 14
      apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts
  3. 2
      libs/ui/src/lib/symbol-autocomplete/symbol-autocomplete.component.ts

48
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<AdminMarketData>;
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 });
});
});

14
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
});
}
}

2
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;

Loading…
Cancel
Save