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

Disable the "Mark all as read" button when there are no active notifications for a given filter

Kabiru Mwenjaf6003c3f2e9c
diff --git a/app/components/notifications/index_sub_header_component.html.erb b/app/components/notifications/index_sub_header_component.html.erb
index d60ba3816d0..90cc56f2287 100644
--- a/app/components/notifications/index_sub_header_component.html.erb
+++ b/app/components/notifications/index_sub_header_component.html.erb
@@ -23,7 +23,9 @@
href: mark_all_read_notifications_path(**current_filters),
data: { method: :post, confirm: I18n.t("js.notifications.center.mark_all_read_confirmation") },
size: :medium,
- aria: { label: I18n.t("js.notifications.center.mark_all_read") }
+ aria: { label: I18n.t("js.notifications.center.mark_all_read") },
+ disabled: !unread_notifications?,
+ test_selector: "mark-all-as-read-button"
) do |button|
button.with_leading_visual_icon(icon: :"op-read-all")
I18n.t("js.notifications.center.mark_all_read")
diff --git a/app/components/notifications/index_sub_header_component.rb b/app/components/notifications/index_sub_header_component.rb
index 6ee231797e4..62fce59d8a1 100644
--- a/app/components/notifications/index_sub_header_component.rb
+++ b/app/components/notifications/index_sub_header_component.rb
@@ -45,5 +45,25 @@ module Notifications
def current_filters
@current_filters ||= { filter: @filter_type, name: @filter_name }.compact
end
+
+ def unread_notifications?
+ unread_notifications_query.valid? && unread_notifications_query.results.any?
+ end
+
+ private
+
+ def unread_notifications_query
+ @unread_notifications_query ||= Queries::Notifications::NotificationQuery.new(user: User.current).tap do |query|
+ query.where(:read_ian, "=", "f")
+
+ case filter_type
+ when "project"
+ id = filter_name.to_i
+ query.where(:project_id, "=", [id])
+ when "reason"
+ query.where(:reason, "=", [filter_name])
+ end
+ end
+ end
end
end
diff --git a/spec/features/notifications/notification_center/notification_center_spec.rb b/spec/features/notifications/notification_center/notification_center_spec.rb
index 7fbae2d99a6..ea44eaf4759 100644
--- a/spec/features/notifications/notification_center/notification_center_spec.rb
+++ b/spec/features/notifications/notification_center/notification_center_spec.rb
@@ -152,6 +152,7 @@ RSpec.describe "Notification center",
wait_for_network_idle
center.expect_bell_count 0
+ center.expect_mark_all_as_read_button_disabled
side_menu.expect_item_with_no_count "Inbox"
side_menu.expect_item_with_no_count "Mentioned"
side_menu.expect_item_with_no_count "Watcher"
diff --git a/spec/support/pages/notifications/center.rb b/spec/support/pages/notifications/center.rb
index daa322262be..02a6801ac78 100644
--- a/spec/support/pages/notifications/center.rb
+++ b/spec/support/pages/notifications/center.rb
@@ -140,6 +140,10 @@ module Pages
end
end
+ def expect_mark_all_as_read_button_disabled
+ expect(page).to have_css('[data-test-selector="mark-all-as-read-button"][disabled]', text: "Mark all as read")
+ end
+
def bell_element
page.find('opce-in-app-notification-bell [data-test-selector="op-ian-bell"]')
end