From d4942f65eabd1a29354cedd19c747b6454c5df22 Mon Sep 17 00:00:00 2001 From: Tahbit Fehran Date: Sun, 15 Jun 2025 12:00:31 +0600 Subject: [PATCH] Conditionally display date range options based on user activity --- .../src/lib/assistant/assistant.component.ts | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/libs/ui/src/lib/assistant/assistant.component.ts b/libs/ui/src/lib/assistant/assistant.component.ts index a74ef310a..63aefa8a8 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 { @@ -332,6 +333,7 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { public ngOnChanges() { this.accounts = this.user?.accounts ?? []; + // Start with basic date range options that don't depend on user activity this.dateRangeOptions = [ { label: $localize`Today`, value: '1d' }, { @@ -345,13 +347,21 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { { label: $localize`Year to date` + ' (' + $localize`YTD` + ')', value: 'ytd' - }, - { - label: '1 ' + $localize`year` + ' (' + $localize`1Y` + ')', - value: '1y' } ]; + const currentDate = new Date(); + + if ( + this.user?.dateOfFirstActivity && + differenceInYears(currentDate, 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,19 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { // ); // } - this.dateRangeOptions = this.dateRangeOptions.concat([ - { + // Only add the 5Y option if the user has activity data from at least 5 years ago + if ( + this.user?.dateOfFirstActivity && + differenceInYears(currentDate, this.user.dateOfFirstActivity) >= 5 + ) { + this.dateRangeOptions.push({ label: '5 ' + $localize`years` + ' (' + $localize`5Y` + ')', value: '5y' - }, - { label: $localize`Max`, value: 'max' } - ]); + }); + } + + // Always add the Max option + this.dateRangeOptions.push({ label: $localize`Max`, value: 'max' }); this.dateRangeFormControl.disable({ emitEvent: false });