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..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,24 +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) - - this.activeUser$.pipe(takeUntil(this.destroy$)).subscribe((user) => { - this.activeUser = user - this.isActiveUserMetadaEditor = [ - 'Administrator', - 'UserAdmin', - 'Reviewer', - 'Editor', - ].includes(user?.profile) - }) + try { + this.metadataViewFacade.loadUserFeedbacks(this.metadataUuid) + } catch (error) { + console.error('Error while loading the user feedbacks:', error) + } combineLatest([ this.metadataViewFacade.userFeedbacks$, @@ -114,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 }) => { @@ -166,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.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 4c71fb3691..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 @@ -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(undefined) + }) + ) } 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) + }) + ) } } 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 @@ > -
+