From 4bd80c9951f2b831cf705e83558b3f84d9815614 Mon Sep 17 00:00:00 2001 From: Alisa Ismailati Date: Tue, 7 Nov 2023 15:28:04 +0100 Subject: [PATCH 1/2] [CST-12535] GET quality assurance topics by source/target --- .../admin-notifications-routing.module.ts | 2 +- ...ality-assurance-topic-data.service.spec.ts | 51 +++++++++++------- .../quality-assurance-topic-data.service.ts | 52 +++++-------------- .../qa-event-notification.component.html | 2 +- src/app/shared/mocks/notifications.mock.ts | 4 +- .../quality-assurance-events.component.ts | 2 - .../quality-assurance-topics.actions.ts | 8 ++- .../quality-assurance-topics.component.html | 4 +- ...quality-assurance-topics.component.spec.ts | 12 ++--- .../quality-assurance-topics.component.ts | 18 +++---- .../quality-assurance-topics.effects.ts | 4 +- .../quality-assurance-topics.reducer.spec.ts | 2 +- .../quality-assurance-topics.service.spec.ts | 33 ++++++++---- .../quality-assurance-topics.service.ts | 41 ++++----------- ...estion-notifications-state.service.spec.ts | 4 +- .../suggestion-notifications-state.service.ts | 4 +- 16 files changed, 110 insertions(+), 133 deletions(-) diff --git a/src/app/admin/admin-notifications/admin-notifications-routing.module.ts b/src/app/admin/admin-notifications/admin-notifications-routing.module.ts index 6d02ac8292..b943369928 100644 --- a/src/app/admin/admin-notifications/admin-notifications-routing.module.ts +++ b/src/app/admin/admin-notifications/admin-notifications-routing.module.ts @@ -51,7 +51,7 @@ import { SourceDataResolver } from './admin-quality-assurance-source-page-compon }, { canActivate: [ AuthenticatedGuard ], - path: `${QUALITY_ASSURANCE_EDIT_PATH}/:sourceId/:targetId`, + path: `${QUALITY_ASSURANCE_EDIT_PATH}/:sourceId/target/:targetId`, component: AdminQualityAssuranceTopicsPageComponent, pathMatch: 'full', resolve: { diff --git a/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.spec.ts b/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.spec.ts index 638ee3fa62..c9b1407a53 100644 --- a/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.spec.ts +++ b/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.spec.ts @@ -80,22 +80,27 @@ describe('QualityAssuranceTopicDataService', () => { notificationsService ); - spyOn((service as any).findAllData, 'findAll').and.callThrough(); - spyOn((service as any), 'findById').and.callThrough(); + spyOn((service as any).searchData, 'searchBy').and.callThrough(); }); - describe('getTopics', () => { - it('should call findListByHref', (done) => { - service.getTopics().subscribe( - (res) => { - expect((service as any).findAllData.findAll).toHaveBeenCalledWith({}, true, true); - } + describe('searchTopicsByTarget', () => { + it('should call searchData.searchBy with the correct parameters', () => { + const options = { elementsPerPage: 10 }; + const useCachedVersionIfAvailable = true; + const reRequestOnStale = true; + + service.searchTopicsByTarget(options, useCachedVersionIfAvailable, reRequestOnStale); + + expect((service as any).searchData.searchBy).toHaveBeenCalledWith( + 'byTarget', + options, + useCachedVersionIfAvailable, + reRequestOnStale ); - done(); }); it('should return a RemoteData> for the object with the given URL', () => { - const result = service.getTopics(); + const result = service.searchTopicsByTarget(); const expected = cold('(a)', { a: paginatedListRD }); @@ -103,20 +108,26 @@ describe('QualityAssuranceTopicDataService', () => { }); }); - describe('getTopic', () => { - it('should call findByHref', (done) => { - service.getTopic(qualityAssuranceTopicObjectMorePid.id).subscribe( - (res) => { - expect((service as any).findById).toHaveBeenCalledWith(qualityAssuranceTopicObjectMorePid.id, true, true); - } + describe('searchTopicsBySource', () => { + it('should call searchData.searchBy with the correct parameters', () => { + const options = { elementsPerPage: 10 }; + const useCachedVersionIfAvailable = true; + const reRequestOnStale = true; + + service.searchTopicsBySource(options, useCachedVersionIfAvailable, reRequestOnStale); + + expect((service as any).searchData.searchBy).toHaveBeenCalledWith( + 'bySource', + options, + useCachedVersionIfAvailable, + reRequestOnStale, ); - done(); }); - it('should return a RemoteData for the object with the given URL', () => { - const result = service.getTopic(qualityAssuranceTopicObjectMorePid.id); + it('should return a RemoteData> for the object with the given URL', () => { + const result = service.searchTopicsBySource(); const expected = cold('(a)', { - a: qaTopicObjectRD + a: paginatedListRD }); expect(result).toBeObservable(expected); }); diff --git a/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.ts b/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.ts index bb98e6fabf..6944e43a56 100644 --- a/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.ts +++ b/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.ts @@ -15,7 +15,6 @@ import { FindListOptions } from '../../../data/find-list-options.model'; import { IdentifiableDataService } from '../../../data/base/identifiable-data.service'; import { dataService } from '../../../data/base/data-service.decorator'; import { QUALITY_ASSURANCE_TOPIC_OBJECT } from '../models/quality-assurance-topic-object.resource-type'; -import { FindAllData, FindAllDataImpl } from '../../../data/base/find-all-data'; import { SearchData, SearchDataImpl } from '../../../../core/data/base/search-data'; /** @@ -25,10 +24,10 @@ import { SearchData, SearchDataImpl } from '../../../../core/data/base/search-da @dataService(QUALITY_ASSURANCE_TOPIC_OBJECT) export class QualityAssuranceTopicDataService extends IdentifiableDataService { - private findAllData: FindAllData; private searchData: SearchData; private searchByTargetMethod = 'byTarget'; + private searchBySourceMethod = 'bySource'; /** * Initialize service variables @@ -46,27 +45,9 @@ export class QualityAssuranceTopicDataService extends IdentifiableDataService>> - * The list of Quality Assurance topics. - */ - public getTopics(options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable>> { - return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); - } - /** * Search for Quality Assurance topics. * @param options The search options. @@ -75,31 +56,26 @@ export class QualityAssuranceTopicDataService extends IdentifiableDataService[]): Observable>> { + public searchTopicsByTarget(options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable>> { return this.searchData.searchBy(this.searchByTargetMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); } + /** + * Searches for quality assurance topics by source. + * @param options The search options. + * @param useCachedVersionIfAvailable Whether to use a cached version if available. + * @param reRequestOnStale Whether to re-request the data if it's stale. + * @param linksToFollow The links to follow. + * @returns An observable of the remote data containing the paginated list of quality assurance topics. + */ + public searchTopicsBySource(options: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable>> { + return this.searchData.searchBy(this.searchBySourceMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); + } + /** * Clear FindAll topics requests from cache */ public clearFindAllTopicsRequests() { this.requestService.setStaleByHrefSubstring('qualityassurancetopics'); } - - /** - * Return a single Quality Assurance topic. - * - * @param id The Quality Assurance topic id - * @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's - * no valid cached version. Defaults to true - * @param reRequestOnStale Whether or not the request should automatically be re- - * requested after the response becomes stale - * @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved. - * - * @return Observable> - * The Quality Assurance topic. - */ - public getTopic(id: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable> { - return this.findById(id, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); - } } diff --git a/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.html b/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.html index 2e47916fd7..7f9e7fbd4e 100644 --- a/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.html +++ b/src/app/item-page/simple/qa-event-notification/qa-event-notification.component.html @@ -5,7 +5,7 @@
{{'item.qa-event-notification.check.notification-info' | translate : {num: source.totalEvents } }}
-
diff --git a/src/app/shared/mocks/notifications.mock.ts b/src/app/shared/mocks/notifications.mock.ts index dc1c98c7b9..82ba818b13 100644 --- a/src/app/shared/mocks/notifications.mock.ts +++ b/src/app/shared/mocks/notifications.mock.ts @@ -1838,8 +1838,8 @@ export function getMockNotificationsStateService(): any { */ export function getMockQualityAssuranceTopicRestService(): QualityAssuranceTopicDataService { return jasmine.createSpyObj('QualityAssuranceTopicDataService', { - getTopics: jasmine.createSpy('getTopics'), - getTopic: jasmine.createSpy('getTopic'), + searchTopicsBySource: jasmine.createSpy('searchTopicsBySource'), + searchTopicsByTarget: jasmine.createSpy('searchTopicsByTarget'), }); } diff --git a/src/app/suggestion-notifications/qa/events/quality-assurance-events.component.ts b/src/app/suggestion-notifications/qa/events/quality-assurance-events.component.ts index e34c121f35..742047e76f 100644 --- a/src/app/suggestion-notifications/qa/events/quality-assurance-events.component.ts +++ b/src/app/suggestion-notifications/qa/events/quality-assurance-events.component.ts @@ -140,7 +140,6 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy { return this.getQualityAssuranceEvents(); }) ).subscribe((events: QualityAssuranceEventData[]) => { - console.log(events); this.eventsUpdated$.next(events); this.isEventPageLoading.next(false); }); @@ -356,7 +355,6 @@ export class QualityAssuranceEventsComponent implements OnInit, OnDestroy { if (rd.hasSucceeded) { this.totalElements$.next(rd.payload.totalElements); if (rd.payload.totalElements > 0) { - console.log(rd.payload.page); return this.fetchEvents(rd.payload.page); } else { return of([]); diff --git a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.actions.ts b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.actions.ts index 2459d4352a..482a85a988 100644 --- a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.actions.ts +++ b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.actions.ts @@ -25,6 +25,8 @@ export class RetrieveAllTopicsAction implements Action { payload: { elementsPerPage: number; currentPage: number; + source: string; + target?: string; }; /** @@ -35,10 +37,12 @@ export class RetrieveAllTopicsAction implements Action { * @param currentPage * The page number to retrieve */ - constructor(elementsPerPage: number, currentPage: number) { + constructor(elementsPerPage: number, currentPage: number, source: string, target?: string) { this.payload = { elementsPerPage, - currentPage + currentPage, + source, + target }; } } diff --git a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.html b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.html index db8586f264..c13929bf8a 100644 --- a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.html +++ b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.html @@ -15,7 +15,7 @@ [collectionSize]="(totalElements$ | async)" [hideGear]="false" [hideSortOptions]="true" - (paginationChange)="getQualityAssuranceTopics()"> + (paginationChange)="getQualityAssuranceTopics(sourceId, targetId)"> @@ -40,7 +40,7 @@ diff --git a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.spec.ts b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.spec.ts index 39d7335f2d..52700d778b 100644 --- a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.spec.ts +++ b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.spec.ts @@ -16,7 +16,6 @@ import { SuggestionNotificationsStateService } from '../../suggestion-notificati import { cold } from 'jasmine-marbles'; import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub'; import { PaginationService } from '../../../core/pagination/pagination.service'; -import { QualityAssuranceTopicsService } from './quality-assurance-topics.service'; describe('QualityAssuranceTopicsComponent test suite', () => { let fixture: ComponentFixture; @@ -44,18 +43,13 @@ describe('QualityAssuranceTopicsComponent test suite', () => { providers: [ { provide: SuggestionNotificationsStateService, useValue: mockNotificationsStateService }, { provide: ActivatedRoute, useValue: { data: observableOf(activatedRouteParams), snapshot: { - paramMap: { - get: () => 'openaire', + params: { + sourceId: 'openaire', + targetId: null }, }}}, { provide: PaginationService, useValue: paginationService }, QualityAssuranceTopicsComponent, - // tslint:disable-next-line: no-empty - { provide: QualityAssuranceTopicsService, useValue: { - setSourceId: (sourceId: string) => { } , - setTargetId: (targetId: string) => { } - } - } ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents().then(() => { diff --git a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.ts b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.ts index 6d96795ea3..b04bb4fbf2 100644 --- a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.ts +++ b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.ts @@ -15,7 +15,6 @@ import { } from '../../../admin/admin-notifications/admin-quality-assurance-topics-page/admin-quality-assurance-topics-page-resolver.service'; import { PaginationService } from '../../../core/pagination/pagination.service'; import { ActivatedRoute } from '@angular/router'; -import { QualityAssuranceTopicsService } from './quality-assurance-topics.service'; /** * Component to display the Quality Assurance topic list. @@ -76,19 +75,16 @@ export class QualityAssuranceTopicsComponent implements OnInit { constructor( private paginationService: PaginationService, private activatedRoute: ActivatedRoute, - private notificationsStateService: SuggestionNotificationsStateService, - private qualityAssuranceTopicsService: QualityAssuranceTopicsService + private notificationsStateService: SuggestionNotificationsStateService ) { + this.sourceId = this.activatedRoute.snapshot.params.sourceId; + this.targetId = this.activatedRoute.snapshot.params.targetId; } /** * Component initialization. */ ngOnInit(): void { - this.sourceId = this.activatedRoute.snapshot.paramMap.get('sourceId'); - this.targetId = this.activatedRoute.snapshot.paramMap.get('targetId'); - this.qualityAssuranceTopicsService.setSourceId(this.sourceId); - this.qualityAssuranceTopicsService.setTargetId(this.targetId); this.topics$ = this.notificationsStateService.getQualityAssuranceTopics(); this.totalElements$ = this.notificationsStateService.getQualityAssuranceTopicsTotals(); } @@ -101,7 +97,7 @@ export class QualityAssuranceTopicsComponent implements OnInit { this.notificationsStateService.isQualityAssuranceTopicsLoaded().pipe( take(1) ).subscribe(() => { - this.getQualityAssuranceTopics(); + this.getQualityAssuranceTopics(this.sourceId, this.targetId); }) ); } @@ -129,13 +125,15 @@ export class QualityAssuranceTopicsComponent implements OnInit { /** * Dispatch the Quality Assurance topics retrival. */ - public getQualityAssuranceTopics(): void { + public getQualityAssuranceTopics(source: string, target?: string): void { this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig).pipe( distinctUntilChanged(), ).subscribe((options: PaginationComponentOptions) => { this.notificationsStateService.dispatchRetrieveQualityAssuranceTopics( options.pageSize, - options.currentPage + options.currentPage, + source, + target ); }); } diff --git a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.effects.ts b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.effects.ts index 13e3670000..92d7dc9e21 100644 --- a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.effects.ts +++ b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.effects.ts @@ -37,7 +37,9 @@ export class QualityAssuranceTopicsEffects { switchMap(([action, currentState]: [RetrieveAllTopicsAction, any]) => { return this.qualityAssuranceTopicService.getTopics( action.payload.elementsPerPage, - action.payload.currentPage + action.payload.currentPage, + action.payload.source, + action.payload.target ).pipe( map((topics: PaginatedList) => new AddTopicsAction(topics.page, topics.totalPages, topics.currentPage, topics.totalElements) diff --git a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.reducer.spec.ts b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.reducer.spec.ts index a1c002d3f2..2872e41f94 100644 --- a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.reducer.spec.ts +++ b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.reducer.spec.ts @@ -29,7 +29,7 @@ describe('qualityAssuranceTopicsReducer test suite', () => { const expectedState = qualityAssuranceTopicInitialState; expectedState.processing = true; - const action = new RetrieveAllTopicsAction(elementPerPage, currentPage); + const action = new RetrieveAllTopicsAction(elementPerPage, currentPage, 'source', 'target'); const newState = qualityAssuranceTopicsReducer(qualityAssuranceTopicInitialState, action); expect(newState).toEqual(expectedState); diff --git a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.service.spec.ts b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.service.spec.ts index 1e4e3fcffd..1faaa7f43d 100644 --- a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.service.spec.ts +++ b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.service.spec.ts @@ -42,31 +42,46 @@ describe('QualityAssuranceTopicsService', () => { beforeEach(() => { restService = TestBed.inject(QualityAssuranceTopicDataService); restServiceAsAny = restService; - restServiceAsAny.getTopics.and.returnValue(observableOf(paginatedListRD)); + restServiceAsAny.searchTopicsBySource.and.returnValue(observableOf(paginatedListRD)); + restServiceAsAny.searchTopicsByTarget.and.returnValue(observableOf(paginatedListRD)); service = new QualityAssuranceTopicsService(restService); serviceAsAny = service; }); - describe('getTopics', () => { - it('Should proxy the call to qualityAssuranceTopicRestService.getTopics', () => { + describe('getTopicsBySource', () => { + it('should proxy the call to qualityAssuranceTopicRestService.searchTopicsBySource', () => { const sortOptions = new SortOptions('name', SortDirection.ASC); const findListOptions: FindListOptions = { elementsPerPage: elementsPerPage, currentPage: currentPage, sort: sortOptions, - searchParams: [new RequestParam('source', 'ENRICH!MORE!ABSTRACT')] + searchParams: [new RequestParam('source', 'openaire')] }; - service.setSourceId('ENRICH!MORE!ABSTRACT'); - const result = service.getTopics(elementsPerPage, currentPage); - expect((service as any).qualityAssuranceTopicRestService.getTopics).toHaveBeenCalledWith(findListOptions); + const result = service.getTopics(elementsPerPage, currentPage, 'openaire'); + expect((service as any).qualityAssuranceTopicRestService.searchTopicsBySource).toHaveBeenCalledWith(findListOptions); }); - it('Should return a paginated list of Quality Assurance topics', () => { + it('should return a paginated list of Quality Assurance topics', () => { const expected = cold('(a|)', { a: paginatedList }); - const result = service.getTopics(elementsPerPage, currentPage); + const result = service.getTopics(elementsPerPage, currentPage, 'openaire'); expect(result).toBeObservable(expected); }); + + it('should include targetId in searchParams if set', () => { + const sortOptions = new SortOptions('name', SortDirection.ASC); + const findListOptions: FindListOptions = { + elementsPerPage: elementsPerPage, + currentPage: currentPage, + sort: sortOptions, + searchParams: [ + new RequestParam('source', 'openaire'), + new RequestParam('target', '0000-0000-0000-0000-0000') + ] + }; + const result = service.getTopics(elementsPerPage, currentPage,'openaire', '0000-0000-0000-0000-0000'); + expect((service as any).qualityAssuranceTopicRestService.searchTopicsByTarget).toHaveBeenCalledWith(findListOptions); + }); }); }); diff --git a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.service.ts b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.service.ts index c94ffe72d4..4144cd8875 100644 --- a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.service.ts +++ b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.service.ts @@ -29,15 +29,6 @@ export class QualityAssuranceTopicsService { private qualityAssuranceTopicRestService: QualityAssuranceTopicDataService ) { } - /** - * sourceId used to get topics - */ - sourceId: string; - - /** - * targetId used to get topics - */ - targetId: string; /** * Return the list of Quality Assurance topics managing pagination and errors. @@ -49,21 +40,25 @@ export class QualityAssuranceTopicsService { * @return Observable> * The list of Quality Assurance topics. */ - public getTopics(elementsPerPage, currentPage): Observable> { + public getTopics(elementsPerPage, currentPage, source: string, target?: string): Observable> { const sortOptions = new SortOptions('name', SortDirection.ASC); - const findListOptions: FindListOptions = { elementsPerPage: elementsPerPage, currentPage: currentPage, sort: sortOptions, - searchParams: [new RequestParam('source', this.sourceId)] + searchParams: [new RequestParam('source', source)] }; - if (hasValue(this.targetId)) { - findListOptions.searchParams.push(new RequestParam('target', this.targetId)); + let request$: Observable>>; + + if (hasValue(target)) { + findListOptions.searchParams.push(new RequestParam('target', target)); + request$ = this.qualityAssuranceTopicRestService.searchTopicsByTarget(findListOptions); + } else { + request$ = this.qualityAssuranceTopicRestService.searchTopicsBySource(findListOptions); } - return this.qualityAssuranceTopicRestService.getTopics(findListOptions).pipe( + return request$.pipe( getFirstCompletedRemoteData(), map((rd: RemoteData>) => { if (rd.hasSucceeded) { @@ -74,20 +69,4 @@ export class QualityAssuranceTopicsService { }) ); } - - /** - * set sourceId which is used to get topics - * @param sourceId string - */ - setSourceId(sourceId: string) { - this.sourceId = sourceId; - } - - /** - * set targetId which is used to get topics - * @param targetId string - */ - setTargetId(targetId: string) { - this.targetId = targetId; - } } diff --git a/src/app/suggestion-notifications/suggestion-notifications-state.service.spec.ts b/src/app/suggestion-notifications/suggestion-notifications-state.service.spec.ts index ac669ed954..16d0de974d 100644 --- a/src/app/suggestion-notifications/suggestion-notifications-state.service.spec.ts +++ b/src/app/suggestion-notifications/suggestion-notifications-state.service.spec.ts @@ -271,8 +271,8 @@ describe('NotificationsStateService', () => { it('Should call store.dispatch', () => { const elementsPerPage = 3; const currentPage = 1; - const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage); - service.dispatchRetrieveQualityAssuranceTopics(elementsPerPage, currentPage); + const action = new RetrieveAllTopicsAction(elementsPerPage, currentPage, 'source', 'target'); + service.dispatchRetrieveQualityAssuranceTopics(elementsPerPage, currentPage, 'source', 'target'); expect(serviceAsAny.store.dispatch).toHaveBeenCalledWith(action); }); }); diff --git a/src/app/suggestion-notifications/suggestion-notifications-state.service.ts b/src/app/suggestion-notifications/suggestion-notifications-state.service.ts index ec1ea2e039..1fc5422018 100644 --- a/src/app/suggestion-notifications/suggestion-notifications-state.service.ts +++ b/src/app/suggestion-notifications/suggestion-notifications-state.service.ts @@ -118,8 +118,8 @@ export class SuggestionNotificationsStateService { * @param currentPage * The number of the current page. */ - public dispatchRetrieveQualityAssuranceTopics(elementsPerPage: number, currentPage: number): void { - this.store.dispatch(new RetrieveAllTopicsAction(elementsPerPage, currentPage)); + public dispatchRetrieveQualityAssuranceTopics(elementsPerPage: number, currentPage: number, sourceId: string, targteId?: string): void { + this.store.dispatch(new RetrieveAllTopicsAction(elementsPerPage, currentPage, sourceId, targteId)); } // Quality Assurance source From 6675f9cd6aa455bdfb193e3c76ed87875d40c091 Mon Sep 17 00:00:00 2001 From: Alisa Ismailati Date: Fri, 10 Nov 2023 11:20:33 +0100 Subject: [PATCH 2/2] [CST-12535] improvements --- ...ality-assurance-topic-data.service.spec.ts | 19 +++++++++ .../quality-assurance-topic-data.service.ts | 20 ++++++++++ .../quality-assurance-topics.component.html | 6 ++- ...quality-assurance-topics.component.spec.ts | 2 + .../quality-assurance-topics.component.ts | 40 ++++++++++++++++++- src/assets/i18n/en.json5 | 2 + 6 files changed, 86 insertions(+), 3 deletions(-) diff --git a/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.spec.ts b/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.spec.ts index c9b1407a53..277da6e4ba 100644 --- a/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.spec.ts +++ b/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.spec.ts @@ -81,6 +81,7 @@ describe('QualityAssuranceTopicDataService', () => { ); spyOn((service as any).searchData, 'searchBy').and.callThrough(); + spyOn((service as any), 'findById').and.callThrough(); }); describe('searchTopicsByTarget', () => { @@ -133,4 +134,22 @@ describe('QualityAssuranceTopicDataService', () => { }); }); + describe('getTopic', () => { + it('should call findByHref', (done) => { + service.getTopic(qualityAssuranceTopicObjectMorePid.id).subscribe( + (res) => { + expect((service as any).findById).toHaveBeenCalledWith(qualityAssuranceTopicObjectMorePid.id, true, true); + } + ); + done(); + }); + + it('should return a RemoteData for the object with the given URL', () => { + const result = service.getTopic(qualityAssuranceTopicObjectMorePid.id); + const expected = cold('(a)', { + a: qaTopicObjectRD + }); + expect(result).toBeObservable(expected); + }); + }); }); diff --git a/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.ts b/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.ts index 6944e43a56..86c8f5eeaa 100644 --- a/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.ts +++ b/src/app/core/suggestion-notifications/qa/topics/quality-assurance-topic-data.service.ts @@ -16,6 +16,7 @@ import { IdentifiableDataService } from '../../../data/base/identifiable-data.se import { dataService } from '../../../data/base/data-service.decorator'; import { QUALITY_ASSURANCE_TOPIC_OBJECT } from '../models/quality-assurance-topic-object.resource-type'; import { SearchData, SearchDataImpl } from '../../../../core/data/base/search-data'; +import { FindAllData, FindAllDataImpl } from '../../../data/base/find-all-data'; /** * The service handling all Quality Assurance topic REST requests. @@ -24,6 +25,7 @@ import { SearchData, SearchDataImpl } from '../../../../core/data/base/search-da @dataService(QUALITY_ASSURANCE_TOPIC_OBJECT) export class QualityAssuranceTopicDataService extends IdentifiableDataService { + private findAllData: FindAllData; private searchData: SearchData; private searchByTargetMethod = 'byTarget'; @@ -45,6 +47,7 @@ export class QualityAssuranceTopicDataService extends IdentifiableDataService> + * The Quality Assurance topic. + */ + public getTopic(id: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable> { + return this.findById(id, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); + } } diff --git a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.html b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.html index c13929bf8a..68de6aec7a 100644 --- a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.html +++ b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.html @@ -2,7 +2,11 @@

{{'quality-assurance.title'| translate}}

- {{'quality-assurance.topics.description'| translate:{source: sourceId} }} + {{'quality-assurance.topics.description'| translate:{source: sourceId} }} + + {{'quality-assurance.topics.description-with-target'| translate:{source: sourceId} }} + {{(getTargetItemTitle() | async)}} +
diff --git a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.spec.ts b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.spec.ts index 52700d778b..4137fdfae1 100644 --- a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.spec.ts +++ b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.spec.ts @@ -16,6 +16,7 @@ import { SuggestionNotificationsStateService } from '../../suggestion-notificati import { cold } from 'jasmine-marbles'; import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub'; import { PaginationService } from '../../../core/pagination/pagination.service'; +import { ItemDataService } from '../../../core/data/item-data.service'; describe('QualityAssuranceTopicsComponent test suite', () => { let fixture: ComponentFixture; @@ -49,6 +50,7 @@ describe('QualityAssuranceTopicsComponent test suite', () => { }, }}}, { provide: PaginationService, useValue: paginationService }, + { provide: ItemDataService, useValue: {} }, QualityAssuranceTopicsComponent, ], schemas: [NO_ERRORS_SCHEMA] diff --git a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.ts b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.ts index b04bb4fbf2..0f7a111089 100644 --- a/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.ts +++ b/src/app/suggestion-notifications/qa/topics/quality-assurance-topics.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { Observable, Subscription } from 'rxjs'; -import { distinctUntilChanged, take } from 'rxjs/operators'; +import { distinctUntilChanged, map, take, tap } from 'rxjs/operators'; import { SortOptions } from '../../../core/cache/models/sort-options.model'; import { @@ -15,6 +15,10 @@ import { } from '../../../admin/admin-notifications/admin-quality-assurance-topics-page/admin-quality-assurance-topics-page-resolver.service'; import { PaginationService } from '../../../core/pagination/pagination.service'; import { ActivatedRoute } from '@angular/router'; +import { ItemDataService } from '../../../core/data/item-data.service'; +import { getFirstCompletedRemoteData, getRemoteDataPayload } from '../../../core/shared/operators'; +import { Item } from '../../../core/shared/item.model'; +import { getItemPageRoute } from '../../../item-page/item-page-routing-paths'; /** * Component to display the Quality Assurance topic list. @@ -65,6 +69,11 @@ export class QualityAssuranceTopicsComponent implements OnInit { */ public targetId: string; + /** + * The URL of the item page. + */ + public itemPageUrl: string; + /** * Initialize the component variables. * @param {PaginationService} paginationService @@ -75,7 +84,8 @@ export class QualityAssuranceTopicsComponent implements OnInit { constructor( private paginationService: PaginationService, private activatedRoute: ActivatedRoute, - private notificationsStateService: SuggestionNotificationsStateService + private notificationsStateService: SuggestionNotificationsStateService, + private itemService: ItemDataService ) { this.sourceId = this.activatedRoute.snapshot.params.sourceId; this.targetId = this.activatedRoute.snapshot.params.targetId; @@ -156,6 +166,32 @@ export class QualityAssuranceTopicsComponent implements OnInit { } } + /** + * Returns an Observable that emits the title of the target item. + * The target item is retrieved by its ID using the itemService. + * The title is extracted from the first metadata value of the item. + * The item page URL is also set in the component. + * @returns An Observable that emits the title of the target item. + */ + getTargetItemTitle(): Observable { + return this.itemService.findById(this.targetId).pipe( + take(1), + getFirstCompletedRemoteData(), + getRemoteDataPayload(), + tap((item: Item) => this.itemPageUrl = getItemPageRoute(item)), + map((item: Item) => item.firstMetadataValue('dc.title')) + ); + } + + /** + * Returns the page route for the given item. + * @param item The item to get the page route for. + * @returns The page route for the given item. + */ + getItemPageRoute(item: Item): string { + return getItemPageRoute(item); + } + /** * Unsubscribe from all subscriptions. */ diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index fd887d742c..a559f4cccf 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -3232,6 +3232,8 @@ "quality-assurance.topics.description": "Below you can see all the topics received from the subscriptions to {{source}}.", + "quality-assurance.topics.description-with-target": "Below you can see all the topics received from the subscriptions to {{source}} in regards to the", + "quality-assurance.source.description": "Below you can see all the notification's sources.", "quality-assurance.topics": "Current Topics",