Skip to content

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

Review feedback

Oliver Günther90639975d5bb
diff --git a/frontend/src/app/core/state/collection-store.type.ts b/frontend/src/app/core/state/collection-store.ts
similarity index 85%
rename from frontend/src/app/core/state/collection-store.type.ts
rename to frontend/src/app/core/state/collection-store.ts
index 51720ebbee9..3a7a8178613 100644
--- a/frontend/src/app/core/state/collection-store.type.ts
+++ b/frontend/src/app/core/state/collection-store.ts
@@ -54,7 +54,7 @@ export function collectionKey(params:Apiv3ListParameters):string {
* @param service
* @param params
*/
-export function selectCollection$<T extends CollectionItem>(service:CollectionService<T>, params:Apiv3ListParameters):Observable<CollectionResponse> {
+export function selectCollectionAsHrefs$<T extends CollectionItem>(service:CollectionService<T>, params:Apiv3ListParameters):Observable<CollectionResponse> {
return service
.query
.select((state) => {
@@ -72,7 +72,7 @@ export function selectCollection$<T extends CollectionItem>(service:CollectionSe
* @param service
* @param params
*/
-export function selectCollectionEntities$<T extends CollectionItem>(service:CollectionService<T>, params:Apiv3ListParameters):Observable<T[]> {
+export function selectCollectionAsEntities$<T extends CollectionItem>(service:CollectionService<T>, params:Apiv3ListParameters):Observable<T[]> {
const key = collectionKey(params);
return service
diff --git a/frontend/src/app/core/state/effects/effect-handler.decorator.ts b/frontend/src/app/core/state/effects/effect-handler.decorator.ts
index 91d2a7aad55..ee2e028265e 100644
--- a/frontend/src/app/core/state/effects/effect-handler.decorator.ts
+++ b/frontend/src/app/core/state/effects/effect-handler.decorator.ts
@@ -7,33 +7,59 @@ import { ActionCreator } from 'ts-action/action';
import { Injector } from '@angular/core';
import { Action } from 'ts-action';
-// We're opening a baseclass through the decorator, the decorator enforces using any */
-/* eslint-disable @typescript-eslint/no-explicit-any */
-/* eslint-disable @typescript-eslint/no-unsafe-member-access */
-/* eslint-disable no-param-reassign */
-
+/**
+ * This interface specifies a constraint on the classes that can
+ * be used as an @EffectHandler.
+ *
+ * As we depend on the ActionsService, we need that as a public property.
+ */
export interface EffectClass extends UntilDestroyedMixin {
- injector:Injector;
+ actions$:ActionsService;
}
+
const EffectHandlers = Symbol('EffectHandlers');
type EffectHandlerItem = { callback:(action:Action) => void, action:ActionCreator };
+/**
+ * The EffectHandler decorates a class to be used for effects callbacks
+ * To use, add it to a store service like so
+ *
+ * ```
+ * @Injectable()
+ * @EffectHandler
+ * export class FooStoreService {
+ * @EffectCallback(someActionName)
+ * private actionCallback(action:ReturnType<typeof someActionName>) {
+ * // Effect callback for the given action
+ * }
+ * }
+ */
+/* The class decorator requires any[] args to it to function */
+
+/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
export function EffectHandler<T extends { new(...args:any[]):EffectClass }>(constructor:T):any {
return class extends constructor {
+ /* The class decorator requires any[] args to it to function */
+
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
constructor(...args:any[]) {
super(...args);
+
+ // Access the handlers registered in the @EffectCallback method decorator
+ // We're accessing a separate symbol on the base class that is not present
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const handlers = constructor.prototype[EffectHandlers] as Map<string, EffectHandlerItem>;
if (handlers) {
handlers.forEach((item:EffectHandlerItem, key:string) => {
- debugLog(`Subscribing to effect ${key}`);
-
- const actions$ = this.injector.get(ActionsService);
+ debugLog(`[${constructor.name}] Subscribing to effect ${key}`);
- actions$
+ // Subscribe to the specified action for the duration of this service's life.
+ this.actions$
.ofType(item.action)
.pipe(untilComponentDestroyed(this))
.subscribe((instance) => {
+ // Wrap callback in a try-catch to avoid completing the subscription.
try {
item.callback.call(this, instance);
} catch (e) {
@@ -47,10 +73,32 @@ export function EffectHandler<T extends { new(...args:any[]):EffectClass }>(cons
};
}
+/**
+ * The EffectCallback decorates a method of a `@EffectHandler` decorated class
+ * to be used for effects callbacks.
+ *
+ * The decorator subscribes to the actionService for the given service for
+ * the lifetime of the service.
+ *
+ * Example:
+ *
+ * ```
+ * @Injectable()
+ * @EffectHandler
+ * export class FooStoreService {
+ * @EffectCallback(someActionName)
+ * private actionCallback(action:ReturnType<typeof someActionName>) {
+ * // Effect callback for the given action
+ * }
+ * }
+ */
export function EffectCallback(action:ActionCreator) {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
- return (target:any, property:string, descriptor:PropertyDescriptor):void => {
+ return (service:unknown, property:string, descriptor:PropertyDescriptor):void => {
+ const target = service as { [EffectHandlers]:Map<string, EffectHandlerItem> };
if (!target[EffectHandlers]) {
+ // We're assigning the symbol property in the base class
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,no-param-reassign
target[EffectHandlers] = new Map();
}
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.ts
index 2805cd57a74..ac93a9ce40f 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,7 +1,4 @@
-import {
- Injectable,
- Injector,
-} from '@angular/core';
+import { Injectable } from '@angular/core';
import {
catchError,
tap,
@@ -19,7 +16,7 @@ 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 } from 'core-app/core/state/collection-store.type';
+import { collectionKey } from 'core-app/core/state/collection-store';
import {
markNotificationsAsRead,
notificationsMarkedRead,
@@ -39,11 +36,10 @@ export class InAppNotificationsService extends UntilDestroyedMixin {
readonly query = new InAppNotificationsQuery(this.store);
constructor(
- readonly injector:Injector,
+ readonly actions$:ActionsService,
private http:HttpClient,
private apiV3Service:APIV3Service,
private notifications:NotificationsService,
- private actions$:ActionsService,
) {
super();
}
diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.store.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.store.ts
index 6d7503a6764..4d0f8512814 100644
--- a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.store.ts
+++ b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.store.ts
@@ -1,6 +1,6 @@
import { EntityStore, StoreConfig } from '@datorama/akita';
import { InAppNotification } from './in-app-notification.model';
-import { CollectionState, createInitialCollectionState } from 'core-app/core/state/collection-store.type';
+import { CollectionState, createInitialCollectionState } from 'core-app/core/state/collection-store';
export interface InAppNotificationsState extends CollectionState<InAppNotification> {
}
diff --git a/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts
index 455e5dfb50c..9df19c9649a 100644
--- a/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts
+++ b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts
@@ -1,7 +1,4 @@
-import {
- Injectable,
- Injector,
-} from '@angular/core';
+import { Injectable } from '@angular/core';
import { IanBellStore } from './ian-bell.store';
import { InAppNotificationsService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
import { IAN_FACET_FILTERS } from 'core-app/features/in-app-notifications/center/state/ian-center.store';
@@ -17,6 +14,7 @@ import {
} from 'core-app/core/state/effects/effect-handler.decorator';
import { notificationsMarkedRead } from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
+import { ActionsService } from 'core-app/core/state/actions/actions.service';
@Injectable()
@EffectHandler
@@ -30,7 +28,7 @@ export class IanBellService extends UntilDestroyedMixin {
unread$ = this.query.select('totalUnread');
constructor(
- readonly injector:Injector,
+ readonly actions$:ActionsService,
readonly ianService:InAppNotificationsService,
) {
super();
@@ -47,12 +45,8 @@ export class IanBellService extends UntilDestroyedMixin {
);
}
- markRead(count:number):void {
- this.store.update(({ totalUnread }) => ({ totalUnread: totalUnread - count }));
- }
-
@EffectCallback(notificationsMarkedRead)
private reloadOnNotificationRead(action:ReturnType<typeof notificationsMarkedRead>) {
- this.markRead(action.notifications.length);
+ this.store.update(({ totalUnread }) => ({ totalUnread: totalUnread - action.notifications.length }));
}
}
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.ts
index f303ac91cd8..0f4bf672df1 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
@@ -25,29 +25,13 @@ import { NOTIFICATIONS_MAX_SIZE } from 'core-app/core/state/in-app-notifications
export class InAppNotificationCenterComponent implements OnInit {
maxSize = NOTIFICATIONS_MAX_SIZE;
- activeFacet$ = this.storeService.activeFacet$;
+ hasMoreThanPageSize$ = this.storeService.query.hasMoreThanPageSize$;
- notifications$ = this
- .storeService
- .aggregatedCenterNotifications$
- .pipe(
- map((items) => Object.values(items)),
- );
-
- hasNotifications$ = this
- .notifications$
- .pipe(
- map((items) => items.length > 0),
- );
-
- hasMoreThanPageSize$ = this
- .storeService
- .notLoaded$
- .pipe(
- map((notLoaded) => notLoaded > 0),
- );
+ hasNotifications$ = this.storeService.query.hasNotifications$;
noResultText$ = this
+ .storeService
+ .query
.activeFacet$
.pipe(
map((facet:'unread'|'all') => this.text.no_results[facet] || this.text.no_results.unread),
@@ -55,6 +39,7 @@ 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.ts
index 827b2363931..5f8cff2979d 100644
--- 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.ts
@@ -1,11 +1,62 @@
import { Query } from '@datorama/akita';
import {
+ IAN_FACET_FILTERS,
IanCenterState,
IanCenterStore,
} from 'core-app/features/in-app-notifications/center/state/ian-center.store';
import { InAppNotificationsService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
+import {
+ map,
+ switchMap,
+} from 'rxjs/operators';
+import { Apiv3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
+import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';
+import { selectCollectionAsEntities$ } 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']);
+
+ selectNotifications$ = this
+ .paramsChanges$
+ .pipe(
+ switchMap(() => selectCollectionAsEntities$<InAppNotification>(this.ianService, this.params)),
+ );
+
+ aggregatedCenterNotifications$ = this
+ .selectNotifications$
+ .pipe(
+ map((notifications) => (
+ _.groupBy(notifications, (notification) => notification._links.resource?.href || 'none')
+ )),
+ );
+
+ notifications$ = this
+ .aggregatedCenterNotifications$
+ .pipe(
+ map((items) => Object.values(items)),
+ );
+
+ hasNotifications$ = this
+ .notifications$
+ .pipe(
+ map((items) => items.length > 0),
+ );
+
+ hasMoreThanPageSize$ = this
+ .notLoaded$
+ .pipe(
+ map((notLoaded) => notLoaded > 0),
+ );
+
+ get params():Apiv3ListParameters {
+ const state = this.store.getValue();
+ return { ...state.params, filters: IAN_FACET_FILTERS[state.activeFacet] };
+ }
+
constructor(
protected store:IanCenterStore,
protected ianService:InAppNotificationsService,
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.ts
index 7ab14bc5e71..fd704ccb14f 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
@@ -3,21 +3,13 @@ import {
Injector,
} from '@angular/core';
import {
- IAN_FACET_FILTERS,
IanCenterStore,
InAppNotificationFacet,
} from './ian-center.store';
import {
map,
- switchMap,
take,
- tap,
} from 'rxjs/operators';
-import {
- selectCollection$,
- selectCollectionEntities$,
-} from 'core-app/core/state/collection-store.type';
-import { InAppNotificationsService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
import {
markNotificationsAsRead,
notificationsMarkedRead,
@@ -30,11 +22,12 @@ import {
EffectHandler,
} from 'core-app/core/state/effects/effect-handler.decorator';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
-import { Apiv3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
import { ActionsService } from 'core-app/core/state/actions/actions.service';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';
import { from } from 'rxjs';
+import { InAppNotificationsService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
+import { selectCollectionAsHrefs$ } from 'core-app/core/state/collection-store';
@Injectable()
@EffectHandler
@@ -45,29 +38,6 @@ export class IanCenterService extends UntilDestroyedMixin {
readonly query = new IanCenterQuery(this.store, this.ianService);
- activeFacet$ = this.query.select('activeFacet');
-
- notLoaded$ = this.query.select('notLoaded');
-
- paramsChanges$ = this
- .query
- .select(['params', 'activeFacet']);
-
- selectNotifications$ = this
- .paramsChanges$
- .pipe(
- switchMap(() => selectCollectionEntities$<InAppNotification>(this.ianService, this.params)),
- tap((notifications) => this.sideLoadInvolvedWorkPackages(notifications)),
- );
-
- aggregatedCenterNotifications$ = this
- .selectNotifications$
- .pipe(
- map((notifications) => (
- _.groupBy(notifications, (notification) => notification._links.resource?.href || 'none')
- )),
- );
-
constructor(
readonly injector:Injector,
readonly ianService:InAppNotificationsService,
@@ -89,7 +59,7 @@ export class IanCenterService extends UntilDestroyedMixin {
}
markAllAsRead():void {
- selectCollection$(this.ianService, this.params)
+ selectCollectionAsHrefs$(this.ianService, this.query.params)
.pipe(
take(1),
)
@@ -106,7 +76,7 @@ export class IanCenterService extends UntilDestroyedMixin {
if (action.caller === this) {
this
.ianService
- .removeFromCollection(this.params, action.notifications);
+ .removeFromCollection(this.query.params, action.notifications);
} else {
this.reload();
}
@@ -114,8 +84,10 @@ export class IanCenterService extends UntilDestroyedMixin {
private reload() {
this.ianService
- .fetchNotifications(this.params)
- .subscribe();
+ .fetchNotifications(this.query.params)
+ .subscribe(
+ (results) => this.sideLoadInvolvedWorkPackages(results._embedded.elements),
+ );
}
private sideLoadInvolvedWorkPackages(elements:InAppNotification[]):void {
@@ -140,9 +112,4 @@ export class IanCenterService extends UntilDestroyedMixin {
);
});
}
-
- private get params():Apiv3ListParameters {
- const state = this.store.getValue();
- return { ...state.params, filters: IAN_FACET_FILTERS[state.activeFacet] };
- }
}
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.ts
index d2ed3be2f65..88b552d19d2 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.activeFacet$;
+ activeFacet$ = this.storeService.query.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.ts
index 25a05871709..cc222448298 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
@@ -130,6 +130,7 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implements
protected 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.ts
index 5ca6e08c746..3bad49dd213 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.selectNotificationsCount$;
+ return storeService.query.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.ts
index a4903569fb0..7f95ccc6a73 100644
--- 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.ts
@@ -1,6 +1,46 @@
import { Query } from '@datorama/akita';
-import { WpSingleViewState } from './wp-single-view.store';
+import {
+ WpSingleViewState,
+ WpSingleViewStore,
+} from './wp-single-view.store';
+import {
+ filter,
+ map,
+ switchMap,
+} 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 { InAppNotificationsService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
+import { Apiv3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
export class WpSingleViewQuery extends Query<WpSingleViewState> {
+ selectNotifications$ = this
+ .select((state) => state.notifications.filters)
+ .pipe(
+ filter((filters) => filters.length > 0),
+ switchMap((filters) => selectCollectionAsEntities$<InAppNotification>(this.ianService, { 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 ianService:InAppNotificationsService,
+ ) {
+ 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.ts
index 48f00075ccf..8bcb0a0ec03 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,20 +1,8 @@
-import {
- Injectable,
- Injector,
-} from '@angular/core';
+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 {
- selectCollection$,
- selectCollectionEntities$,
-} from 'core-app/core/state/collection-store.type';
-import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';
+import { take } from 'rxjs/operators';
+import { selectCollectionAsHrefs$ } from 'core-app/core/state/collection-store';
import { InAppNotificationsService } 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 {
@@ -35,32 +23,11 @@ export class WpSingleViewService extends UntilDestroyedMixin {
protected store = new WpSingleViewStore();
- readonly query = new WpSingleViewQuery(this.store);
-
- selectNotifications$ = this
- .query
- .select((state) => state.notifications.filters)
- .pipe(
- filter((filters) => filters.length > 0),
- switchMap((filters) => selectCollectionEntities$<InAppNotification>(this.ianService, { filters })),
- );
-
- selectNotificationsCount$ = this
- .selectNotifications$
- .pipe(
- map((notifications) => notifications.length),
- );
-
- hasNotifications$ = this
- .selectNotificationsCount$
- .pipe(
- map((count) => count > 0),
- );
+ readonly query = new WpSingleViewQuery(this.store, this.ianService);
constructor(
- readonly injector:Injector,
+ readonly actions$:ActionsService,
private ianService:InAppNotificationsService,
- private actions$:ActionsService,
) {
super();
}
@@ -81,11 +48,11 @@ export class WpSingleViewService extends UntilDestroyedMixin {
}
));
- this.reload(filters);
+ this.reload();
}
markAllAsRead():void {
- selectCollection$(this.ianService, { filters: this.store.getValue().notifications.filters })
+ selectCollectionAsHrefs$(this.ianService, { filters: this.store.getValue().notifications.filters })
.pipe(
take(1),
)
@@ -96,10 +63,10 @@ export class WpSingleViewService extends UntilDestroyedMixin {
});
}
- private reload(filters:ApiV3ListFilter[]) {
+ private reload() {
this
.ianService
- .fetchNotifications({ filters })
+ .fetchNotifications(this.query.params)
.subscribe();
}
@@ -108,7 +75,6 @@ export class WpSingleViewService extends UntilDestroyedMixin {
*/
@EffectCallback(notificationsMarkedRead)
private reloadOnNotificationRead() {
- const { filters } = this.store.getValue().notifications;
- this.reload(filters);
+ this.reload();
}
}
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.ts
index ef397459392..0f492da254d 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
@@ -102,8 +102,6 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
* Needs to be run explicitly by descendants.
*/
protected observeWorkPackage() {
- /** Require the work package once to ensure we're displaying errors */
- let initialized = false;
this
.apiV3Service
.work_packages
@@ -113,11 +111,13 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
this.untilDestroyed(),
)
.subscribe((wp:WorkPackageResource) => {
- this.workPackage = wp;
- if (!initialized) {
+ if (!this.workPackage) {
+ this.workPackage = wp;
this.init();
- initialized = true;
+ } else {
+ this.workPackage = wp;
}
+
this.cdRef.detectChanges();
},
(error) => this.notificationService.handleRawError(error));
@@ -148,7 +148,7 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
this.cdRef.detectChanges();
});
- this.displayNotificationsButton$ = this.storeService.hasNotifications$;
+ this.displayNotificationsButton$ = this.storeService.query.hasNotifications$;
this.storeService.setFilters(this.workPackage.id as string);
// Set authorisation data