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

[39506] use shareReplay to ensure notification selected on load (#9801)

Oliver Günther6ec73cafc998
diff --git a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html
index 8ee520dd9cf..600c1d04443 100644
--- a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html
+++ b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html
@@ -20,6 +20,7 @@
[aggregatedNotifications]="records"
attr.data-qa-selector="op-ian-notification-item-{{records[0].id}}"
[attr.data-qa-ian-read]="records[0].readIAN === true || undefined"
+ [attr.data-qa-ian-selected]="(stateChanged$ | async) === records[0]._links.resource.href"
></op-in-app-notification-entry>
</cdk-virtual-scroll-viewport>
</ng-container>
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 3752729f0fd..ef0b4e5c6e3 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,16 +3,19 @@ import {
Injector,
} from '@angular/core';
import {
+ debounceTime,
distinctUntilChanged,
map,
mapTo,
pluck,
- share,
+ shareReplay,
switchMap,
take,
- debounceTime,
} from 'rxjs/operators';
-import { Subject, from } from 'rxjs';
+import {
+ from,
+ Subject,
+} from 'rxjs';
import {
ID,
setLoading,
@@ -20,10 +23,10 @@ import {
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import {
+ centerUpdatedInPlace,
markNotificationsAsRead,
- notificationsMarkedRead,
notificationCountIncreased,
- centerUpdatedInPlace,
+ 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';
@@ -35,7 +38,10 @@ 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 { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
-import { mapHALCollectionToIDCollection, selectCollectionAsHrefs$ } from 'core-app/core/state/collection-store';
+import {
+ mapHALCollectionToIDCollection,
+ selectCollectionAsHrefs$,
+} from 'core-app/core/state/collection-store';
import { INotificationPageQueryParameters } from 'core-app/features/in-app-notifications/in-app-notifications.routes';
import {
IanCenterStore,
@@ -80,7 +86,7 @@ export class IanCenterService extends UntilDestroyedMixin {
pluck('workPackageId'),
distinctUntilChanged(),
map((workPackageId:string) => (workPackageId ? this.apiV3Service.work_packages.id(workPackageId).path : undefined)),
- share(),
+ shareReplay(),
);
constructor(
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.ts
index 6e2f030469c..65268dc30c3 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
@@ -24,7 +24,6 @@ import { PathHelperService } from 'core-app/core/path-helper/path-helper.service
import { take } from 'rxjs/internal/operators/take';
import { StateService } from '@uirouter/angular';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
-import { BackRouteOptions } from 'core-app/features/work-packages/components/back-routing/back-routing.service';
import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';
import { IanCenterService } from 'core-app/features/in-app-notifications/center/state/ian-center.service';
import { DeviceService } from 'core-app/core/browser/device.service';
@@ -47,6 +46,8 @@ export class InAppNotificationEntryComponent implements OnInit {
loading$ = this.storeService.query.selectLoading();
+ stateChanged$ = this.storeService.stateChanged$;
+
// The actor, if any
actors:PrincipalLike[] = [];
diff --git a/spec/features/notifications/navigation_spec.rb b/spec/features/notifications/navigation_spec.rb
index 3380f5d6ddc..df9f9f9ddb8 100644
--- a/spec/features/notifications/navigation_spec.rb
+++ b/spec/features/notifications/navigation_spec.rb
@@ -97,4 +97,14 @@ describe "Notification center navigation", type: :feature, js: true do
split_screen.expect_empty_state
end
+
+ it 'deep linking to a notification details highlights it' do
+ visit "/notifications/details/#{work_package.id}"
+
+ expect(page).to have_current_path "/notifications/details/#{work_package.id}/overview"
+
+ split_screen.expect_open
+
+ center.expect_item_selected notification
+ end
end
diff --git a/spec/support/pages/notifications/center.rb b/spec/support/pages/notifications/center.rb
index 1b54d1d594c..024432b62c0 100644
--- a/spec/support/pages/notifications/center.rb
+++ b/spec/support/pages/notifications/center.rb
@@ -92,6 +92,11 @@ module Pages
.not_to have_selector("[data-qa-selector='op-ian-notification-item-#{notification.id}'][data-qa-ian-read]")
end
+ def expect_item_selected(notification)
+ expect(page)
+ .to have_selector("[data-qa-selector='op-ian-notification-item-#{notification.id}'][data-qa-ian-selected]")
+ end
+
def expect_work_package_item(*notifications)
notifications.each do |notification|
work_package = notification.resource