diff --git a/apps/api/src/services/tag/tag.service.ts b/apps/api/src/services/tag/tag.service.ts index 2d5e8aa0b..b16f22fbb 100644 --- a/apps/api/src/services/tag/tag.service.ts +++ b/apps/api/src/services/tag/tag.service.ts @@ -6,22 +6,8 @@ import { Injectable } from '@nestjs/common'; export class TagService { public constructor(private readonly prismaService: PrismaService) {} - public async getPublic() { - return this.prismaService.tag.findMany({ - orderBy: { - name: 'asc' - }, - where: { - userId: null - } - }); - } - public async getTagsForUser(userId: string) { const tags = await this.prismaService.tag.findMany({ - orderBy: { - name: 'asc' - }, include: { _count: { select: { @@ -33,6 +19,9 @@ export class TagService { } } }, + orderBy: { + name: 'asc' + }, where: { OR: [ { diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts index ca367afba..792ec6f9c 100644 --- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts +++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts @@ -147,16 +147,6 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { ) {} public ngOnInit() { - this.userService.stateChanged - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe((state) => { - if (state?.user) { - this.user = state.user; - - this.changeDetectorRef.markForCheck(); - } - }); - this.activityForm = this.formBuilder.group({ tags: [] }); @@ -166,14 +156,6 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { { id: this.data.symbol, type: 'SYMBOL' } ]; - const { tags } = this.user; - this.tagsAvailable = tags.map((tag) => { - return { - ...tag, - name: translate(tag.name) - }; - }); - this.activityForm .get('tags') .valueChanges.pipe(takeUntil(this.unsubscribeSubject)) @@ -436,6 +418,24 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { this.changeDetectorRef.markForCheck(); } ); + + this.userService.stateChanged + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe((state) => { + if (state?.user) { + this.user = state.user; + + this.tagsAvailable = + this.user?.tags?.map((tag) => { + return { + ...tag, + name: translate(tag.name) + }; + }) ?? []; + + this.changeDetectorRef.markForCheck(); + } + }); } public onAddTag(event: MatAutocompleteSelectedEvent) { diff --git a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts index b7c8584f6..cb21c255d 100644 --- a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts +++ b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts @@ -82,13 +82,13 @@ export class CreateOrUpdateActivityDialog implements OnDestroy { this.defaultDateFormat = getDateFormatString(this.locale); this.platforms = platforms; - const tags = this.data.user?.tags; - this.tagsAvailable = tags.map((tag) => { - return { - ...tag, - name: translate(tag.name) - }; - }); + this.tagsAvailable = + this.data.user?.tags?.map((tag) => { + return { + ...tag, + name: translate(tag.name) + }; + }) ?? []; Object.keys(Type).forEach((type) => { this.typesTranslationMap[Type[type]] = translate(Type[type]); diff --git a/libs/ui/src/lib/assistant/assistant.component.ts b/libs/ui/src/lib/assistant/assistant.component.ts index aebd9f2ea..c93d04303 100644 --- a/libs/ui/src/lib/assistant/assistant.component.ts +++ b/libs/ui/src/lib/assistant/assistant.component.ts @@ -156,7 +156,6 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { ) {} public ngOnInit() { - this.accounts = this.user?.accounts; this.assetClasses = Object.keys(AssetClass).map((assetClass) => { return { id: assetClass, @@ -164,13 +163,6 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { type: 'ASSET_CLASS' }; }); - this.tags = this.user?.tags - .filter(({ isUsed }) => isUsed) - .map(({ id, name }) => ({ - id, - label: translate(name), - type: 'TAG' - })); this.searchFormControl.valueChanges .pipe( @@ -212,6 +204,8 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { } public ngOnChanges() { + this.accounts = this.user?.accounts ?? []; + this.dateRangeOptions = [ { label: $localize`Today`, value: '1d' }, { @@ -269,16 +263,6 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { this.filterForm.enable({ emitEvent: false }); } - this.tags = this.user?.tags - .filter(({ isUsed }) => isUsed) - .map(({ id, name }) => { - return { - id, - label: translate(name), - type: 'TAG' - }; - }); - this.filterForm.setValue( { account: this.user?.settings?.['filters.accounts']?.[0] ?? null, @@ -289,6 +273,23 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit { emitEvent: false } ); + + this.tags = + this.user?.tags + ?.filter(({ isUsed }) => { + return isUsed; + }) + .map(({ id, name }) => { + return { + id, + label: translate(name), + type: 'TAG' + }; + }) ?? []; + + if (this.tags.length === 0) { + this.filterForm.get('tag').disable({ emitEvent: false }); + } } public hasFilter(aFormValue: { [key: string]: string }) {