Skip to content

Commit

Permalink
Merge pull request #5272 from Rafael-Martins/create-mycases-dropdown
Browse files Browse the repository at this point in the history
Feat: Added "My Cases" dropdown for volunteers
  • Loading branch information
schoork authored Oct 22, 2023
2 parents d521c78 + 4ad4f95 commit 21b46c0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 23 deletions.
4 changes: 4 additions & 0 deletions app/helpers/sidebar_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def menu_item(label:, path:, visible: false)
link_to label, path, class: "list-group-item #{active_class(path)}" if visible
end

def get_case_contact_link(casa_case)
case_contacts_path(casa_case_id: casa_case.id)
end

private # private doesn't work in modules. It's here for semantic purposes

def active_class(link_path)
Expand Down
53 changes: 32 additions & 21 deletions app/views/layouts/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,34 @@
<% if current_user.casa_admin? || current_user.supervisor? %>
<%= render partial: "layouts/other_duties_nav_item" %>
<% end %>
<li class="<%= active_class(casa_cases_path) %> nav-item">
<%= link_to casa_cases_path do %>
<i class="lni lni-folder mr-10"></i>
<%= cases_index_title %>
<% end %>
</li>

<% if current_user.volunteer? %>
<li class="nav-item nav-item-has-children">
<a
href="#0"
class="collapsed"
data-bs-toggle="collapse"
data-bs-target="#ddmenu_cases"
aria-controls="ddmenu_cases"
aria-expanded="true"
aria-label="Toggle navigation">
<span class="icon">
<i class="lni lni-folder mr-10"></i>
</span>
<span class="text"><%= cases_index_title %></span>
</a>
<%= render partial: 'shared/sidebar_dropdown', locals: { all_link_path: casa_cases_path, dropdown_id: "ddmenu_cases", link_generator: method(:casa_case_path) } %>
</li>

<% else %>
<li class="<%= active_class(casa_cases_path) %> nav-item">
<%= link_to casa_cases_path do %>
<i class="lni lni-folder mr-10"></i>
<%= cases_index_title %>
<% end %>
</li>
<% end %>

<% if policy(CasaAdmin).index? %>
<li class="<%= active_class(casa_admins_path) %> nav-item">
<%= link_to casa_admins_path do %>
Expand All @@ -61,7 +83,7 @@
<li class="nav-item nav-item-has-children">
<a
href="#0"
class=""
class="collapsed"
data-bs-toggle="collapse"
data-bs-target="#ddmenu_case_contacts"
aria-controls="ddmenu_case_contacts"
Expand All @@ -72,18 +94,7 @@
</span>
<span class="text">Case Contacts</span>
</a>
<ul id="ddmenu_case_contacts" class="collapse dropdown-nav">
<li>
<%= link_to 'All', case_contacts_path %>
</li>
<% current_user.casa_cases.each do |casa_case| %>
<li>
<%= link_to case_contacts_path(casa_case_id: casa_case.id) do %>
<%= casa_case.case_number %>
<% end %>
</li>
<% end %>
</ul>
<%= render partial: 'shared/sidebar_dropdown', locals: { all_link_path: case_contacts_path, dropdown_id: "ddmenu_case_contacts", link_generator: method(:get_case_contact_link) } %>
</li>
<li class="<%= active_class(volunteer_learning_hours_path(volunteer_id: current_user.id || 0)) %> nav-item">
<%= link_to volunteer_learning_hours_path(volunteer_id: current_user.id || 0) do %>
Expand All @@ -104,7 +115,7 @@
<%= render partial: "layouts/other_duties_nav_item" %>
<% end %>

<% if policy(:application).see_banner_page? %>
<% if policy(:application).see_banner_page? %>
<li class="<%= active_class(casa_admins_path) %> nav-item">
<%= link_to banners_path, class: "#{active_class(banners_path)}" do %>
<i class="lni lni-flag mr-10"></i>
Expand All @@ -116,6 +127,7 @@
<li class="nav-item nav-item-has-children">
<a
href="#0"
class="collapsed"
class="group-actions"
data-bs-toggle="collapse"
data-bs-target="#ddmenu_55"
Expand Down Expand Up @@ -181,7 +193,6 @@
<% end %>
</li>
<% end %>

</ul>
</li>
<li>
Expand Down
12 changes: 12 additions & 0 deletions app/views/shared/_sidebar_dropdown.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ul id="<%= dropdown_id %>" class="collapse dropdown-nav">
<li>
<%= link_to 'All', all_link_path %>
</li>
<% current_user.casa_cases.each do |casa_case| %>
<li>
<%= link_to link_generator.call(casa_case) do %>
<%= casa_case.case_number %>
<% end %>
</li>
<% end %>
</ul>
22 changes: 21 additions & 1 deletion spec/system/casa_cases/index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
require "rails_helper"

RSpec.describe "casa_cases/index", type: :system do
let(:organization) { create(:casa_org) }
let(:volunteer) { build(:volunteer, display_name: "Bob Loblaw", casa_org: organization) }
let(:case_number) { "CINA-1" }

it "is filterable and linkable", :js do
organization = build(:casa_org)
admin = build(:casa_admin, casa_org: organization)
volunteer = build(:volunteer, display_name: "Cool Volunteer", casa_org: organization)
cina = build(:casa_case, active: true, casa_org: organization, case_number: "CINA-1")
cina = build(:casa_case, active: true, casa_org: organization, case_number: case_number)
tpr = create(:casa_case, active: true, casa_org: organization, case_number: "TPR-100")
no_prefix = create(:casa_case, active: true, casa_org: organization, case_number: "123-12-123")
create(:case_assignment, volunteer: volunteer, casa_case: cina)
Expand All @@ -24,4 +28,20 @@
click_on "Assigned to Transition Aged Youth"
click_on "Casa Case Prefix"
end

it "has a usable dropdown in sidebar" do
cina = build(:casa_case, active: true, casa_org: organization, case_number: case_number)
create(:case_assignment, volunteer: volunteer, casa_case: cina)

sign_in volunteer

visit root_path
click_on "My Cases"
within "#ddmenu_cases" do
click_on case_number
end

expect(page).to have_text("CASA Case Details")
expect(page).to have_text("Case number: CINA-1")
end
end
2 changes: 1 addition & 1 deletion spec/views/layouts/sidebar.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def true_user

render partial: "layouts/sidebar"

expect(rendered).to have_link("My Cases", href: "/casa_cases")
expect(rendered).to have_link("All", href: "/casa_cases")
expect(rendered).to have_link("All", href: "/case_contacts")
expect(rendered).to have_link("Generate Court Report", href: "/case_court_reports")
expect(rendered).to_not have_link("Export Data", href: "/reports")
Expand Down

0 comments on commit 21b46c0

Please sign in to comment.