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

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

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

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

@ -43,7 +43,7 @@
</mat-option>
}
@if (hasPermissionToCreateTags && tagInputControl.value) {
@if (hasPermissionToCreateTag && tagInputControl.value) {
<mat-option [value]="tagInputControl.value.trim()">
<span class="align-items-center d-flex">
<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 = {
args: {
hasPermissionToCreateTags: true,
hasPermissionToCreateTag: true,
tags: [
{
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'
})
export class GfTagsSelectorComponent implements OnInit, OnChanges, OnDestroy {
@Input() hasPermissionToCreateTags = false;
@Input() hasPermissionToCreateTag = false;
@Input() readonly = false;
@Input() tags: Tag[];
@Input() tagsAvailable: Tag[];
@ -81,7 +81,7 @@ export class GfTagsSelectorComponent implements OnInit, OnChanges, OnDestroy {
return id === event.option.value;
});
if (!tag && this.hasPermissionToCreateTags) {
if (!tag && this.hasPermissionToCreateTag) {
tag = {
id: undefined,
name: event.option.value as string,

Loading…
Cancel
Save