Feature/improve preselected currency in create or update activity dialog (#2349)
* Preselect currency based on account's currency * Update changelog
This commit is contained in:
parent
e23bf62859
commit
c668d7b456
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Improved the preselected currency based on the account's currency in the create or edit activity dialog
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fixed a memory leak related to the server's timezone (behind UTC) in the data gathering
|
- Fixed a memory leak related to the server's timezone (behind UTC) in the data gathering
|
||||||
|
@ -20,7 +20,7 @@ import { translate } from '@ghostfolio/ui/i18n';
|
|||||||
import { AssetClass, AssetSubClass, Tag, Type } from '@prisma/client';
|
import { AssetClass, AssetSubClass, Tag, Type } from '@prisma/client';
|
||||||
import { isUUID } from 'class-validator';
|
import { isUUID } from 'class-validator';
|
||||||
import { EMPTY, Observable, Subject, lastValueFrom, of } from 'rxjs';
|
import { EMPTY, Observable, Subject, lastValueFrom, of } from 'rxjs';
|
||||||
import { catchError, map, startWith, takeUntil } from 'rxjs/operators';
|
import { catchError, delay, map, startWith, takeUntil } from 'rxjs/operators';
|
||||||
|
|
||||||
import { CreateOrUpdateActivityDialogParams } from './interfaces/interfaces';
|
import { CreateOrUpdateActivityDialogParams } from './interfaces/interfaces';
|
||||||
|
|
||||||
@ -139,7 +139,12 @@ export class CreateOrUpdateActivityDialog implements OnDestroy {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.activityForm.valueChanges
|
this.activityForm.valueChanges
|
||||||
.pipe(takeUntil(this.unsubscribeSubject))
|
.pipe(
|
||||||
|
// Slightly delay until the more specific form control value changes have
|
||||||
|
// completed
|
||||||
|
delay(300),
|
||||||
|
takeUntil(this.unsubscribeSubject)
|
||||||
|
)
|
||||||
.subscribe(async () => {
|
.subscribe(async () => {
|
||||||
let exchangeRateOfFee = 1;
|
let exchangeRateOfFee = 1;
|
||||||
let exchangeRateOfUnitPrice = 1;
|
let exchangeRateOfUnitPrice = 1;
|
||||||
@ -234,6 +239,23 @@ export class CreateOrUpdateActivityDialog implements OnDestroy {
|
|||||||
this.changeDetectorRef.markForCheck();
|
this.changeDetectorRef.markForCheck();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.activityForm.controls['accountId'].valueChanges.subscribe(
|
||||||
|
(accountId) => {
|
||||||
|
const type = this.activityForm.controls['type'].value;
|
||||||
|
|
||||||
|
if (type === 'FEE' || type === 'ITEM' || type === 'LIABILITY') {
|
||||||
|
const currency =
|
||||||
|
this.data.accounts.find(({ id }) => {
|
||||||
|
return id === accountId;
|
||||||
|
})?.currency ?? this.data.user.settings.baseCurrency;
|
||||||
|
|
||||||
|
this.activityForm.controls['currency'].setValue(currency);
|
||||||
|
this.activityForm.controls['currencyOfFee'].setValue(currency);
|
||||||
|
this.activityForm.controls['currencyOfUnitPrice'].setValue(currency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
this.activityForm.controls['searchSymbol'].valueChanges.subscribe(() => {
|
this.activityForm.controls['searchSymbol'].valueChanges.subscribe(() => {
|
||||||
if (this.activityForm.controls['searchSymbol'].invalid) {
|
if (this.activityForm.controls['searchSymbol'].invalid) {
|
||||||
this.data.activity.SymbolProfile = null;
|
this.data.activity.SymbolProfile = null;
|
||||||
@ -269,19 +291,21 @@ export class CreateOrUpdateActivityDialog implements OnDestroy {
|
|||||||
Validators.required
|
Validators.required
|
||||||
);
|
);
|
||||||
this.activityForm.controls['accountId'].updateValueAndValidity();
|
this.activityForm.controls['accountId'].updateValueAndValidity();
|
||||||
this.activityForm.controls['currency'].setValue(
|
|
||||||
this.data.user.settings.baseCurrency
|
const currency =
|
||||||
);
|
this.data.accounts.find(({ id }) => {
|
||||||
this.activityForm.controls['currencyOfFee'].setValue(
|
return id === this.activityForm.controls['accountId'].value;
|
||||||
this.data.user.settings.baseCurrency
|
})?.currency ?? this.data.user.settings.baseCurrency;
|
||||||
);
|
|
||||||
this.activityForm.controls['currencyOfUnitPrice'].setValue(
|
this.activityForm.controls['currency'].setValue(currency);
|
||||||
this.data.user.settings.baseCurrency
|
this.activityForm.controls['currencyOfFee'].setValue(currency);
|
||||||
);
|
this.activityForm.controls['currencyOfUnitPrice'].setValue(currency);
|
||||||
|
|
||||||
this.activityForm.controls['dataSource'].removeValidators(
|
this.activityForm.controls['dataSource'].removeValidators(
|
||||||
Validators.required
|
Validators.required
|
||||||
);
|
);
|
||||||
this.activityForm.controls['dataSource'].updateValueAndValidity();
|
this.activityForm.controls['dataSource'].updateValueAndValidity();
|
||||||
|
this.activityForm.controls['feeInCustomCurrency'].reset();
|
||||||
this.activityForm.controls['name'].setValidators(Validators.required);
|
this.activityForm.controls['name'].setValidators(Validators.required);
|
||||||
this.activityForm.controls['name'].updateValueAndValidity();
|
this.activityForm.controls['name'].updateValueAndValidity();
|
||||||
this.activityForm.controls['quantity'].setValue(1);
|
this.activityForm.controls['quantity'].setValue(1);
|
||||||
@ -296,23 +320,25 @@ export class CreateOrUpdateActivityDialog implements OnDestroy {
|
|||||||
Validators.required
|
Validators.required
|
||||||
);
|
);
|
||||||
this.activityForm.controls['accountId'].updateValueAndValidity();
|
this.activityForm.controls['accountId'].updateValueAndValidity();
|
||||||
this.activityForm.controls['currency'].setValue(
|
|
||||||
this.data.user.settings.baseCurrency
|
const currency =
|
||||||
);
|
this.data.accounts.find(({ id }) => {
|
||||||
this.activityForm.controls['currencyOfFee'].setValue(
|
return id === this.activityForm.controls['accountId'].value;
|
||||||
this.data.user.settings.baseCurrency
|
})?.currency ?? this.data.user.settings.baseCurrency;
|
||||||
);
|
|
||||||
this.activityForm.controls['currencyOfUnitPrice'].setValue(
|
this.activityForm.controls['currency'].setValue(currency);
|
||||||
this.data.user.settings.baseCurrency
|
this.activityForm.controls['currencyOfFee'].setValue(currency);
|
||||||
);
|
this.activityForm.controls['currencyOfUnitPrice'].setValue(currency);
|
||||||
|
|
||||||
this.activityForm.controls['dataSource'].removeValidators(
|
this.activityForm.controls['dataSource'].removeValidators(
|
||||||
Validators.required
|
Validators.required
|
||||||
);
|
);
|
||||||
this.activityForm.controls['dataSource'].updateValueAndValidity();
|
this.activityForm.controls['dataSource'].updateValueAndValidity();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
type === 'FEE' &&
|
(type === 'FEE' &&
|
||||||
this.activityForm.controls['feeInCustomCurrency'].value === 0
|
this.activityForm.controls['feeInCustomCurrency'].value === 0) ||
|
||||||
|
type === 'LIABILITY'
|
||||||
) {
|
) {
|
||||||
this.activityForm.controls['feeInCustomCurrency'].reset();
|
this.activityForm.controls['feeInCustomCurrency'].reset();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user