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
Rework unread counts for notification stores
Benjamin Bädorf18b6b61a0f35
diff --git a/frontend/src/app/features/in-app-notifications/bell/in-app-notification-bell.component.ts b/frontend/src/app/features/in-app-notifications/bell/in-app-notification-bell.component.tsindex 425a90a6513..db70a2b689e 100644--- a/frontend/src/app/features/in-app-notifications/bell/in-app-notification-bell.component.ts+++ b/frontend/src/app/features/in-app-notifications/bell/in-app-notification-bell.component.ts@@ -1,10 +1,10 @@-import { ChangeDetectionStrategy, Component } from '@angular/core';+import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';import { InAppNotificationsQuery } from 'core-app/features/in-app-notifications/store/in-app-notifications.query';import { InAppNotificationsStore } from 'core-app/features/in-app-notifications/store/in-app-notifications.store';import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';import { OpModalService } from 'core-app/shared/components/modal/modal.service';-import { merge, timer } from 'rxjs';-import { filter, switchMap } from 'rxjs/operators';+import { timer, combineLatest } from 'rxjs';+import { filter, switchMap, tap, map } from 'rxjs/operators';import { ActiveWindowService } from 'core-app/core/active-window/active-window.service';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';@@ -22,17 +22,18 @@ const POLLING_INTERVAL = 10000;InAppNotificationsQuery,],})-export class InAppNotificationBellComponent {+export class InAppNotificationBellComponent implements OnInit {polling$ = timer(10, POLLING_INTERVAL)- .pipe(- filter(() => this.activeWindow.isActive),- switchMap(() => this.inAppService.fetchUnreadCount()),- );+ .pipe(+ filter(() => this.activeWindow.isActive),+ tap(() => console.log('sending fetch request from bell')),+ switchMap(() => this.inAppService.fetchNotifications()),+ );- unreadCount$ = merge(+ unreadCount$ = combineLatest([+ this.inAppQuery.notLoaded$,this.polling$,- this.inAppQuery.unreadCount$,- );+ ]).pipe(map(([count]) => count));constructor(readonly inAppQuery:InAppNotificationsQuery,@@ -40,7 +41,12 @@ export class InAppNotificationBellComponent {readonly activeWindow:ActiveWindowService,readonly modalService:OpModalService,readonly pathHelper:PathHelperService,- ) {}+ ) { }++ ngOnInit() {+ this.inAppService.setPageSize(0);+ console.log('ngoninit ian bell');+ }notificationsPath():string {return this.pathHelper.notificationsPath();diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.tsindex 0573d9e3a2e..4ef2e8044ea 100644--- a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts+++ b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts@@ -13,7 +13,7 @@ export class InAppNotificationsQuery extends QueryEntity<InAppNotificationsState/** Select the active filter facet */activeFacet$ = this.select('activeFacet');- activeFetchParameters$ = this.select(['activeFacet', 'activeFilters']);+ activeFetchParameters$ = this.select(['activeFacet', 'pageSize', 'activeFilters']);/** Select the active filter facet */notLoaded$ = this.select('notLoaded');@@ -42,17 +42,17 @@ export class InAppNotificationsQuery extends QueryEntity<InAppNotificationsState)),);- /** Get the number of unread items */- unreadCount$ = this.select('unreadCount');-- /** Do we have any unread items? */- hasUnread$ = this.unreadCount$.pipe(map((count) => count > 0));-/** Get the unread items */unread$ = this.selectAll({filterBy: ({ readIAN }) => !readIAN,});+ /** Get the number of unread items */+ unreadCount$ = this.unread$.pipe(map((notifications) => notifications.length));++ /** Do we have any unread items? */+ hasUnread$ = this.unreadCount$.pipe(map((count) => count > 0));+/** Get all items that shall be kept in the notification center */unreadOrKept$ = this.selectAll({filterBy: ({ readIAN, keep }) => !readIAN || !!keep,diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.tsindex f3c40b7ae0b..e7b1b746802 100644--- a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts+++ b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts@@ -1,10 +1,10 @@import { Injectable } from '@angular/core';import {debounceTime,- map,switchMap,take,tap,+ catchError,} from 'rxjs/operators';import { applyTransaction, ID, setLoading } from '@datorama/akita';import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';@@ -13,7 +13,7 @@ import { NotificationsService } from 'core-app/shared/components/notifications/nimport { InAppNotificationsQuery } from 'core-app/features/in-app-notifications/store/in-app-notifications.query';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { InAppNotificationsStore } from './in-app-notifications.store';-import { InAppNotification, NOTIFICATIONS_MAX_SIZE } from './in-app-notification.model';+import { InAppNotification } from './in-app-notification.model';import { Observable } from 'rxjs';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';@@ -26,53 +26,40 @@ export class InAppNotificationsService {private notifications:NotificationsService,) {this.query.activeFetchParameters$- .pipe(debounceTime(0))- .subscribe(() => {- this.fetchNotifications();- this.fetchUnreadCount();- });+ .pipe(+ debounceTime(0),+ switchMap(() => this.fetchNotifications()),+ ).subscribe();}fetchNotifications():Observable<IHALCollection<InAppNotification>> {this.store.setLoading(true);- const { activeFacet, activeFilters } = this.query.getValue();+ const {+ activeFacet,+ activeFilters,+ pageSize,+ } = this.query.getValue();- const call = this+ return this.apiV3Service.notifications.facet(activeFacet, {- pageSize: NOTIFICATIONS_MAX_SIZE,+ pageSize,filters: activeFilters,- });-- call+ }).pipe(- tap((events) => this.sideLoadInvolvedWorkPackages(events._embedded.elements)),- )- .subscribe(- (events) => applyTransaction(() => {- this.store.set(events._embedded.elements);- this.store.update({ notShowing: events.total - events.count });+ tap((events) => {+ this.sideLoadInvolvedWorkPackages(events._embedded.elements);+ applyTransaction(() => {+ this.store.set(events._embedded.elements);+ this.store.update({ notLoaded: events.total - events.count });+ });+ this.store.setLoading(false);}),- (error) => this.notifications.addError(error),- )- .add(() => this.store.setLoading(false));-- return call;- }-- fetchUnreadCount():Observable<number> {- const { activeFilters } = this.query.getValue();-- return this- .apiV3Service- .notifications- .unread({ pageSize: 0, filters: activeFilters })- .pipe(- map((events) => events.total),- tap((unreadCount) => {- this.store.update({ unreadCount });+ catchError((error) => {+ this.notifications.addError(error);+ throw error;}),);}@@ -81,6 +68,10 @@ export class InAppNotificationsService {this.store.update(id, inAppNotification);}+ setPageSize(pageSize:number):void {+ this.store.update((state) => ({ ...state, pageSize }));+ }+setActiveFacet(facet:string):void {this.store.update((state) => ({ ...state, activeFacet: facet }));}diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.tsindex 5a415c207c5..97968fc52df 100644--- a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.ts+++ b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.ts@@ -1,13 +1,12 @@import { Injectable } from '@angular/core';import { EntityState, EntityStore, StoreConfig } from '@datorama/akita';-import { InAppNotification } from './in-app-notification.model';+import { InAppNotification, NOTIFICATIONS_MAX_SIZE } from './in-app-notification.model';import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';export interface InAppNotificationsState extends EntityState<InAppNotification> {- /** The entities in the store might not all be unread so we keep separate count */- unreadCount:number;/** Number of elements not showing after max values loaded */notLoaded:number;+ pageSize:number;activeFacet:string;activeFilters:ApiV3ListFilter[];expanded:boolean;@@ -15,8 +14,8 @@ export interface InAppNotificationsState extends EntityState<InAppNotification>export function createInitialState():InAppNotificationsState {return {- unreadCount: 0,notLoaded: 0,+ pageSize: NOTIFICATIONS_MAX_SIZE,activeFacet: 'unread',activeFilters: [],expanded: false,diff --git a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.tsindex 63a58f8afbe..f2d49bd0506 100644--- a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts+++ b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts@@ -56,7 +56,7 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imppublic displayWatchButton:boolean;- public displayNotificationsButton$:Observable<boolean> = this.ianService.query.hasNotifications$;+ public displayNotificationsButton$:Observable<boolean> = this.ianService.query.hasUnread$;public watchers:any;diff --git a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.htmlindex 024b2bdf8e1..dcde90f9dad 100644--- a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html+++ b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html@@ -35,8 +35,7 @@[workPackage]="workPackage"buttonClasses="toolbar-icon"data-qa-selector="mark-notification-read-button"- >- </op-work-package-mark-notification-button>+ ></op-work-package-mark-notification-button></li><li class="toolbar-item hidden-for-mobile"><zen-mode-toggle-button>diff --git a/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts b/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.tsindex 1c80dd00d0c..ac9d31fcdcd 100644--- a/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts+++ b/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts@@ -62,7 +62,7 @@ export class WorkPackageSplitViewComponent extends WorkPackageSingleViewBase imp/** Reference to the base route e.g., work-packages.partitioned.list or bim.partitioned.split */private baseRoute:string = this.$state.current.data.baseRoute;- public displayNotificationsButton$:Observable<boolean> = this.ianService.query.hasNotifications$;+ public displayNotificationsButton$:Observable<boolean> = this.ianService.query.hasUnread$;constructor(public injector:Injector,