Skip to content

Commit

Permalink
Merge pull request #5534 from sarvaiyanidhi/display-assigned-volunteer
Browse files Browse the repository at this point in the history
Display Volunteer name next to Case Number
  • Loading branch information
compwron authored Apr 14, 2024
2 parents cf332dc + 27ea13b commit 9fade37
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 7 deletions.
9 changes: 9 additions & 0 deletions app/components/assigned_volunteers_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% unless @current_user.volunteer? %>
<span class="badge badge-pill light-bg text-black fs-6 fw-medium">
<% if @casa_case.assigned_volunteers.present? %>
<%= @casa_case.assigned_volunteers.map(&:display_name).join(", ") %>
<% else %>
Unassigned
<% end %>
</span>
<% end %>
6 changes: 6 additions & 0 deletions app/components/assigned_volunteers_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AssignedVolunteersComponent < ViewComponent::Base
def initialize(casa_case, current_user)
@casa_case = casa_case
@current_user = current_user
end
end
4 changes: 2 additions & 2 deletions app/helpers/ui_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ def grouped_options_for_assigning_case(volunteer)
CasaCase
.not_assigned(@volunteer.casa_org).active
.uniq { |casa_case| casa_case.case_number }
.map { |casa_case| [casa_case.case_number, casa_case.id] }
.map { |casa_case| ["#{casa_case.case_number} - #{render AssignedVolunteersComponent.new(casa_case, current_user)}".html_safe, casa_case.id] }
],
[
"Assigned",
CasaCase
.actively_assigned_excluding_volunteer(@volunteer)
.uniq { |casa_case| casa_case.case_number }
.map { |casa_case| [casa_case.case_number, casa_case.id] }
.map { |casa_case| ["#{casa_case.case_number} - #{render AssignedVolunteersComponent.new(casa_case, current_user)}".html_safe, casa_case.id] }
]
]
end
Expand Down
5 changes: 3 additions & 2 deletions app/views/casa_cases/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
<tbody>
<% @casa_cases.each do |casa_case| %>
<tr class="<%= casa_case.decorate.inactive_class %>">
<td class="min-width"><%= link_to(casa_case.case_number, casa_case) %></td>
<td class="min-width"><%= link_to(casa_case.case_number, casa_case) %>
</td>
<td class="min-width"><%= casa_case.hearing_type_name %></td>
<td class="min-width"><%= casa_case.judge_name %></td>
<td class="min-width"><%= casa_case.decorate.status %></td>
Expand All @@ -93,7 +94,7 @@
<% end %>
</td>
<% end %>
<td>
<td class="min-width">
<i class="lni lni-pencil-alt text-danger"></i>
<%= link_to "Edit", edit_casa_case_path(casa_case), class: 'text-danger' %>
</td>
Expand Down
4 changes: 3 additions & 1 deletion app/views/casa_cases/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class: "btn btn-primary pull-left casa-case-button") %>
<%= render "inactive_case", casa_case: @casa_case %>
<% end %>
<p>
<h6><strong>Case number:</strong> <%= @casa_case.case_number %></h6>
<h6><strong>Case number:</strong> <%= @casa_case.case_number %>
<%= render AssignedVolunteersComponent.new(@casa_case, current_user) %>
</h6>
</p>
<% if @casa_case.hearing_type %>
<p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/case_groups/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<%= form.label :casa_case_ids, 'Cases' %>
<%= form.select(
:casa_case_ids,
current_organization.casa_cases.pluck(:case_number, :id),
current_organization.casa_cases.map { |casa_case| [sanitize("#{casa_case.case_number} - #{render AssignedVolunteersComponent.new(casa_case, current_user) }"), casa_case.id] },
{ include_hidden: false, autocomplete: "off" },
{ class: "form-control", multiple: true,
data: { "multiple-select-target": "select" }
Expand Down
1 change: 1 addition & 0 deletions app/views/case_groups/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<% case_group.casa_cases.each do |casa_case| %>
<li>
<%= link_to casa_case.case_number, casa_case_path(casa_case) %>
<%= render AssignedVolunteersComponent.new(casa_case, current_user) %>
</li>
<% end %>
</ul>
Expand Down
5 changes: 4 additions & 1 deletion app/views/volunteers/_manage_cases.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
<tbody>
<% @volunteer.case_assignments_with_cases.each do |assignment| %>
<tr id="<%= dom_id(assignment) %>">
<td><%= link_to assignment.casa_case.case_number, casa_case_path(assignment.casa_case) %></td>
<td>
<%= link_to assignment.casa_case.case_number, casa_case_path(assignment.casa_case) %>
<%= render AssignedVolunteersComponent.new(assignment.casa_case, current_user) %>
</td>
<td><%= assignment.casa_case.decorate.transition_aged_youth %></td>
<td>
<% if @volunteer.active? && assignment.casa_case.active? && assignment.active? %>
Expand Down
38 changes: 38 additions & 0 deletions spec/components/assigned_volunteers_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe AssignedVolunteersComponent, type: :component do
let(:casa_case) { create(:casa_case) }
let(:current_user) { create(:user) }

context "when user is not a volunteer" do
it "renders assigned volunteers" do
volunteer = create(:volunteer)
casa_case.volunteers << volunteer

component = described_class.new(casa_case, current_user)
render_inline(component)

expect(page).to have_selector("span.badge", text: volunteer.display_name)
end

it "renders 'Unassigned' when no volunteers present" do
component = described_class.new(casa_case, current_user)
render_inline(component)

expect(page).to have_selector("span.badge", text: "Unassigned")
end
end

context "when user is a volunteer" do
let(:current_user) { create(:volunteer) }

it "does not render badge" do
component = described_class.new(casa_case, current_user)
render_inline(component)

expect(page).not_to have_selector("span.badge")
end
end
end
2 changes: 2 additions & 0 deletions spec/helpers/ui_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
before(:each) do
@casa_cases = create_list(:casa_case, 4)
@volunteer = create(:volunteer, casa_org: @casa_cases[0].casa_org)
current_user = create(:supervisor)
allow(helper).to receive(:current_user).and_return(current_user)
end

it "does not render duplicate casa_case" do
Expand Down

0 comments on commit 9fade37

Please sign in to comment.