From 5266194d845f74639e8a944ad7a04f80c2568de5 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 7 Jul 2022 16:29:50 +0200 Subject: [PATCH 1/3] [CST-5337] Update state name --- src/app/suggestion-notifications/selectors.ts | 6 ++++-- ...estion-notifications-state.service.spec.ts | 20 +++++++++---------- .../suggestion-notifications.module.ts | 14 +++++++++---- .../suggestion-notifications.reducer.ts | 12 ++++++++--- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/app/suggestion-notifications/selectors.ts b/src/app/suggestion-notifications/selectors.ts index c5947e3196d..d98c023ee45 100644 --- a/src/app/suggestion-notifications/selectors.ts +++ b/src/app/suggestion-notifications/selectors.ts @@ -4,7 +4,9 @@ import { suggestionNotificationsSelector, SuggestionNotificationsState } from '. import { QualityAssuranceTopicObject } from '../core/suggestion-notifications/qa/models/quality-assurance-topic.model'; import { QualityAssuranceTopicState } from './qa/topics/quality-assurance-topics.reducer'; import { QualityAssuranceSourceState } from './qa/source/quality-assurance-source.reducer'; -import { QualityAssuranceSourceObject } from '../core/suggestion-notifications/qa/models/quality-assurance-source.model'; +import { + QualityAssuranceSourceObject +} from '../core/suggestion-notifications/qa/models/quality-assurance-source.model'; /** * Returns the Notifications state. @@ -12,7 +14,7 @@ import { QualityAssuranceSourceObject } from '../core/suggestion-notifications/q * @param {AppState} state Top level state. * @return {SuggestionNotificationsState} */ -const _getNotificationsState = createFeatureSelector('notifications'); +const _getNotificationsState = createFeatureSelector('suggestionNotifications'); // Quality Assurance topics // ---------------------------------------------------------------------------- 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 b04368cfadb..ac669ed9548 100644 --- a/src/app/suggestion-notifications/suggestion-notifications-state.service.spec.ts +++ b/src/app/suggestion-notifications/suggestion-notifications-state.service.spec.ts @@ -25,7 +25,7 @@ describe('NotificationsStateService', () => { function init(mode: string) { if (mode === 'empty') { initialState = { - notifications: { + suggestionNotifications: { qaTopic: { topics: [], processing: false, @@ -39,7 +39,7 @@ describe('NotificationsStateService', () => { }; } else { initialState = { - notifications: { + suggestionNotifications: { qaTopic: { topics: [ qualityAssuranceTopicObjectMorePid, @@ -63,7 +63,7 @@ describe('NotificationsStateService', () => { init('empty'); TestBed.configureTestingModule({ imports: [ - StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any), + StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any), ], providers: [ provideMockStore({ initialState }), @@ -155,7 +155,7 @@ describe('NotificationsStateService', () => { init('full'); TestBed.configureTestingModule({ imports: [ - StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any), + StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any), ], providers: [ provideMockStore({ initialState }), @@ -251,7 +251,7 @@ describe('NotificationsStateService', () => { init('full'); TestBed.configureTestingModule({ imports: [ - StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any), + StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any), ], providers: [ provideMockStore({ initialState }), @@ -283,7 +283,7 @@ describe('NotificationsStateService', () => { function init(mode: string) { if (mode === 'empty') { initialState = { - notifications: { + suggestionNotifications: { qaSource: { source: [], processing: false, @@ -297,7 +297,7 @@ describe('NotificationsStateService', () => { }; } else { initialState = { - notifications: { + suggestionNotifications: { qaSource: { source: [ qualityAssuranceSourceObjectMorePid, @@ -321,7 +321,7 @@ describe('NotificationsStateService', () => { init('empty'); TestBed.configureTestingModule({ imports: [ - StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any), + StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any), ], providers: [ provideMockStore({ initialState }), @@ -413,7 +413,7 @@ describe('NotificationsStateService', () => { init('full'); TestBed.configureTestingModule({ imports: [ - StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any), + StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any), ], providers: [ provideMockStore({ initialState }), @@ -509,7 +509,7 @@ describe('NotificationsStateService', () => { init('full'); TestBed.configureTestingModule({ imports: [ - StoreModule.forRoot({ notifications: suggestionNotificationsReducers } as any), + StoreModule.forRoot({ suggestionNotifications: suggestionNotificationsReducers } as any), ], providers: [ provideMockStore({ initialState }), diff --git a/src/app/suggestion-notifications/suggestion-notifications.module.ts b/src/app/suggestion-notifications/suggestion-notifications.module.ts index f659d27a28e..90e73eb0bef 100644 --- a/src/app/suggestion-notifications/suggestion-notifications.module.ts +++ b/src/app/suggestion-notifications/suggestion-notifications.module.ts @@ -12,20 +12,26 @@ import { SuggestionNotificationsStateService } from './suggestion-notifications- import { suggestionNotificationsReducers, SuggestionNotificationsState } from './suggestion-notifications.reducer'; import { suggestionNotificationsEffects } from './suggestion-notifications-effects'; import { QualityAssuranceTopicsService } from './qa/topics/quality-assurance-topics.service'; -import { QualityAssuranceTopicRestService } from '../core/suggestion-notifications/qa/topics/quality-assurance-topic-rest.service'; -import { QualityAssuranceEventRestService } from '../core/suggestion-notifications/qa/events/quality-assurance-event-rest.service'; +import { + QualityAssuranceTopicRestService +} from '../core/suggestion-notifications/qa/topics/quality-assurance-topic-rest.service'; +import { + QualityAssuranceEventRestService +} from '../core/suggestion-notifications/qa/events/quality-assurance-event-rest.service'; import { ProjectEntryImportModalComponent } from './qa/project-entry-import-modal/project-entry-import-modal.component'; import { TranslateModule } from '@ngx-translate/core'; import { SearchModule } from '../shared/search/search.module'; import { QualityAssuranceSourceComponent } from './qa/source/quality-assurance-source.component'; import { QualityAssuranceSourceService } from './qa/source/quality-assurance-source.service'; -import { QualityAssuranceSourceRestService } from '../core/suggestion-notifications/qa/source/quality-assurance-source-rest.service'; +import { + QualityAssuranceSourceRestService +} from '../core/suggestion-notifications/qa/source/quality-assurance-source-rest.service'; const MODULES = [ CommonModule, SharedModule, CoreModule.forRoot(), - StoreModule.forFeature('notifications', suggestionNotificationsReducers, storeModuleConfig as StoreConfig), + StoreModule.forFeature('suggestionNotifications', suggestionNotificationsReducers, storeModuleConfig as StoreConfig), EffectsModule.forFeature(suggestionNotificationsEffects), TranslateModule ]; diff --git a/src/app/suggestion-notifications/suggestion-notifications.reducer.ts b/src/app/suggestion-notifications/suggestion-notifications.reducer.ts index cc0cdd71013..289d1e498b8 100644 --- a/src/app/suggestion-notifications/suggestion-notifications.reducer.ts +++ b/src/app/suggestion-notifications/suggestion-notifications.reducer.ts @@ -1,6 +1,12 @@ import { ActionReducerMap, createFeatureSelector } from '@ngrx/store'; -import { qualityAssuranceSourceReducer, QualityAssuranceSourceState } from './qa/source/quality-assurance-source.reducer'; -import { qualityAssuranceTopicsReducer, QualityAssuranceTopicState, } from './qa/topics/quality-assurance-topics.reducer'; +import { + qualityAssuranceSourceReducer, + QualityAssuranceSourceState +} from './qa/source/quality-assurance-source.reducer'; +import { + qualityAssuranceTopicsReducer, + QualityAssuranceTopicState, +} from './qa/topics/quality-assurance-topics.reducer'; /** * The OpenAIRE State @@ -15,4 +21,4 @@ export const suggestionNotificationsReducers: ActionReducerMap('notifications'); +export const suggestionNotificationsSelector = createFeatureSelector('suggestionNotifications'); From 92b1ce2d179e8b7a1d31b88c221bbe09ca7ab96b Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 7 Jul 2022 17:25:56 +0200 Subject: [PATCH 2/3] [CST-5337] Fix issue with list that wasn't updated after last element has been processed --- .../quality-assurance-events.component.ts | 105 +++++++++--------- 1 file changed, 55 insertions(+), 50 deletions(-) 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 edac869f8e4..0f71123d22a 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 @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; @@ -10,25 +10,27 @@ import { SortDirection, SortOptions } from '../../../core/cache/models/sort-opti import { PaginatedList } from '../../../core/data/paginated-list.model'; import { RemoteData } from '../../../core/data/remote-data'; import { - QualityAssuranceEventObject, - OpenaireQualityAssuranceEventMessageObject + OpenaireQualityAssuranceEventMessageObject, + QualityAssuranceEventObject } from '../../../core/suggestion-notifications/qa/models/quality-assurance-event.model'; -import { QualityAssuranceEventRestService } from '../../../core/suggestion-notifications/qa/events/quality-assurance-event-rest.service'; +import { + QualityAssuranceEventRestService +} from '../../../core/suggestion-notifications/qa/events/quality-assurance-event-rest.service'; import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; import { Metadata } from '../../../core/shared/metadata.utils'; import { followLink } from '../../../shared/utils/follow-link-config.model'; -import { hasValue } from '../../../shared/empty.util'; +import { hasValue, isEmpty } from '../../../shared/empty.util'; import { ItemSearchResult } from '../../../shared/object-collection/shared/item-search-result.model'; import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { - QualityAssuranceEventData, - ProjectEntryImportModalComponent + ProjectEntryImportModalComponent, + QualityAssuranceEventData } from '../project-entry-import-modal/project-entry-import-modal.component'; import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; import { PaginationService } from '../../../core/pagination/pagination.service'; import { combineLatest } from 'rxjs/internal/observable/combineLatest'; import { Item } from '../../../core/shared/item.model'; -import {FindListOptions} from '../../../core/data/find-list-options.model'; +import { FindListOptions } from '../../../core/data/find-list-options.model'; /** * Component to display the Quality Assurance event list. @@ -38,7 +40,7 @@ import {FindListOptions} from '../../../core/data/find-list-options.model'; templateUrl: './quality-assurance-events.component.html', styleUrls: ['./quality-assurance-events.scomponent.scss'], }) -export class QualityAssuranceEventsComponent implements OnInit { +export class QualityAssuranceEventsComponent implements OnInit, OnDestroy { /** * The pagination system configuration for HTML listing. * @type {PaginationComponentOptions} @@ -376,47 +378,50 @@ export class QualityAssuranceEventsComponent implements OnInit { * the Quality Assurance event item */ protected setEventUpdated(events: QualityAssuranceEventObject[]): void { - this.subs.push( - from(events).pipe( - mergeMap((event: QualityAssuranceEventObject) => { - const related$ = event.related.pipe( - getFirstCompletedRemoteData(), - ); - const target$ = event.target.pipe( - getFirstCompletedRemoteData() - ); - return combineLatest([related$, target$]).pipe( - map(([relatedItemRD, targetItemRD]: [RemoteData, RemoteData]) => { - const data: QualityAssuranceEventData = { - event: event, - id: event.id, - title: event.title, - hasProject: false, - projectTitle: null, - projectId: null, - handle: null, - reason: null, - isRunning: false, - target: (targetItemRD?.hasSucceeded) ? targetItemRD.payload : null, - }; - if (relatedItemRD?.hasSucceeded && relatedItemRD?.payload?.id) { - data.hasProject = true; - data.projectTitle = event.message.title; - data.projectId = relatedItemRD?.payload?.id; - data.handle = relatedItemRD?.payload?.handle; - } - return data; - }) - ); - }), - scan((acc: any, value: any) => [...acc, value], []), - take(events.length) - ).subscribe( - (eventsReduced) => { - this.eventsUpdated$.next(eventsReduced); - } - ) - ); + if (isEmpty(events)) { + this.eventsUpdated$.next([]); + } else { + this.subs.push( + from(events).pipe( + mergeMap((event: QualityAssuranceEventObject) => { + const related$ = event.related.pipe( + getFirstCompletedRemoteData(), + ); + const target$ = event.target.pipe( + getFirstCompletedRemoteData() + ); + return combineLatest([related$, target$]).pipe( + map(([relatedItemRD, targetItemRD]: [RemoteData, RemoteData]) => { + const data: QualityAssuranceEventData = { + event: event, + id: event.id, + title: event.title, + hasProject: false, + projectTitle: null, + projectId: null, + handle: null, + reason: null, + isRunning: false, + target: (targetItemRD?.hasSucceeded) ? targetItemRD.payload : null, + }; + if (relatedItemRD?.hasSucceeded && relatedItemRD?.payload?.id) { + data.hasProject = true; + data.projectTitle = event.message.title; + data.projectId = relatedItemRD?.payload?.id; + data.handle = relatedItemRD?.payload?.handle; + } + return data; + }) + ); + }), + scan((acc: any, value: any) => [...acc, value], []), + take(events.length) + ).subscribe((eventsReduced) => { + this.eventsUpdated$.next(eventsReduced); + } + ) + ); + } } protected computePIDHref(event: OpenaireQualityAssuranceEventMessageObject) { From 0942a1e474b4751256421450af327338191106e1 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 7 Jul 2022 17:26:58 +0200 Subject: [PATCH 3/3] [CST-5337] Improve layout --- .../quality-assurance-events.component.html | 61 ++++++++++--------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/app/suggestion-notifications/qa/events/quality-assurance-events.component.html b/src/app/suggestion-notifications/qa/events/quality-assurance-events.component.html index d7f6129b3b2..209b2cde278 100644 --- a/src/app/suggestion-notifications/qa/events/quality-assurance-events.component.html +++ b/src/app/suggestion-notifications/qa/events/quality-assurance-events.component.html @@ -91,7 +91,7 @@


{{(eventElement.hasProject ? 'quality-assurance.event.project.found' : 'quality-assurance.event.project.notFound') | translate}} - {{eventElement.handle}} + {{eventElement.handle}}
-
+
- - -
@@ -155,13 +166,13 @@
@@ -192,16 +200,13 @@