Skip to content

Commit

Permalink
Merge pull request openSUSE#16594 from danidoni/fix-the-mark-as-read-…
Browse files Browse the repository at this point in the history
…or-unread-button-in-notification-toolbar

Refactor the notification toolbar helpers to make them simpler
  • Loading branch information
danidoni authored Aug 1, 2024
2 parents 51ac3a6 + 9505839 commit 6887135
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
11 changes: 0 additions & 11 deletions src/api/app/helpers/webui/notification_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ def avatars(notification)

private

def mark_as_read_or_unread_button(notification)
button = notification.unread? ? 'read' : 'unread'
update_path = my_notifications_path(notification_ids: [notification.id], button: button)
title, icon = notification.unread? ? ['Mark as read', 'fa-check'] : ['Mark as unread', 'fa-undo']
link_to(update_path, id: dom_id(notification, :update), method: :put,
class: 'btn btn-sm btn-outline-success', title: title) do
concat(tag.i(class: "#{icon} fas"))
concat(" #{title}")
end
end

def number_of_hidden_avatars(avatar_objects)
[0, avatar_objects.size - MAXIMUM_DISPLAYED_AVATARS].max
end
Expand Down
13 changes: 12 additions & 1 deletion src/api/app/views/layouts/webui/_notification_toolbar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@
= link_to(my_notifications_path, class: 'btn btn-sm btn-outline-secondary', title: 'Back to notifications') do
%i.fas.fa-arrow-left
Back to notifications
= mark_as_read_or_unread_button(notification)
- if notification.unread?
= link_to(my_notifications_path(notification_ids: [notification.id], button: 'read'),
id: dom_id(notification, :update), method: :put,
class: 'btn btn-sm btn-outline-success', title: 'Mark as read') do
%i.fas.fa-check
Mark as read
- else
= link_to(my_notifications_path(notification_ids: [notification.id], button: 'unread'),
id: dom_id(notification, :update), method: :put,
class: 'btn btn-sm btn-outline-success', title: 'Mark as unread') do
%i.fas.fa-undo
Mark as unread
20 changes: 0 additions & 20 deletions src/api/spec/helpers/webui/notification_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
RSpec.describe Webui::NotificationHelper do
describe '#mark_as_read_or_unread_button' do
let(:link) { mark_as_read_or_unread_button(notification) }

context 'for unread notification' do
let(:notification) { create(:notification_for_comment, :web_notification, delivered: false) }

it { expect(link).to include('button=read') }
it { expect(link).to include('Mark as read') }
it { expect(link).to include('fa-check fas') }
end

context 'for read notification' do
let(:notification) { create(:notification_for_comment, :web_notification, delivered: true) }

it { expect(link).to include('button=unread') }
it { expect(link).to include('Mark as unread') }
it { expect(link).to include('fa-undo fas') }
end
end

describe '#truncate_to_first_new_line' do
context 'when the text is nil' do
it { expect(truncate_to_first_new_line(nil)).to eql('') }
Expand Down

0 comments on commit 6887135

Please sign in to comment.