From 42e2c2ca43e28ea41d4b191bf88b668c98a43999 Mon Sep 17 00:00:00 2001 From: Nidhi Sarvaiya Date: Fri, 16 Feb 2024 13:46:38 -0500 Subject: [PATCH 1/5] Display Volunteer name next to Case Number --- .../assigned_volunteers_component.html.erb | 9 +++++ .../assigned_volunteers_component.rb | 6 +++ app/views/casa_cases/index.html.erb | 6 ++- app/views/casa_cases/show.html.erb | 4 +- .../assigned_volunteers_component_spec.rb | 38 +++++++++++++++++++ 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 app/components/assigned_volunteers_component.html.erb create mode 100644 app/components/assigned_volunteers_component.rb create mode 100644 spec/components/assigned_volunteers_component_spec.rb diff --git a/app/components/assigned_volunteers_component.html.erb b/app/components/assigned_volunteers_component.html.erb new file mode 100644 index 0000000000..15e6abf62c --- /dev/null +++ b/app/components/assigned_volunteers_component.html.erb @@ -0,0 +1,9 @@ +<% unless @current_user.volunteer? %> + + <% if @casa_case.assigned_volunteers.present? %> + <%= @casa_case.assigned_volunteers.map(&:display_name).join(", ") %> + <% else %> + Unassigned + <% end %> + +<% end %> diff --git a/app/components/assigned_volunteers_component.rb b/app/components/assigned_volunteers_component.rb new file mode 100644 index 0000000000..2bfe283fef --- /dev/null +++ b/app/components/assigned_volunteers_component.rb @@ -0,0 +1,6 @@ +class AssignedVolunteersComponent < ViewComponent::Base + def initialize(casa_case, current_user) + @casa_case = casa_case + @current_user = current_user + end +end diff --git a/app/views/casa_cases/index.html.erb b/app/views/casa_cases/index.html.erb index 44ebabed36..7b138c0c8d 100644 --- a/app/views/casa_cases/index.html.erb +++ b/app/views/casa_cases/index.html.erb @@ -77,7 +77,9 @@ <% @casa_cases.each do |casa_case| %> - <%= link_to(casa_case.case_number, casa_case) %> + <%= link_to(casa_case.case_number, casa_case) %> + <%= render AssignedVolunteersComponent.new(casa_case, current_user) %> + <%= casa_case.hearing_type_name %> <%= casa_case.judge_name %> <%= casa_case.decorate.status %> @@ -93,7 +95,7 @@ <% end %> <% end %> - + <%= link_to "Edit", edit_casa_case_path(casa_case), class: 'text-danger' %> diff --git a/app/views/casa_cases/show.html.erb b/app/views/casa_cases/show.html.erb index f18c2d1e4d..049aad1e01 100644 --- a/app/views/casa_cases/show.html.erb +++ b/app/views/casa_cases/show.html.erb @@ -43,7 +43,9 @@ class: "btn btn-primary pull-left casa-case-button") %> <%= render "inactive_case", casa_case: @casa_case %> <% end %>

-

Case number: <%= @casa_case.case_number %>
+
Case number: <%= @casa_case.case_number %> + <%= render AssignedVolunteersComponent.new(@casa_case, current_user) %> +

<% if @casa_case.hearing_type %>

diff --git a/spec/components/assigned_volunteers_component_spec.rb b/spec/components/assigned_volunteers_component_spec.rb new file mode 100644 index 0000000000..fa5079dfc9 --- /dev/null +++ b/spec/components/assigned_volunteers_component_spec.rb @@ -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 From e9cb39a9988f20c538648667aed81e0687835bab Mon Sep 17 00:00:00 2001 From: Nidhi Sarvaiya Date: Wed, 21 Feb 2024 22:54:44 -0500 Subject: [PATCH 2/5] Removed Volunteer name displayed next to case number from table view --- app/views/casa_cases/index.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/casa_cases/index.html.erb b/app/views/casa_cases/index.html.erb index 7b138c0c8d..e75fb79924 100644 --- a/app/views/casa_cases/index.html.erb +++ b/app/views/casa_cases/index.html.erb @@ -78,7 +78,6 @@ <% @casa_cases.each do |casa_case| %> <%= link_to(casa_case.case_number, casa_case) %> - <%= render AssignedVolunteersComponent.new(casa_case, current_user) %> <%= casa_case.hearing_type_name %> <%= casa_case.judge_name %> From 39d2073bb25b0190609147730b10d3b9566f3fe9 Mon Sep 17 00:00:00 2001 From: Nidhi Sarvaiya Date: Fri, 23 Feb 2024 23:25:04 -0500 Subject: [PATCH 3/5] Code changes to show volunteer name in case number droplist --- app/helpers/ui_helper.rb | 4 ++-- app/views/case_groups/_form.html.erb | 2 +- app/views/case_groups/index.html.erb | 1 + app/views/volunteers/_manage_cases.erb | 5 ++++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/helpers/ui_helper.rb b/app/helpers/ui_helper.rb index 0cc332eaa4..9573d91d9e 100644 --- a/app/helpers/ui_helper.rb +++ b/app/helpers/ui_helper.rb @@ -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 diff --git a/app/views/case_groups/_form.html.erb b/app/views/case_groups/_form.html.erb index 074eae4486..c0615f7031 100644 --- a/app/views/case_groups/_form.html.erb +++ b/app/views/case_groups/_form.html.erb @@ -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| ["#{casa_case.case_number} - #{render AssignedVolunteersComponent.new(casa_case, current_user) }".html_safe, casa_case.id] }, { include_hidden: false, autocomplete: "off" }, { class: "form-control", multiple: true, data: { "multiple-select-target": "select" } diff --git a/app/views/case_groups/index.html.erb b/app/views/case_groups/index.html.erb index 80817049ef..7c4bd3df90 100644 --- a/app/views/case_groups/index.html.erb +++ b/app/views/case_groups/index.html.erb @@ -42,6 +42,7 @@ <% case_group.casa_cases.each do |casa_case| %>

  • <%= link_to casa_case.case_number, casa_case_path(casa_case) %> + <%= render AssignedVolunteersComponent.new(casa_case, current_user) %>
  • <% end %> diff --git a/app/views/volunteers/_manage_cases.erb b/app/views/volunteers/_manage_cases.erb index 163b1c0fdb..c448921af6 100644 --- a/app/views/volunteers/_manage_cases.erb +++ b/app/views/volunteers/_manage_cases.erb @@ -18,7 +18,10 @@ <% @volunteer.case_assignments_with_cases.each do |assignment| %> - <%= link_to assignment.casa_case.case_number, casa_case_path(assignment.casa_case) %> + + <%= link_to assignment.casa_case.case_number, casa_case_path(assignment.casa_case) %> + <%= render AssignedVolunteersComponent.new(assignment.casa_case, current_user) %> + <%= assignment.casa_case.decorate.transition_aged_youth %> <% if @volunteer.active? && assignment.casa_case.active? && assignment.active? %> From c005a3ec2df413ae3f833e84799ddfc240a7383e Mon Sep 17 00:00:00 2001 From: Nidhi Sarvaiya Date: Fri, 23 Feb 2024 23:59:30 -0500 Subject: [PATCH 4/5] Fixed Spec issue to get current_user --- spec/helpers/ui_helper_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/helpers/ui_helper_spec.rb b/spec/helpers/ui_helper_spec.rb index 3353285402..0fd8798cc1 100644 --- a/spec/helpers/ui_helper_spec.rb +++ b/spec/helpers/ui_helper_spec.rb @@ -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 From 79b7d036b78a0ad89ce060ce6d040ea6c632a016 Mon Sep 17 00:00:00 2001 From: Nidhi Sarvaiya Date: Sat, 24 Feb 2024 23:14:08 -0500 Subject: [PATCH 5/5] Fix ERB lint issue --- app/views/case_groups/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/case_groups/_form.html.erb b/app/views/case_groups/_form.html.erb index c0615f7031..dd746ab37a 100644 --- a/app/views/case_groups/_form.html.erb +++ b/app/views/case_groups/_form.html.erb @@ -26,7 +26,7 @@ <%= form.label :casa_case_ids, 'Cases' %> <%= form.select( :casa_case_ids, - current_organization.casa_cases.map { |casa_case| ["#{casa_case.case_number} - #{render AssignedVolunteersComponent.new(casa_case, current_user) }".html_safe, casa_case.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" }