OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Unify akita stores
Oliver Günther91ab376a9b63
diff --git a/frontend/src/app/core/state/collection-store.ts b/frontend/src/app/core/state/collection-store.tsindex 15fecd087d6..d6a5487ceb3 100644--- a/frontend/src/app/core/state/collection-store.ts+++ b/frontend/src/app/core/state/collection-store.ts@@ -3,15 +3,12 @@ import {EntityState,EntityStore,ID,- QueryEntity,} from '@datorama/akita';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';import {ApiV3ListParameters,listParamsString,} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';-import { Observable } from 'rxjs';-import { filter } from 'rxjs/operators';export interface CollectionResponse {ids:ID[];@@ -22,10 +19,6 @@ export interface CollectionState<T> extends EntityState<T> {collections:Record<string, CollectionResponse>;}-export interface CollectionService<T> {- query:QueryEntity<CollectionState<T>>;-}-export interface CollectionItem {id:ID;}@@ -54,53 +47,6 @@ export function collectionKey(params:ApiV3ListParameters):string {return listParamsString(params);}-/**- * Retrieve a collection from the given parameter set.- *- * @param service- * @param params- */-export function selectCollectionAsHrefs$<T extends CollectionItem>(service:CollectionService<T>, params:ApiV3ListParameters):Observable<CollectionResponse> {- return service- .query- .select((state) => {- const collection = collectionKey(params);- return state?.collections[collection];- })- .pipe(- filter((collection) => !!collection),- );-}--/**- * Retrieve the entities from the collection a given the ID collection- *- * @param service- * @param collection- */-export function selectEntitiesFromIDCollection<T extends CollectionItem>(service:CollectionService<T>, collection:CollectionResponse):T[] {- const ids = collection?.ids || [];-- return ids- .map((id) => service.query.getEntity(id))- .filter((item) => !!item) as T[];-}--/**- * Retrieve the entities from the collection a given parameter set produces.- *- * @param service- * @param state- * @param params- */-export function selectCollectionAsEntities$<T extends CollectionItem>(service:CollectionService<T>, params:ApiV3ListParameters):T[] {- const state = service.query.getValue();- const key = collectionKey(params);- const collection = state.collections[key];-- return selectEntitiesFromIDCollection(service, collection);-}-/*** Insert a collection into the given entity store*diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.query.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.query.tsdeleted file mode 100644index 75a8ef88457..00000000000--- a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.query.ts+++ /dev/null@@ -1,5 +0,0 @@-import { QueryEntity } from '@datorama/akita';-import { InAppNotificationsState } from './in-app-notifications.store';--export class InAppNotificationsQuery extends QueryEntity<InAppNotificationsState> {-}diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.tsindex 87c4a00d0a3..4348c0b55b5 100644--- a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts+++ b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts@@ -1,18 +1,11 @@import { Injectable } from '@angular/core';-import {- catchError,- tap,-} from 'rxjs/operators';+import { tap } from 'rxjs/operators';import { Observable } from 'rxjs';-import {- applyTransaction,- ID,-} from '@datorama/akita';+import { ID } from '@datorama/akita';import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { ToastService } from 'core-app/shared/components/toaster/toast.service';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';import { HttpClient } from '@angular/common/http';-import { InAppNotificationsQuery } from 'core-app/core/state/in-app-notifications/in-app-notifications.query';import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';import {collectionKey,@@ -29,14 +22,14 @@ import {import { ActionsService } from 'core-app/core/state/actions/actions.service';import { InAppNotificationsStore } from './in-app-notifications.store';import { InAppNotification } from './in-app-notification.model';+import {+ CollectionStore,+ ResourceCollectionService,+} from 'core-app/core/state/resource-collection.service';@EffectHandler@Injectable()-export class InAppNotificationsResourceService {- protected store = new InAppNotificationsStore();-- readonly query = new InAppNotificationsQuery(this.store);-+export class InAppNotificationsResourceService extends ResourceCollectionService<InAppNotification> {private get notificationsPath():string {return this.apiV3Service@@ -50,6 +43,7 @@ export class InAppNotificationsResourceService {private apiV3Service:ApiV3Service,private toastService:ToastService,) {+ super();}fetchNotifications(params:ApiV3ListParameters):Observable<IHALCollection<InAppNotification>> {@@ -67,36 +61,6 @@ export class InAppNotificationsResourceService {this.store.update(id, inAppNotification);}- modifyCollection(params:ApiV3ListParameters, callback:(collection:ID[]) => ID[]):void {- const key = collectionKey(params);- this.store.update(({ collections }) => (- {- collections: {- ...collections,- [key]: {- ...collections[key],- ids: [...callback(collections[key]?.ids || [])],- },- },- }- ));- }-- removeFromCollection(params:ApiV3ListParameters, ids:ID[]):void {- const key = collectionKey(params);- this.store.update(({ collections }) => (- {- collections: {- ...collections,- [key]: {- ...collections[key],- ids: (collections[key]?.ids || []).filter((id) => !ids.includes(id)),- },- },- }- ));- }-markAsRead(notifications:ID[]):Observable<unknown> {return this.apiV3Service@@ -120,4 +84,8 @@ export class InAppNotificationsResourceService {this.actions$.dispatch(notificationsMarkedRead(action))));}++ protected createStore():CollectionStore<InAppNotification> {+ return new InAppNotificationsStore();+ }}diff --git a/frontend/src/app/core/state/resource-collection.service.ts b/frontend/src/app/core/state/resource-collection.service.tsnew file mode 100644index 00000000000..d2e43d68e9d--- /dev/null+++ b/frontend/src/app/core/state/resource-collection.service.ts@@ -0,0 +1,82 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2022 the OpenProject GmbH+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License version 3.+//+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+// Copyright (C) 2006-2013 Jean-Philippe Lang+// Copyright (C) 2010-2013 the ChiliProject Team+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License+// as published by the Free Software Foundation; either version 2+// of the License, or (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+//+// See COPYRIGHT and LICENSE files for more details.+//++++import {+ EntityStore,+ ID,+ QueryEntity,+} from '@datorama/akita';+import { Observable } from 'rxjs';+import {+ filter,+ map,+ switchMap,+} from 'rxjs/operators';+import { CollectionState } from 'core-app/core/state/collection-store';++export type CollectionStore<T> = EntityStore<CollectionState<T>>;++export abstract class ResourceCollectionService<T> {+ protected store:CollectionStore<T> = this.createStore();++ protected query = new QueryEntity(this.store);++ /**+ * Retrieve a collection from the store+ *+ * @param key The collection key to fetch+ */+ collection(key:string):Observable<T[]> {+ return this+ .query+ .select()+ .pipe(+ map((state) => state.collections[key]?.ids),+ switchMap((fileLinkIds) => this.query.selectMany(fileLinkIds)),+ );+ }++ /**+ * Lookup a single entity from the store+ * @param id+ */+ lookup(id:ID):Observable<T> {+ return this+ .query+ .selectEntity(id)+ .pipe(+ filter((entity) => entity !== undefined),+ ) as Observable<T>;+ }++ /**+ * Create a new instance of this resource service's underyling store.+ * @protected+ */+ protected abstract createStore():CollectionStore<T>;+}diff --git a/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.ts b/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.tsindex 56093b0827a..93de3494487 100644--- a/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.ts+++ b/frontend/src/app/features/in-app-notifications/center/empty-state/empty-state.component.ts@@ -59,7 +59,7 @@ export class EmptyStateComponent {no_selection: this.I18n.t('js.notifications.center.empty_state.no_selection'),};- hasNotifications$ = this.storeService.query.hasNotifications$;+ hasNotifications$ = this.storeService.hasNotifications$;totalCount$ = this.bellService.unread$;diff --git a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.ts b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.tsindex 9e95b699ea0..a626108bef8 100644--- a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.ts+++ b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.ts@@ -30,13 +30,13 @@ import { IanBellService } from 'core-app/features/in-app-notifications/bell/statexport class InAppNotificationCenterComponent implements OnInit {maxSize = NOTIFICATIONS_MAX_SIZE;- hasMoreThanPageSize$ = this.storeService.query.hasMoreThanPageSize$;+ hasMoreThanPageSize$ = this.storeService.hasMoreThanPageSize$;- hasNotifications$ = this.storeService.query.hasNotifications$;+ hasNotifications$ = this.storeService.hasNotifications$;- notifications$ = this.storeService.query.notifications$;+ notifications$ = this.storeService.notifications$;- loading$ = this.storeService.query.selectLoading();+ loading$ = this.storeService.loading$;private totalCount$ = this.bellService.unread$;@@ -48,7 +48,6 @@ export class InAppNotificationCenterComponent implements OnInit {totalCountWarning$ = this.storeService- .query.notLoaded$.pipe(filter((notLoaded) => notLoaded > 0),diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.query.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.query.tsdeleted file mode 100644index 39bb0f7c9fa..00000000000--- a/frontend/src/app/features/in-app-notifications/center/state/ian-center.query.ts+++ /dev/null@@ -1,86 +0,0 @@-import { Query } from '@datorama/akita';-import {- distinctUntilChanged,- map,-} from 'rxjs/operators';-import {- IAN_FACET_FILTERS,- IanCenterState,- IanCenterStore,-} from 'core-app/features/in-app-notifications/center/state/ian-center.store';-import {- ApiV3ListFilter,- ApiV3ListParameters,-} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';-import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';-import { selectEntitiesFromIDCollection } from 'core-app/core/state/collection-store';--export class IanCenterQuery extends Query<IanCenterState> {- activeFacet$ = this.select('activeFacet');-- notLoaded$ = this.select('notLoaded');-- paramsChanges$ = this.select(['params', 'activeFacet']);-- activeCollection$ = this.select('activeCollection');-- selectNotifications$ = this- .activeCollection$- .pipe(- map((collection) => selectEntitiesFromIDCollection(this.resourceService, collection)),- distinctUntilChanged(),- );-- aggregatedCenterNotifications$ = this- .selectNotifications$- .pipe(- map((notifications) => (- _.groupBy(notifications, (notification) => notification._links.resource?.href || 'none')- )),- distinctUntilChanged(),- );-- notifications$ = this- .aggregatedCenterNotifications$- .pipe(- map((items) => Object.values(items)),- distinctUntilChanged(),- );-- hasNotifications$ = this- .notifications$- .pipe(- distinctUntilChanged(),- map((items) => items.length > 0),- distinctUntilChanged(),- );-- hasMoreThanPageSize$ = this- .notLoaded$- .pipe(- map((notLoaded) => notLoaded > 0),- distinctUntilChanged(),- );-- get params():ApiV3ListParameters {- const state = this.store.getValue();- const hasFilters = state.filters.name && state.filters.filter;- return {- ...state.params,- filters: [- ...IAN_FACET_FILTERS[state.activeFacet],- ...(hasFilters- ? ([[state.filters.filter, '=', [state.filters.name]]] as ApiV3ListFilter[])- : []- ),- ],- };- }-- constructor(- protected store:IanCenterStore,- protected resourceService:InAppNotificationsResourceService,- ) {- super(store);- }-}diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.tsindex e4bc76c13ce..28e22d0ee66 100644--- a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts@@ -14,15 +14,20 @@ import {tap,} from 'rxjs/operators';import {+ forkJoin,from,+ Observable,Subject,} from 'rxjs';import {ID,- setLoading,+ Query,} from '@datorama/akita';import { I18nService } from 'core-app/core/i18n/i18n.service';-import { IToast, ToastService } from 'core-app/shared/components/toaster/toast.service';+import {+ IToast,+ ToastService,+} from 'core-app/shared/components/toaster/toast.service';import {centerUpdatedInPlace,markNotificationsAsRead,@@ -30,7 +35,6 @@ import {notificationsMarkedRead,} from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';-import { IanCenterQuery } from 'core-app/features/in-app-notifications/center/state/ian-center.query';import {EffectCallback,EffectHandler,@@ -40,12 +44,12 @@ import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';import {+ collectionKey,mapHALCollectionToIDCollection,- selectCollectionAsEntities$,- selectCollectionAsHrefs$,} from 'core-app/core/state/collection-store';import { INotificationPageQueryParameters } from 'core-app/features/in-app-notifications/in-app-notifications.routes';import {+ IAN_FACET_FILTERS,IanCenterStore,InAppNotificationFacet,} from './ian-center.store';@@ -54,6 +58,10 @@ import { UIRouterGlobals } from '@uirouter/core';import { StateService } from '@uirouter/angular';import idFromLink from 'core-app/features/hal/helpers/id-from-link';import { DeviceService } from 'core-app/core/browser/device.service';+import {+ ApiV3ListFilter,+ ApiV3ListParameters,+} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';@Injectable()@EffectHandler@@ -62,7 +70,70 @@ export class IanCenterService extends UntilDestroyedMixin {readonly store = new IanCenterStore();- readonly query = new IanCenterQuery(this.store, this.resourceService);+ readonly query = new Query(this.store);++ activeFacet$ = this.query.select('activeFacet');++ notLoaded$ = this.query.select('notLoaded');++ paramsChanges$ = this.query.select(['params', 'activeFacet']);++ activeCollection$ = this.query.select('activeCollection');++ loading$:Observable<boolean> = this.query.selectLoading();++ selectNotifications$:Observable<InAppNotification[]> = this+ .activeCollection$+ .pipe(+ switchMap((collection) => forkJoin(collection.ids.map((id) => this.resourceService.lookup(id)))),+ );++ aggregatedCenterNotifications$ = this+ .selectNotifications$+ .pipe(+ map((notifications) => (+ _.groupBy(notifications, (notification) => notification._links.resource?.href || 'none')+ )),+ distinctUntilChanged(),+ );++ notifications$ = this+ .aggregatedCenterNotifications$+ .pipe(+ map((items) => Object.values(items)),+ distinctUntilChanged(),+ );++ hasNotifications$ = this+ .notifications$+ .pipe(+ distinctUntilChanged(),+ map((items) => items.length > 0),+ distinctUntilChanged(),+ );++ hasMoreThanPageSize$ = this+ .notLoaded$+ .pipe(+ map((notLoaded) => notLoaded > 0),+ distinctUntilChanged(),+ );++ get params():ApiV3ListParameters {+ const state = this.store.getValue();+ const hasFilters = state.filters.name && state.filters.filter;+ return {+ ...state.params,+ filters: [+ ...IAN_FACET_FILTERS[state.activeFacet],+ ...(+ hasFilters+ ? ([[state.filters.filter, '=', [state.filters.name]]] as ApiV3ListFilter[])+ : []+ ),+ ],+ };+ }private activeReloadToast:IToast|null = null;@@ -75,8 +146,9 @@ export class IanCenterService extends UntilDestroyedMixin {this.store.setLoading(true);}}),- switchMap(() => this.resourceService- .fetchNotifications(this.query.params)+ switchMap(() => this+ .resourceService+ .fetchNotifications(this.params).pipe(switchMap((results) => from(this.sideLoadInvolvedWorkPackages(results._embedded.elements))@@ -149,13 +221,22 @@ export class IanCenterService extends UntilDestroyedMixin {}markAllAsRead():void {- const ids:ID[] = selectCollectionAsEntities$(this.resourceService, this.query.params)- .filter((notification) => notification.readIAN === false)- .map((notification) => notification.id);+ const key = collectionKey(this.params);+ this+ .resourceService+ .collection(key)+ .pipe(+ take(1),+ )+ .subscribe((elements) => {+ const ids:ID[] = elements+ .filter((notification) => notification.readIAN === false)+ .map((notification) => notification.id);- if (ids.length > 0) {- this.markAsRead(ids);- }+ if (ids.length > 0) {+ this.markAsRead(ids);+ }+ });}openSplitScreen(wpId:string|null):void {@@ -168,7 +249,6 @@ export class IanCenterService extends UntilDestroyedMixin {showNextNotification():void {void this- .query.notifications$.pipe(take(1),@@ -268,18 +348,20 @@ export class IanCenterService extends UntilDestroyedMixin {private updateSelectedNotificationIndex() {this- .query.notifications$.pipe(take(1),- ).subscribe((notifications:InAppNotification[][]) => {- for (let i = 0; i < notifications.length; ++i) {- if (notifications[i][0]._links.resource- && idFromLink(notifications[i][0]._links.resource.href) === this.uiRouterGlobals.params.workPackageId) {- this.selectedNotificationIndex = i;- return;+ )+ .subscribe(+ (notifications:InAppNotification[][]) => {+ for (let i = 0; i < notifications.length; ++i) {+ if (notifications[i][0]._links.resource+ && idFromLink(notifications[i][0]._links.resource.href) === this.uiRouterGlobals.params.workPackageId) {+ this.selectedNotificationIndex = i;+ return;+ }}- }- });+ },+ );}}diff --git a/frontend/src/app/features/in-app-notifications/center/toolbar/facet/activate-facet-button.component.ts b/frontend/src/app/features/in-app-notifications/center/toolbar/facet/activate-facet-button.component.tsindex 88b552d19d2..d2ed3be2f65 100644--- a/frontend/src/app/features/in-app-notifications/center/toolbar/facet/activate-facet-button.component.ts+++ b/frontend/src/app/features/in-app-notifications/center/toolbar/facet/activate-facet-button.component.ts@@ -21,7 +21,7 @@ export class ActivateFacetButtonComponent {availableFacets = Object.keys(IAN_FACET_FILTERS);- activeFacet$ = this.storeService.query.activeFacet$;+ activeFacet$ = this.storeService.activeFacet$;constructor(private I18n:I18nService,diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.tsindex 61acc4832c6..6f598ec372d 100644--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts@@ -101,7 +101,8 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implementsthis.reloadActivities();});- this.wpSingleViewService.query+ this+ .wpSingleViewService.selectNotificationsCount$.pipe(this.untilDestroyed(),@@ -113,7 +114,9 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implements}private scrollIfNotificationPresent() {- this.storeService.query.hasNotifications$+ this+ .storeService+ .hasNotifications$.pipe(take(1)).subscribe((hasNotification) => {if (hasNotification) {@@ -166,7 +169,6 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implementsprotected hasUnreadNotification(activityHref:string):Observable<boolean> {return this.storeService- .query.selectNotifications$.pipe(map((notifications) => (diff --git a/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-notifications-count.function.ts b/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-notifications-count.function.tsindex 3bad49dd213..5ca6e08c746 100644--- a/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-notifications-count.function.ts+++ b/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-notifications-count.function.ts@@ -8,5 +8,5 @@ export function workPackageNotificationsCount(injector:Injector,):Observable<number> {const storeService = injector.get(WpSingleViewService);- return storeService.query.selectNotificationsCount$;+ return storeService.selectNotificationsCount$;}diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.query.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.query.tsdeleted file mode 100644index a857a682c4a..00000000000--- a/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.query.ts+++ /dev/null@@ -1,47 +0,0 @@-import { Query } from '@datorama/akita';-import {- WpSingleViewState,- WpSingleViewStore,-} from './wp-single-view.store';-import {- filter,- map,-} from 'rxjs/operators';-import { selectCollectionAsEntities$ } from 'core-app/core/state/collection-store';-import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';-import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';-import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';-import { combineLatest } from 'rxjs';--export class WpSingleViewQuery extends Query<WpSingleViewState> {- selectNotifications$ = combineLatest([- this.select((state) => state.notifications.filters),- this.resourceService.query.select(),- ]).pipe(- filter((filters) => filters.length > 0),- map(([filters]) => selectCollectionAsEntities$<InAppNotification>(this.resourceService, { filters })),- );-- selectNotificationsCount$ = this- .selectNotifications$- .pipe(- map((notifications) => notifications.length),- );-- hasNotifications$ = this- .selectNotificationsCount$- .pipe(- map((count) => count > 0),- );-- get params():ApiV3ListParameters {- return { filters: this.getValue().notifications.filters };- }-- constructor(- protected store:WpSingleViewStore,- protected resourceService:InAppNotificationsResourceService,- ) {- super(store);- }-}diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.tsindex 7090ec93e1b..8c381b9f4df 100644--- a/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts@@ -1,18 +1,20 @@import { Injectable } from '@angular/core';import { WpSingleViewStore } from './wp-single-view.store';-import { WpSingleViewQuery } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.query';import {filter,+ map,switchMap,take,} from 'rxjs/operators';-import { selectCollectionAsHrefs$ } from 'core-app/core/state/collection-store';import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';-import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';import {+ ApiV3ListFilter,+ ApiV3ListParameters,+} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import {+ centerUpdatedInPlace,markNotificationsAsRead,notificationsMarkedRead,- centerUpdatedInPlace,} from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';import { ActionsService } from 'core-app/core/state/actions/actions.service';import {@@ -20,6 +22,8 @@ import {EffectHandler,} from 'core-app/core/state/effects/effect-handler.decorator';import { CurrentUserService } from 'core-app/core/current-user/current-user.service';+import { collectionKey } from 'core-app/core/state/collection-store';+import { Query } from '@datorama/akita';@EffectHandler@Injectable()@@ -28,7 +32,31 @@ export class WpSingleViewService {protected store = new WpSingleViewStore();- readonly query = new WpSingleViewQuery(this.store, this.resourceService);+ protected query = new Query(this.store);++ selectNotifications$ = this+ .query+ .select((state) => state.notifications.filters)+ .pipe(+ filter((filters) => filters.length > 0),+ switchMap((filters) => this.resourceService.collection(collectionKey({ filters }))),+ );++ selectNotificationsCount$ = this+ .selectNotifications$+ .pipe(+ map((notifications) => notifications.length),+ );++ hasNotifications$ = this+ .selectNotificationsCount$+ .pipe(+ map((count) => count > 0),+ );++ get params():ApiV3ListParameters {+ return { filters: this.query.getValue().notifications.filters };+ }constructor(readonly actions$:ActionsService,@@ -57,13 +85,16 @@ export class WpSingleViewService {}markAllAsRead():void {- selectCollectionAsHrefs$(this.resourceService, { filters: this.store.getValue().notifications.filters })+ const key = collectionKey({ filters: this.store.getValue().notifications.filters });+ this+ .resourceService+ .collection(key).pipe(take(1),).subscribe((collection) => {this.actions$.dispatch(- markNotificationsAsRead({ origin: this.id, notifications: collection.ids }),+ markNotificationsAsRead({ origin: this.id, notifications: collection.map((el) => el.id) }),);});}@@ -75,7 +106,7 @@ export class WpSingleViewService {.pipe(take(1),filter((loggedIn) => loggedIn),- switchMap(() => this.resourceService.fetchNotifications(this.query.params)),+ switchMap(() => this.resourceService.fetchNotifications(this.params)),).subscribe();}diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.tsindex 2c6734f4b05..0c32feccb48 100644--- a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts@@ -175,7 +175,7 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {this.toastService.addError(error);});- this.displayNotificationsButton$ = this.storeService.query.hasNotifications$;+ this.displayNotificationsButton$ = this.storeService.hasNotifications$;this.storeService.setFilters(this.workPackage.id as string);// Set authorisation data