Bugfix/fix create or edit transaction dialog (#382)
* Fix create or edit transaction dialog * Update changelog
This commit is contained in:
parent
861dff9210
commit
98be8745d9
@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Removed the default value of the data source attribute
|
- Removed the default value of the data source attribute
|
||||||
- Upgraded `@storybook` dependencies
|
- Upgraded `@storybook` dependencies
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed an issue in the create or edit transaction dialog
|
||||||
|
|
||||||
### Todo
|
### Todo
|
||||||
|
|
||||||
- Apply data migration (`yarn prisma migrate deploy`)
|
- Apply data migration (`yarn prisma migrate deploy`)
|
||||||
|
@ -37,13 +37,14 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
|||||||
|
|
||||||
public currencies: Currency[] = [];
|
public currencies: Currency[] = [];
|
||||||
public currentMarketPrice = null;
|
public currentMarketPrice = null;
|
||||||
public filteredLookupItems: Observable<LookupItem[]>;
|
public filteredLookupItems: LookupItem[];
|
||||||
|
public filteredLookupItemsObservable: Observable<LookupItem[]>;
|
||||||
public isLoading = false;
|
public isLoading = false;
|
||||||
public platforms: { id: string; name: string }[];
|
public platforms: { id: string; name: string }[];
|
||||||
public searchSymbolCtrl = new FormControl(
|
public searchSymbolCtrl = new FormControl(
|
||||||
{
|
{
|
||||||
dataSource: this.data.transaction.dataSource,
|
dataSource: this.data.transaction.dataSource,
|
||||||
name: this.data.transaction.symbol
|
symbol: this.data.transaction.symbol
|
||||||
},
|
},
|
||||||
Validators.required
|
Validators.required
|
||||||
);
|
);
|
||||||
@ -63,18 +64,26 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
|||||||
this.currencies = currencies;
|
this.currencies = currencies;
|
||||||
this.platforms = platforms;
|
this.platforms = platforms;
|
||||||
|
|
||||||
this.filteredLookupItems = this.searchSymbolCtrl.valueChanges.pipe(
|
this.filteredLookupItemsObservable =
|
||||||
startWith(''),
|
this.searchSymbolCtrl.valueChanges.pipe(
|
||||||
debounceTime(400),
|
startWith(''),
|
||||||
distinctUntilChanged(),
|
debounceTime(400),
|
||||||
switchMap((query: string) => {
|
distinctUntilChanged(),
|
||||||
if (isString(query)) {
|
switchMap((query: string) => {
|
||||||
return this.dataService.fetchSymbols(query);
|
if (isString(query)) {
|
||||||
}
|
const filteredLookupItemsObservable =
|
||||||
|
this.dataService.fetchSymbols(query);
|
||||||
|
|
||||||
return [];
|
filteredLookupItemsObservable.subscribe((filteredLookupItems) => {
|
||||||
})
|
this.filteredLookupItems = filteredLookupItems;
|
||||||
);
|
});
|
||||||
|
|
||||||
|
return filteredLookupItemsObservable;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
if (this.data.transaction.symbol) {
|
if (this.data.transaction.symbol) {
|
||||||
this.dataService
|
this.dataService
|
||||||
@ -96,17 +105,22 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public displayFn(aLookupItem: LookupItem) {
|
public displayFn(aLookupItem: LookupItem) {
|
||||||
return aLookupItem?.name ?? '';
|
return aLookupItem?.symbol ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public onBlurSymbol() {
|
public onBlurSymbol() {
|
||||||
this.data.transaction.currency = null;
|
const currentLookupItem = this.filteredLookupItems.find((lookupItem) => {
|
||||||
this.data.transaction.dataSource = null;
|
return lookupItem.symbol === this.data.transaction.symbol;
|
||||||
|
});
|
||||||
|
|
||||||
if (this.autocomplete.isOpen) {
|
if (currentLookupItem) {
|
||||||
this.searchSymbolCtrl.setErrors({ incorrect: true });
|
this.updateSymbol(currentLookupItem.symbol);
|
||||||
} else {
|
} else {
|
||||||
this.data.transaction.unitPrice = null;
|
this.searchSymbolCtrl.setErrors({ incorrect: true });
|
||||||
|
|
||||||
|
this.data.transaction.currency = null;
|
||||||
|
this.data.transaction.dataSource = null;
|
||||||
|
this.data.transaction.symbol = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.changeDetectorRef.markForCheck();
|
this.changeDetectorRef.markForCheck();
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
>
|
>
|
||||||
<ng-container>
|
<ng-container>
|
||||||
<mat-option
|
<mat-option
|
||||||
*ngFor="let lookupItem of filteredLookupItems | async"
|
*ngFor="let lookupItem of filteredLookupItemsObservable | async"
|
||||||
class="autocomplete"
|
class="autocomplete"
|
||||||
[value]="lookupItem"
|
[value]="lookupItem"
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user