diff --git a/CHANGELOG.md b/CHANGELOG.md index 5909cb3a1..feac50910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased -### Changelog +### Changed +- Adapted the options of the date range selector in the assistant dynamically based on the user’s first activity - Migrated the `@ghostfolio/ui/assistant` component to control flow - Migrated the `@ghostfolio/ui/value` component to control flow - Improved the language localization for Chinese (`zh`) diff --git a/libs/ui/src/lib/assistant/assistant.component.ts b/libs/ui/src/lib/assistant/assistant.component.ts index a74ef310a..a5a5fdb9f 100644 --- a/libs/ui/src/lib/assistant/assistant.component.ts +++ b/libs/ui/src/lib/assistant/assistant.component.ts @@ -40,6 +40,7 @@ import { MatMenuTrigger } from '@angular/material/menu'; import { MatSelectModule } from '@angular/material/select'; import { RouterModule } from '@angular/router'; import { Account, AssetClass, DataSource } from '@prisma/client'; +import { differenceInYears } from 'date-fns'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { EMPTY, Observable, Subject, merge, of } from 'rxjs'; import { @@ -333,7 +334,10 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { this.accounts = this.user?.accounts ?? []; this.dateRangeOptions = [ - { label: $localize`Today`, value: '1d' }, + { + label: $localize`Today`, + value: '1d' + }, { label: $localize`Week to date` + ' (' + $localize`WTD` + ')', value: 'wtd' @@ -345,13 +349,19 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { { label: $localize`Year to date` + ' (' + $localize`YTD` + ')', value: 'ytd' - }, - { - label: '1 ' + $localize`year` + ' (' + $localize`1Y` + ')', - value: '1y' } ]; + if ( + this.user?.dateOfFirstActivity && + differenceInYears(new Date(), this.user.dateOfFirstActivity) >= 1 + ) { + this.dateRangeOptions.push({ + label: '1 ' + $localize`year` + ' (' + $localize`1Y` + ')', + value: '1y' + }); + } + // TODO // if (this.user?.settings?.isExperimentalFeatures) { // this.dateRangeOptions = this.dateRangeOptions.concat( @@ -367,13 +377,20 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { // ); // } - this.dateRangeOptions = this.dateRangeOptions.concat([ - { + if ( + this.user?.dateOfFirstActivity && + differenceInYears(new Date(), this.user.dateOfFirstActivity) >= 5 + ) { + this.dateRangeOptions.push({ label: '5 ' + $localize`years` + ' (' + $localize`5Y` + ')', value: '5y' - }, - { label: $localize`Max`, value: 'max' } - ]); + }); + } + + this.dateRangeOptions.push({ + label: $localize`Max`, + value: 'max' + }); this.dateRangeFormControl.disable({ emitEvent: false });