Browse Source

resolve comments

pull/4308/head
KenTandrian 6 months ago
parent
commit
e75ae03863
  1. 39
      apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts
  2. 2
      apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html
  3. 2
      libs/ui/src/lib/tags-selector/tags-selector.component.html
  4. 2
      libs/ui/src/lib/tags-selector/tags-selector.component.stories.ts
  5. 4
      libs/ui/src/lib/tags-selector/tags-selector.component.ts

39
apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts

@ -50,8 +50,8 @@ import { Router } from '@angular/router';
import { Account, MarketData, Tag } from '@prisma/client'; import { Account, MarketData, Tag } from '@prisma/client';
import { format, isSameMonth, isToday, parseISO } from 'date-fns'; import { format, isSameMonth, isToday, parseISO } from 'date-fns';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { forkJoin, Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { map, switchMap, takeUntil } from 'rxjs/operators'; import { switchMap, takeUntil } from 'rxjs/operators';
import { HoldingDetailDialogParams } from './interfaces/interfaces'; import { HoldingDetailDialogParams } from './interfaces/interfaces';
@ -99,7 +99,7 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
public dividendYieldPercentWithCurrencyEffect: number; public dividendYieldPercentWithCurrencyEffect: number;
public feeInBaseCurrency: number; public feeInBaseCurrency: number;
public firstBuyDate: string; public firstBuyDate: string;
public hasPermissionToCreateTags: boolean; public hasPermissionToCreateTag: boolean;
public hasPermissionToReadMarketDataOfOwnAssetProfile: boolean; public hasPermissionToReadMarketDataOfOwnAssetProfile: boolean;
public historicalDataItems: LineChartItem[]; public historicalDataItems: LineChartItem[];
public investment: number; public investment: number;
@ -157,29 +157,24 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
.get('tags') .get('tags')
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) .valueChanges.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((tags: Tag[]) => { .subscribe((tags: Tag[]) => {
const newTags = tags.filter((tag) => { const newTag = tags.find(({ id }) => {
return tag.id === undefined; return id === undefined;
}); });
if (this.hasPermissionToCreateTags && newTags.length > 0) { if (newTag && this.hasPermissionToCreateTag) {
const createTagObservables = newTags.map((newTag) => { this.adminService
return this.adminService.postTag({ name: newTag.name }).pipe(); .postTag(newTag)
});
forkJoin(createTagObservables)
.pipe( .pipe(
map((createdTags) => [ switchMap((createdTag) => {
...tags.filter((tag) => tag.id !== undefined),
...createdTags
]),
switchMap((updatedTags) => {
this.activityForm
.get('tags')
.setValue(updatedTags, { emitEvent: false });
return this.dataService.putHoldingTags({ return this.dataService.putHoldingTags({
tags: updatedTags,
dataSource: this.data.dataSource, dataSource: this.data.dataSource,
symbol: this.data.symbol symbol: this.data.symbol,
tags: [
...tags.filter(({ id }) => {
return id !== undefined;
}),
createdTag
]
}); });
}), }),
takeUntil(this.unsubscribeSubject) takeUntil(this.unsubscribeSubject)
@ -453,7 +448,7 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
if (state?.user) { if (state?.user) {
this.user = state.user; this.user = state.user;
this.hasPermissionToCreateTags = hasPermission( this.hasPermissionToCreateTag = hasPermission(
this.user.permissions, this.user.permissions,
permissions.createTag permissions.createTag
); );

2
apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html

@ -388,7 +388,7 @@
</mat-tab-group> </mat-tab-group>
<gf-tags-selector <gf-tags-selector
[hasPermissionToCreateTags]="hasPermissionToCreateTags" [hasPermissionToCreateTag]="hasPermissionToCreateTag"
[readonly]="!data.hasPermissionToUpdateOrder" [readonly]="!data.hasPermissionToUpdateOrder"
[tags]="activityForm.get('tags')?.value" [tags]="activityForm.get('tags')?.value"
[tagsAvailable]="tagsAvailable" [tagsAvailable]="tagsAvailable"

2
libs/ui/src/lib/tags-selector/tags-selector.component.html

@ -43,7 +43,7 @@
</mat-option> </mat-option>
} }
@if (hasPermissionToCreateTags && tagInputControl.value) { @if (hasPermissionToCreateTag && tagInputControl.value) {
<mat-option [value]="tagInputControl.value.trim()"> <mat-option [value]="tagInputControl.value.trim()">
<span class="align-items-center d-flex"> <span class="align-items-center d-flex">
<ion-icon class="mr-2" name="add-circle-outline" /> <ion-icon class="mr-2" name="add-circle-outline" />

2
libs/ui/src/lib/tags-selector/tags-selector.component.stories.ts

@ -50,7 +50,7 @@ export const Default: Story = {
export const CreateCustomTags: Story = { export const CreateCustomTags: Story = {
args: { args: {
hasPermissionToCreateTags: true, hasPermissionToCreateTag: true,
tags: [ tags: [
{ {
id: 'EMERGENCY_FUND', id: 'EMERGENCY_FUND',

4
libs/ui/src/lib/tags-selector/tags-selector.component.ts

@ -42,7 +42,7 @@ import { BehaviorSubject, Subject, takeUntil } from 'rxjs';
templateUrl: 'tags-selector.component.html' templateUrl: 'tags-selector.component.html'
}) })
export class GfTagsSelectorComponent implements OnInit, OnChanges, OnDestroy { export class GfTagsSelectorComponent implements OnInit, OnChanges, OnDestroy {
@Input() hasPermissionToCreateTags = false; @Input() hasPermissionToCreateTag = false;
@Input() readonly = false; @Input() readonly = false;
@Input() tags: Tag[]; @Input() tags: Tag[];
@Input() tagsAvailable: Tag[]; @Input() tagsAvailable: Tag[];
@ -81,7 +81,7 @@ export class GfTagsSelectorComponent implements OnInit, OnChanges, OnDestroy {
return id === event.option.value; return id === event.option.value;
}); });
if (!tag && this.hasPermissionToCreateTags) { if (!tag && this.hasPermissionToCreateTag) {
tag = { tag = {
id: undefined, id: undefined,
name: event.option.value as string, name: event.option.value as string,

Loading…
Cancel
Save