Skip to content

Commit

Permalink
Replace submitted note table color with created/resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Oct 19, 2024
1 parent 6d0c291 commit 7aeafbd
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 10 deletions.
8 changes: 7 additions & 1 deletion app/assets/stylesheets/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ time[title] {
.table-success {
--bs-table-bg: rgb(var(--bs-success-rgb), .25);
}
.table-primary, .table-secondary, .table-success {
.table-warning {
--bs-table-bg: rgb(var(--bs-warning-rgb), .25);
}
.table-danger {
--bs-table-bg: rgb(var(--bs-danger-rgb), .25);
}
.table-primary, .table-secondary, .table-success, .table-warning, .table-danger {
--bs-table-color: initial;
border-color: inherit;
}
Expand Down
22 changes: 16 additions & 6 deletions app/views/notes/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<% content_for :heading do %>
<h1><%= t ".heading", :user => @user.display_name %></h1>
<p><%= t ".subheading_html",
:user => link_to(@user.display_name, @user),
:submitted => tag.span(t(".subheading_submitted"), :class => "px-2 py-1 bg-primary bg-opacity-25"),
:commented => tag.span(t(".subheading_commented"), :class => "px-2 py-1 bg-body") %></p>
<p class="lh-lg"><%= t ".legend_html",
:user => link_to(@user.display_name, @user),
:created => tag.span(t(".legend_created"), :class => "px-2 py-1 bg-danger bg-opacity-25"),
:created_and_resolved => tag.span(t(".legend_created_and_resolved"), :class => "px-2 py-1 bg-warning bg-opacity-25"),
:resolved => tag.span(t(".legend_resolved"), :class => "px-2 py-1 bg-success bg-opacity-25"),
:interacted => tag.span(t(".legend_interacted"), :class => "px-2 py-1 bg-body") %></p>
<% end %>

<% if @notes.empty? %>
Expand All @@ -24,7 +26,15 @@
</tr>
</thead>
<% @notes.each do |note| -%>
<tr<% if note.author == @user %> class="table-primary"<% end %>>
<% opened_by_user = note.author == @user %>
<% closed_by_user = note.comments.last&.author == @user && note.comments.last&.event == "closed" %>
<%= tag.tr :class => if opened_by_user && closed_by_user
"table-warning"
elsif opened_by_user
"table-danger"
elsif closed_by_user
"table-success"
end do %>
<td>
<% if note.closed? %>
<%= image_tag("closed_note_marker.svg", :alt => "closed", :width => 25, :height => 40) %>
Expand All @@ -37,7 +47,7 @@
<td><%= note.comments.first.body.to_html %></td>
<td><%= friendly_date_ago(note.created_at) %></td>
<td><%= friendly_date_ago(note.updated_at) %></td>
</tr>
<% end %>
<% end -%>
</table>

Expand Down
8 changes: 5 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2957,9 +2957,11 @@ en:
index:
title: "Notes submitted or commented on by %{user}"
heading: "%{user}'s Notes"
subheading_html: "Notes %{submitted} or %{commented} by %{user}"
subheading_submitted: "submitted"
subheading_commented: "commented on"
legend_html: "Notes %{created}, %{created_and_resolved}, %{resolved} or %{interacted} by %{user}"
legend_created: "created"
legend_created_and_resolved: "created and resolved"
legend_resolved: "resolved"
legend_interacted: "with other interactions"
no_notes: No notes
id: "Id"
creator: "Creator"
Expand Down
63 changes: 63 additions & 0 deletions test/controllers/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,69 @@ def test_index_success
assert_response :not_found
end

def test_index_interaction_created
user = create(:user)
create(:note) do |note|
create(:note_comment, :note => note, :author => user)
end

get user_notes_path(user)
assert_response :success
assert_dom "table.note_list tbody tr.table-danger:not(.table-warning):not(.table-success)", :count => 1
end

def test_index_interaction_created_and_resolved
user = create(:user)
create(:note) do |note|
create(:note_comment, :note => note, :author => user)
create(:note_comment, :note => note, :author => user, :event => "closed")
end

get user_notes_path(user)
assert_response :success
assert_dom "table.note_list tbody tr:not(.table-danger).table-warning:not(.table-success)", :count => 1
end

def test_index_interaction_resolved
user = create(:user)
other_user = create(:user)
create(:note) do |note|
create(:note_comment, :note => note, :author => other_user)
create(:note_comment, :note => note, :author => user, :event => "closed")
end

get user_notes_path(user)
assert_response :success
assert_dom "table.note_list tbody tr:not(.table-danger):not(.table-warning).table-success", :count => 1
end

def test_index_interaction_resolved_and_reopened_by_other_user
user = create(:user)
other_user = create(:user)
create(:note) do |note|
create(:note_comment, :note => note, :author => other_user)
create(:note_comment, :note => note, :author => user, :event => "closed")
create(:note_comment, :note => note, :author => other_user, :event => "reopened")
end

get user_notes_path(user)
assert_response :success
assert_dom "table.note_list tbody tr:not(.table-danger):not(.table-warning):not(.table-success)", :count => 1
end

def test_index_interaction_commented
user = create(:user)
other_user = create(:user)
create(:note) do |note|
create(:note_comment, :note => note, :author => other_user)
create(:note_comment, :note => note, :author => user, :event => "commented")
end

get user_notes_path(user)
assert_response :success
assert_dom "table.note_list tbody tr:not(.table-danger):not(.table-warning):not(.table-success)", :count => 1
end

def test_index_paged
user = create(:user)

Expand Down

0 comments on commit 7aeafbd

Please sign in to comment.