From f11527abf3c7f64ea0b04573ba14f51075c363b4 Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Fri, 24 May 2024 15:05:24 +0200 Subject: [PATCH 1/3] feat: use activeUser to define who can comment --- .../record-user-feedbacks.component.html | 1 - .../record-user-feedbacks.component.ts | 10 ---------- .../user-feedback-item.component.html | 2 +- .../user-feedback-item/user-feedback-item.component.ts | 1 - 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.html b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.html index 29a7f9c157..658bc1ed3c 100644 --- a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.html +++ b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.html @@ -91,7 +91,6 @@ [userFeedBacksAnswers]=" userFeedBacksAnswers.get(userFeedbackParent.uuid) " - [isActiveUserEditor]="isActiveUserMetadaEditor" [activeUser]="activeUser" [isAddUserFeedbackLoading]="isAddUserFeedbackLoading" (newUserFeedbackAnswer)="onNewUserFeedbackAnswer($event)" diff --git a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts index 7561f56215..b6c563fae2 100644 --- a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts +++ b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts @@ -94,16 +94,6 @@ export class RecordUserFeedbacksComponent implements OnInit, OnDestroy { this.metadataViewFacade.loadUserFeedbacks(this.metadataUuid) - this.activeUser$.pipe(takeUntil(this.destroy$)).subscribe((user) => { - this.activeUser = user - this.isActiveUserMetadaEditor = [ - 'Administrator', - 'UserAdmin', - 'Reviewer', - 'Editor', - ].includes(user?.profile) - }) - combineLatest([ this.metadataViewFacade.userFeedbacks$, this.selectedSortingStrategy$, diff --git a/libs/ui/elements/src/lib/user-feedback-item/user-feedback-item.component.html b/libs/ui/elements/src/lib/user-feedback-item/user-feedback-item.component.html index f91bd17d7e..628fc30d93 100644 --- a/libs/ui/elements/src/lib/user-feedback-item/user-feedback-item.component.html +++ b/libs/ui/elements/src/lib/user-feedback-item/user-feedback-item.component.html @@ -30,7 +30,7 @@ > -
+

Date: Fri, 24 May 2024 15:36:32 +0200 Subject: [PATCH 2/3] feat: add user feedback error handling --- .../record-user-feedbacks.component.ts | 108 +++++++++++------- .../lib/gn4/platform/gn4-platform.service.ts | 26 +++-- 2 files changed, 84 insertions(+), 50 deletions(-) diff --git a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts index b6c563fae2..9e7d92356f 100644 --- a/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts +++ b/apps/datahub/src/app/record/record-user-feedbacks/record-user-feedbacks.component.ts @@ -6,8 +6,8 @@ import { OnDestroy, OnInit, } from '@angular/core' -import { filter, switchMap, takeUntil } from 'rxjs/operators' -import { BehaviorSubject, combineLatest, Observable, Subject } from 'rxjs' +import { catchError, filter, switchMap, takeUntil } from 'rxjs/operators' +import { BehaviorSubject, combineLatest, Observable, of, Subject } from 'rxjs' import { UserFeedback, UserFeedbackViewModel, @@ -85,14 +85,30 @@ export class RecordUserFeedbacksComponent implements OnInit, OnDestroy { ngOnInit(): void { this.metadataViewFacade.isAllUserFeedbackLoading$ - .pipe(takeUntil(this.destroy$)) + .pipe( + takeUntil(this.destroy$), + catchError((error) => { + console.error('Error while loading all the user feedbacks:', error) + return of(false) + }) + ) .subscribe((isLoading) => (this.isAllUserFeedbackLoading = isLoading)) this.metadataViewFacade.isAddUserFeedbackLoading$ - .pipe(takeUntil(this.destroy$)) + .pipe( + takeUntil(this.destroy$), + catchError((error) => { + console.error('Error while adding the user feedback:', error) + return of(false) + }) + ) .subscribe((isLoading) => (this.isAddUserFeedbackLoading = isLoading)) - this.metadataViewFacade.loadUserFeedbacks(this.metadataUuid) + try { + this.metadataViewFacade.loadUserFeedbacks(this.metadataUuid) + } catch (error) { + console.error('Error while loading the user feedbacks:', error) + } combineLatest([ this.metadataViewFacade.userFeedbacks$, @@ -104,50 +120,59 @@ export class RecordUserFeedbacksComponent implements OnInit, OnDestroy { takeUntil(this.destroy$), switchMap( async ([userFeedbacks, selectedSortingStrategy, activeUser]) => { - this.activeUser = activeUser + try { + this.activeUser = activeUser - const userFeedbacksParents = userFeedbacks - .filter((feedback) => !feedback.parentUuid) - .sort(selectedSortingStrategy) + const userFeedbacksParents = userFeedbacks + .filter((feedback) => !feedback.parentUuid) + .sort(selectedSortingStrategy) - const userFeedbacksAnswers = userFeedbacks - .filter((feedback) => feedback.parentUuid) - .sort(this.sortByDateFromOldestToNewest) + const userFeedbacksAnswers = userFeedbacks + .filter((feedback) => feedback.parentUuid) + .sort(this.sortByDateFromOldestToNewest) - const userFeedbacksParentsViewModels = await Promise.all( - userFeedbacksParents.map((feedback) => - this.mapper.createUserFeedbackViewModel(feedback) + const userFeedbacksParentsViewModels = await Promise.all( + userFeedbacksParents.map((feedback) => + this.mapper.createUserFeedbackViewModel(feedback) + ) ) - ) - const userFeedbacksAnswersViewModels = await Promise.all( - userFeedbacksAnswers.map((feedback) => - this.mapper.createUserFeedbackViewModel(feedback) + const userFeedbacksAnswersViewModels = await Promise.all( + userFeedbacksAnswers.map((feedback) => + this.mapper.createUserFeedbackViewModel(feedback) + ) ) - ) - - const userFeedBacksAnswersMap = new Map() - userFeedbacksAnswersViewModels.forEach( - (userFeedbackAnswerViewModel) => { - const parentUuid = userFeedbackAnswerViewModel.parentUuid - if (userFeedBacksAnswersMap.has(parentUuid)) { - userFeedBacksAnswersMap - .get(parentUuid) - .push(userFeedbackAnswerViewModel) - } else { - userFeedBacksAnswersMap.set(parentUuid, [ - userFeedbackAnswerViewModel, - ]) + + const userFeedBacksAnswersMap = new Map() + userFeedbacksAnswersViewModels.forEach( + (userFeedbackAnswerViewModel) => { + const parentUuid = userFeedbackAnswerViewModel.parentUuid + if (userFeedBacksAnswersMap.has(parentUuid)) { + userFeedBacksAnswersMap + .get(parentUuid) + .push(userFeedbackAnswerViewModel) + } else { + userFeedBacksAnswersMap.set(parentUuid, [ + userFeedbackAnswerViewModel, + ]) + } } - } - ) + ) - return { - parentsViewModels: userFeedbacksParentsViewModels, - answersMap: userFeedBacksAnswersMap, + return { + parentsViewModels: userFeedbacksParentsViewModels, + answersMap: userFeedBacksAnswersMap, + } + } catch (error) { + console.error('Error processing user feedbacks:', error) + throw error } } - ) + ), + catchError((error) => { + console.error('Error combining feedbacks and answers:', error) + return of({ parentsViewModels: [], answersMap: new Map() }) + }) ) .subscribe({ next: ({ parentsViewModels, answersMap }) => { @@ -156,7 +181,10 @@ export class RecordUserFeedbacksComponent implements OnInit, OnDestroy { this.cdr.markForCheck() }, error: (err) => { - console.error('Error processing feedback', err) + console.error( + 'Error during the subscription to user feedback data:', + err + ) }, }) } diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts index 4c71fb3691..f89f322afe 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts @@ -162,19 +162,25 @@ export class Gn4PlatformService implements PlatformServiceInterface { } getUserFeedbacks(uuid: string): Observable { - return this.userfeedbackApiService - .getUserComments(uuid) - .pipe( - map((userFeedbacks) => - userFeedbacks.map(this.mapper.userFeedbacksFromApi) - ) - ) + return this.userfeedbackApiService.getUserComments(uuid).pipe( + map((userFeedbacks) => + userFeedbacks.map(this.mapper.userFeedbacksFromApi) + ), + catchError((error) => { + console.error('Error fetching user feedbacks:', error) + return of([]) // return an empty array as fallback + }) + ) } postUserFeedbacks(userFeedback: UserFeedback): Observable { const mappedUserFeedBack = this.mapper.userFeedbacksToApi(userFeedback) - return this.userfeedbackApiService - .newUserFeedback(mappedUserFeedBack) - .pipe(map(() => undefined)) + return this.userfeedbackApiService.newUserFeedback(mappedUserFeedBack).pipe( + map(() => undefined), + catchError((error) => { + console.error('Error posting user feedback:', error) + return of(undefined) // return undefined as fallback + }) + ) } } From 9a5b125fcd85a308b39aa295944a066b10fdac7e Mon Sep 17 00:00:00 2001 From: Camille Moinier Date: Fri, 24 May 2024 16:07:10 +0200 Subject: [PATCH 3/3] fix: change unit test --- .../src/lib/gn4/platform/gn4-platform.service.spec.ts | 10 +++++----- .../src/lib/gn4/platform/gn4-platform.service.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts index e062a7202a..8e7e77cfcc 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts @@ -397,13 +397,13 @@ describe('Gn4PlatformService', () => { ) service.getUserFeedbacks(mockUuid).subscribe({ - next: () => { - done('Expected error, but got success') - }, - error: (error) => { - expect(error).toBe(errorResponse) + next: (result) => { + expect(result).toBeUndefined() done() }, + error: () => { + done('Expected success, but got error') + }, }) }) }) diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts index f89f322afe..a4be2ba0e0 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts @@ -168,7 +168,7 @@ export class Gn4PlatformService implements PlatformServiceInterface { ), catchError((error) => { console.error('Error fetching user feedbacks:', error) - return of([]) // return an empty array as fallback + return of(undefined) }) ) } @@ -179,7 +179,7 @@ export class Gn4PlatformService implements PlatformServiceInterface { map(() => undefined), catchError((error) => { console.error('Error posting user feedback:', error) - return of(undefined) // return undefined as fallback + return of(undefined) }) ) }