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
Trigger changes of the notifications$ Observable when the data has changed (e.g a notification is marked as read) and not only when the route changes. Further we track the index of the currently selected WP in the (aggregated) notifications array. Thus we know which one to open when a notification is read and thus removed from the array.
Henriette Darge2388dc474555
diff --git a/frontend/src/app/core/state/collection-store.ts b/frontend/src/app/core/state/collection-store.tsindex 3a7a8178613..d837c152255 100644--- a/frontend/src/app/core/state/collection-store.ts+++ b/frontend/src/app/core/state/collection-store.ts@@ -70,22 +70,15 @@ export function selectCollectionAsHrefs$<T extends CollectionItem>(service:Colle* 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):Observable<T[]> {+export function selectCollectionAsEntities$<T extends CollectionItem>(service:CollectionService<T>, state:CollectionState<T>, params:Apiv3ListParameters):T[] {const key = collectionKey(params);+ const collection = state.collections[key];+ const ids = collection?.ids || [];- return service- .query- .select()- .pipe(- map((state) => {- const collection = state.collections[key];- const ids = collection?.ids || [];-- return ids- .map((id) => service.query.getEntity(id))- .filter((item) => !!item) as T[];- }),- );+ return ids+ .map((id:string) => service.query.getEntity(id))+ .filter((item) => !!item) as T[];}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 674b1ab4cbb..f887ffcd0f5 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@@ -7,21 +7,14 @@ import {} from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';import {- distinctUntilChanged,filter,map,- pluck,- share,} from 'rxjs/operators';-import { StateService } from '@uirouter/angular';-import { UIRouterGlobals } from '@uirouter/core';import { IanCenterService } from 'core-app/features/in-app-notifications/center/state/ian-center.service';import {InAppNotification,NOTIFICATIONS_MAX_SIZE,} from 'core-app/core/state/in-app-notifications/in-app-notification.model';-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';-import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';@Component({selector: 'op-in-app-notification-center',@@ -29,7 +22,7 @@ import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';styleUrls: ['./in-app-notification-center.component.sass'],changeDetection: ChangeDetectionStrategy.OnPush,})-export class InAppNotificationCenterComponent extends UntilDestroyedMixin implements OnInit {+export class InAppNotificationCenterComponent implements OnInit {maxSize = NOTIFICATIONS_MAX_SIZE;hasMoreThanPageSize$ = this.storeService.query.hasMoreThanPageSize$;@@ -60,13 +53,7 @@ export class InAppNotificationCenterComponent extends UntilDestroyedMixin implem)),);- stateChanged$ = this.uiRouterGlobals.params$?.pipe(- this.untilDestroyed(),- pluck('workPackageId'),- distinctUntilChanged(),- map((workPackageId:string) => (workPackageId ? this.apiV3.work_packages.id(workPackageId).path : undefined)),- share(),- );+ stateChanged$ = this.storeService.stateChanged$;originalOrder = ():number => 0;@@ -83,18 +70,12 @@ export class InAppNotificationCenterComponent extends UntilDestroyedMixin implem},};- selectedNotification:InAppNotification|undefined;-constructor(readonly cdRef:ChangeDetectorRef,readonly elementRef:ElementRef,readonly I18n:I18nService,readonly storeService:IanCenterService,- readonly uiRouterGlobals:UIRouterGlobals,- readonly state:StateService,- readonly apiV3:APIV3Service,) {- super();}ngOnInit():void {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.tsindex 8bb6a6feee5..7b4dc0d4977 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@@ -7,8 +7,8 @@ import {import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';import {map,- switchMap,} from 'rxjs/operators';+import { combineLatest } from 'rxjs';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';@@ -20,11 +20,12 @@ export class IanCenterQuery extends Query<IanCenterState> {paramsChanges$ = this.select(['params', 'activeFacet']);- selectNotifications$ = this- .paramsChanges$- .pipe(- switchMap(() => selectCollectionAsEntities$<InAppNotification>(this.resourceService, this.params)),- );+ selectNotifications$ = combineLatest([+ this.paramsChanges$,+ this.resourceService.query.select(),+ ]).pipe(+ map(([, state]) => selectCollectionAsEntities$<InAppNotification>(this.resourceService, state, this.params)),+ );aggregatedCenterNotifications$ = this.selectNotifications$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 bc44a5fa598..7bd2d92fc50 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@@ -7,9 +7,13 @@ import {InAppNotificationFacet,} from './ian-center.store';import {+ distinctUntilChanged,map,+ pluck,+ share,switchMap,take,+ tap,} from 'rxjs/operators';import {markNotificationsAsRead,@@ -32,11 +36,13 @@ import { from } from 'rxjs';import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';import { selectCollectionAsHrefs$ } from 'core-app/core/state/collection-store';import { StateService } from '@uirouter/angular';-import { BackRouteOptions } from 'core-app/features/work-packages/components/back-routing/back-routing.service';+import idFromLink from 'core-app/features/hal/helpers/id-from-link';+import { UIRouterGlobals } from '@uirouter/core';+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';@Injectable()@EffectHandler-export class IanCenterService {+export class IanCenterService extends UntilDestroyedMixin {readonly id = 'ian-center';readonly store = new IanCenterStore();@@ -45,13 +51,24 @@ export class IanCenterService {public selectedNotificationIndex = 0;+ stateChanged$ = this.uiRouterGlobals.params$?.pipe(+ this.untilDestroyed(),+ pluck('workPackageId'),+ distinctUntilChanged(),+ tap(() => this.updateSelectedNotificationIndex()),+ map((workPackageId:string) => (workPackageId ? this.apiV3Service.work_packages.id(workPackageId).path : undefined)),+ share(),+ );+constructor(readonly injector:Injector,readonly resourceService:InAppNotificationsResourceService,readonly actions$:ActionsService,readonly apiV3Service:APIV3Service,+ readonly uiRouterGlobals:UIRouterGlobals,readonly state:StateService,) {+ super();}setFacet(facet:InAppNotificationFacet):void {@@ -75,14 +92,38 @@ export class IanCenterService {});}+ openSplitScreen(wpId:string|null):void {+ void this.state.go(+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access+ `${(this.state.current.data).baseRoute}.details.tabs`,+ { workPackageId: wpId, tabIdentifier: 'activity' },+ );+ }+/*** Reload after notifications were successfully marked as read*/@EffectCallback(notificationsMarkedRead)private reloadOnNotificationRead(action:ReturnType<typeof notificationsMarkedRead>) {- this.beforeReloadNotifications(action.notifications[0]);- this.resourceService.removeFromCollection(this.query.params, action.notifications);- this.afterReloadNotifications(this.selectedNotificationIndex);+ if (action.origin === this.id) {+ this+ .resourceService+ .removeFromCollection(this.query.params, action.notifications);++ this+ .query+ .notifications$+ .pipe(+ take(1),+ ).subscribe((notifications) => {+ if (notifications[this.selectedNotificationIndex][0]._links.resource) {+ const wpId = idFromLink(notifications[this.selectedNotificationIndex][0]._links.resource!.href);+ this.openSplitScreen(wpId);+ }+ });+ } else {+ this.reload();+ }}private reload() {@@ -120,49 +161,20 @@ export class IanCenterService {return promise;}- private afterReloadNotifications(notificationIndex:number) {- if (window.location.href.indexOf('details') <= -1) {- return;- }- this.query.notifications$.pipe(take(1)).subscribe((notifications) => {- if (notifications.length <= 0) {- void this.state.go(- `${(this.state.current.data as BackRouteOptions).baseRoute}`,- );- } else {- const index = notificationIndex > notifications.length ? 0 : notificationIndex - 1;- const href = notifications[index][0]._links.resource?.href;- const id = href && HalResource.matchFromLink(href, 'work_packages');- if (id) {- const wp = this- .apiV3Service- .work_packages- .id(id)- .requireAndStream();-- wp.pipe(take(1))- .subscribe((workPackage) => {- void this.state.go(- `${(this.state.current.data as BackRouteOptions).baseRoute}.details.tabs`,- { workPackageId: workPackage.id, tabIdentifier: 'activity' },- );- });- }- }- });- }-- private beforeReloadNotifications(notificationID:string | number) {- this.query.notifications$.pipe().subscribe((wpNotifications) => {- let counter = 0;- wpNotifications.forEach((wpNotification) => {- counter += 1;- wpNotification.forEach((notification) => {- if (notification.id === notificationID) {- this.selectedNotificationIndex = counter;+ private updateSelectedNotificationIndex() {+ this+ .query+ .notifications$+ .pipe(+ take(1),+ ).subscribe((notifications) => {+ 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) {// eslint-disable-line @typescript-eslint/no-non-null-assertion+ this.selectedNotificationIndex = i;+ return;}- });+ }});- });}}diff --git a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.tsindex 5af620a4f02..e4dd66dec9e 100644--- a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts+++ b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts@@ -145,10 +145,7 @@ export class InAppNotificationEntryComponent implements OnInit {take(1),).subscribe((wp) => {- void this.state.go(- `${(this.state.current.data as BackRouteOptions).baseRoute}.details.tabs`,- { workPackageId: wp.id, tabIdentifier: 'activity' },- );+ this.storeService.openSplitScreen(wp.id);});}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.tsindex 09dfcefd849..856be080250 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@@ -6,20 +6,21 @@ import {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 { 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$ = this- .select((state) => state.notifications.filters)- .pipe(- filter((filters) => filters.length > 0),- switchMap((filters) => selectCollectionAsEntities$<InAppNotification>(this.resourceService, { filters })),- );+ selectNotifications$ = combineLatest([+ this.select((state) => state.notifications.filters),+ this.resourceService.query.select(),+ ]).pipe(+ filter((filters) => filters.length > 0),+ map(([filters, state]) => selectCollectionAsEntities$<InAppNotification>(this.resourceService, state, { filters })),+ );selectNotificationsCount$ = this.selectNotifications$