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

Show number of unread notifications next to the "Inbox" entry

Henriette Darge4073413c36de
diff --git a/frontend/src/app/features/in-app-notifications/center/menu/menu.component.ts b/frontend/src/app/features/in-app-notifications/center/menu/menu.component.ts
index cf7d22db5b3..671465d34c6 100644
--- a/frontend/src/app/features/in-app-notifications/center/menu/menu.component.ts
+++ b/frontend/src/app/features/in-app-notifications/center/menu/menu.component.ts
@@ -24,6 +24,7 @@ export const ianMenuSelector = 'op-ian-menu';
export class IanMenuComponent implements OnInit {
baseMenuItems = [
{
+ key: 'inbox',
title: this.I18n.t('js.notifications.menu.inbox'),
icon: 'inbox',
href: this.getHrefForFilters({}),
@@ -57,6 +58,13 @@ export class IanMenuComponent implements OnInit {
},
];
+ baseMenuItemNotifications$ = this.ianMenuService.query.baseMenuItemNotifications$.pipe(
+ map((items) => this.baseMenuItems.map((baseItem) => ({
+ ...items.find((item) => item.value === baseItem.key),
+ ...baseItem,
+ }))),
+ );
+
notificationsByProject$ = this.ianMenuService.query.notificationsByProject$.pipe(
map((items) => items
.map((item) => ({
@@ -81,11 +89,12 @@ export class IanMenuComponent implements OnInit {
);
menuItems$ = combineLatest([
+ this.baseMenuItemNotifications$,
this.notificationsByProject$,
this.notificationsByReason$,
]).pipe(
- map(([byProject, byReason]) => [
- ...this.baseMenuItems,
+ map(([baseMenu, byProject, byReason]) => [
+ ...baseMenu,
{
title: this.I18n.t('js.notifications.menu.by_reason'),
collapsible: true,
diff --git a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.query.ts b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.query.ts
index c32f60f1f88..413bc8b87d6 100644
--- a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.query.ts
+++ b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.query.ts
@@ -44,6 +44,8 @@ export class IanMenuQuery extends Query<IanMenuState> {
notificationsByReason$ = this.select('notificationsByReason');
+ baseMenuItemNotifications$ = this.select('baseMenuItemNotifications');
+
constructor(
protected store:IanMenuStore,
protected resourceService:InAppNotificationsResourceService,
diff --git a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.service.ts b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.service.ts
index 5d745130f1a..00256b1ff4d 100644
--- a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.service.ts
+++ b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.service.ts
@@ -18,6 +18,7 @@ import {
IanMenuStore,
IAN_MENU_PROJECT_FILTERS,
IAN_MENU_REASON_FILTERS,
+ IAN_MENU_INBOX_FILTER,
} from './ian-menu.store';
@Injectable()
@@ -65,6 +66,11 @@ export class IanMenuService {
this.projectsResourceService.fetchProjects(projectsFilter).subscribe();
});
this.ianResourceService.fetchNotifications(IAN_MENU_REASON_FILTERS)
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
.subscribe((data) => this.store.update({ notificationsByReason: data.groups }));
+
+ this.ianResourceService.fetchNotifications(IAN_MENU_INBOX_FILTER)
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
+ .subscribe((data) => this.store.update({ baseMenuItemNotifications: [{ value: 'inbox', count: data.total }] }));
}
}
diff --git a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.store.ts b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.store.ts
index c1bcfac1798..b49cd9d68e0 100644
--- a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.store.ts
+++ b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.store.ts
@@ -12,7 +12,13 @@ export interface IanMenuGroupingData {
};
}
+export interface BaseMenuItemData {
+ value:string;
+ count:number;
+}
+
export interface IanMenuState {
+ baseMenuItemNotifications:BaseMenuItemData[]
notificationsByProject:IanMenuGroupingData[],
notificationsByReason:IanMenuGroupingData[],
projectsFilter:Apiv3ListParameters,
@@ -30,8 +36,14 @@ export const IAN_MENU_REASON_FILTERS:Apiv3ListParameters = {
filters: [['read_ian', '=', false]],
};
+export const IAN_MENU_INBOX_FILTER:Apiv3ListParameters = {
+ pageSize: 0,
+ filters: [['read_ian', '=', false]],
+};
+
export function createInitialState():IanMenuState {
return {
+ baseMenuItemNotifications: [],
notificationsByProject: [],
notificationsByReason: [],
projectsFilter: {},
diff --git a/frontend/src/app/shared/components/sidemenu/sidemenu.component.html b/frontend/src/app/shared/components/sidemenu/sidemenu.component.html
index da1e6409161..0c3abb7c7d5 100644
--- a/frontend/src/app/shared/components/sidemenu/sidemenu.component.html
+++ b/frontend/src/app/shared/components/sidemenu/sidemenu.component.html
@@ -4,7 +4,7 @@
(click)="toggleCollapsed()"
*ngIf="title && collapsible"
>
- <span class="icon-context icon-small"
+ <span class="icon3 icon-small"
[ngClass]="collapsed ? 'icon-arrow-down1' : 'icon-arrow-up1'"
aria-hidden="true">
</span>
diff --git a/spec/features/notifications/notification_center/notification_center_sidemenu_spec.rb b/spec/features/notifications/notification_center/notification_center_sidemenu_spec.rb
index 72b573fc08b..da4d96df7ea 100644
--- a/spec/features/notifications/notification_center/notification_center_sidemenu_spec.rb
+++ b/spec/features/notifications/notification_center/notification_center_sidemenu_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
-require 'support/components/notifications/center'
-describe "Notification center sidemenu", type: :feature, js: true, with_settings: { journal_aggregation_time_minutes: 0 } do
+describe "Notification center sidemenu", type: :feature, js: true do
shared_let(:project) { FactoryBot.create :project }
shared_let(:project2) { FactoryBot.create :project }
shared_let(:project3) { FactoryBot.create :project, parent: project2 }
@@ -18,7 +17,7 @@ describe "Notification center sidemenu", type: :feature, js: true, with_settings
shared_let(:work_package3) { FactoryBot.create :work_package, project: project3, author: other_user }
shared_let(:work_package4) { FactoryBot.create :work_package, project: project3, author: other_user }
- shared_let(:notification) do
+ let!(:notification) do
FactoryBot.create :notification,
recipient: recipient,
project: project,
@@ -26,7 +25,7 @@ describe "Notification center sidemenu", type: :feature, js: true, with_settings
reason_ian: :watched
end
- shared_let(:notification2) do
+ let!(:notification2) do
FactoryBot.create :notification,
recipient: recipient,
project: project2,
@@ -34,7 +33,7 @@ describe "Notification center sidemenu", type: :feature, js: true, with_settings
reason_ian: :assigned
end
- shared_let(:notification3) do
+ let!(:notification3) do
FactoryBot.create :notification,
recipient: recipient,
project: project3,
@@ -42,7 +41,7 @@ describe "Notification center sidemenu", type: :feature, js: true, with_settings
reason_ian: :responsible
end
- shared_let(:notification4) do
+ let!(:notification4) do
FactoryBot.create :notification,
recipient: recipient,
project: project3,
@@ -87,7 +86,7 @@ describe "Notification center sidemenu", type: :feature, js: true, with_settings
# ... and show only those projects with a notification
side_menu.expect_item_not_visible project.name
side_menu.expect_item_with_count project2.name, 1
- side_menu.expect_item_with_count project3.name, 2
+ side_menu.expect_item_with_count "... #{project3.name}", 2
# Marking all as read
center.mark_all_read
@@ -99,7 +98,7 @@ describe "Notification center sidemenu", type: :feature, js: true, with_settings
side_menu.expect_item_not_visible project.name
side_menu.expect_item_not_visible project2.name
- side_menu.expect_item_not_visible project3.name
+ side_menu.expect_item_not_visible "... #{project3.name}"
end
it 'updates the content when a filter is clicked' do
@@ -108,36 +107,43 @@ describe "Notification center sidemenu", type: :feature, js: true, with_settings
# Filter for "Watching"
side_menu.click_item 'Watching'
+ side_menu.finished_loading
center.expect_work_package_item notification
center.expect_no_item notification2, notification3, notification4
# Filter for "Assignee"
- side_menu.click_item 'Assignee'
+ side_menu.click_item 'Assigned'
+ side_menu.finished_loading
center.expect_work_package_item notification2
center.expect_no_item notification, notification3, notification4
- # Filter for "Responsible"
- side_menu.click_item 'Responsible'
+ # Filter for "Accountable"
+ side_menu.click_item 'Accountable'
+ side_menu.finished_loading
center.expect_work_package_item notification3
center.expect_no_item notification, notification2, notification4
# Filter for "@mentioned"
side_menu.click_item '@mentioned'
+ side_menu.finished_loading
center.expect_work_package_item notification4
center.expect_no_item notification, notification2, notification3
# Filter for project1
side_menu.click_item project.name
+ side_menu.finished_loading
center.expect_work_package_item notification
center.expect_no_item notification2, notification3, notification4
# Filter for project3
- side_menu.click_item project3.name
+ side_menu.click_item "... #{project3.name}"
+ side_menu.finished_loading
center.expect_work_package_item notification3, notification4
center.expect_no_item notification, notification2
# Reset by clicking on the Inbox
side_menu.click_item 'Inbox'
+ side_menu.finished_loading
center.expect_work_package_item notification, notification2, notification3, notification4
end
end
diff --git a/spec/support/components/common/sidemenu.rb b/spec/support/components/common/sidemenu.rb
index 3b036e6e2ba..a04395923fc 100644
--- a/spec/support/components/common/sidemenu.rb
+++ b/spec/support/components/common/sidemenu.rb
@@ -43,21 +43,25 @@ module Components
end
def expect_item_with_count(item, count)
- within "[data-qa-selector='op-sidemenu--item-action--#{item.delete(' ')}']" do
+ within item_action_selector(item) do
expect(page).to have_text item
expect_count(count)
end
end
def expect_item_with_no_count(item)
- within "[data-qa-selector='op-sidemenu--item-action--#{item.delete(' ')}']" do
+ within item_action_selector(item) do
expect(page).to have_text item
expect_no_count
end
end
def click_item(item)
- page.find(item_selector, text: item).click
+ page.find(item_action_selector(item), text: item).click
+ end
+
+ def finished_loading
+ expect(page).to have_no_selector('.op-ian-center--loading-indicator')
end
private
@@ -70,6 +74,10 @@ module Components
expect(page).to have_no_selector('.op-bubble')
end
+ def item_action_selector(item)
+ "[data-qa-selector='op-sidemenu--item-action--#{item.delete(' ')}']"
+ end
+
def item_selector
'[data-qa-selector="op-sidemenu--item"]'
end