From 3052d09fa7284f2e2a5040064c1cb3f06162b24d Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Sat, 29 Jul 2023 14:01:00 -0400 Subject: [PATCH 1/2] Add an "Outstanding Requests" card to org dashboard Lists the pending and started requests right on the main page so that the user has an idea of what they need to work on now. resolves #3669 --- app/controllers/dashboard_controller.rb | 2 + .../dashboard/_outstanding_requests.html.erb | 20 +++++ app/views/dashboard/index.html.erb | 19 +++++ .../pages/organization_dashboard_page.rb | 24 ++++++ spec/system/dashboard_system_spec.rb | 74 +++++++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 app/views/dashboard/_outstanding_requests.html.erb diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 45454f4ba9..990ff9ee2f 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -29,5 +29,7 @@ def index # passing nil here filters the announcements that didn't come from an organization @broadcast_announcements = BroadcastAnnouncement.filter_announcements(nil) + + @outstanding_requests = Request.where(status: %i[pending started]).order(:created_at) end end diff --git a/app/views/dashboard/_outstanding_requests.html.erb b/app/views/dashboard/_outstanding_requests.html.erb new file mode 100644 index 0000000000..1037e38dc1 --- /dev/null +++ b/app/views/dashboard/_outstanding_requests.html.erb @@ -0,0 +1,20 @@ + + + + + + + + + + + <% outstanding_requests.each do |item| %> + + + + + + + <% end %> + +
DatePartnerRequestorComments
<%= link_to item.created_at.strftime("%m/%d/%Y"), item %><%= item.partner.name %><%= item.partner_user&.name %><%= item.comments %>
diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 185404290a..a666437f76 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -115,6 +115,25 @@ <% end %> + <%= + outstanding_type = @outstanding_requests.empty? ? :box : :table + render( + "card", + id: "outstanding", + gradient: "warning", + title: "Outstanding Requests", + type: outstanding_type, + footer: link_to("See more...", requests_path), + footer_options: { class: "text-center" }, + ) do + if @outstanding_requests.empty? + "No outstanding requests!" + else + render "outstanding_requests", outstanding_requests: @outstanding_requests + end + end + %> + <%= render( "card", id: "distributions", diff --git a/spec/support/pages/organization_dashboard_page.rb b/spec/support/pages/organization_dashboard_page.rb index 50fac9cc37..3e93161a4a 100644 --- a/spec/support/pages/organization_dashboard_page.rb +++ b/spec/support/pages/organization_dashboard_page.rb @@ -84,6 +84,10 @@ def has_organization_logo? has_selector? org_logo_selector end + def has_outstanding_section? + has_selector? outstanding_selector + end + def manufacturers_total_donations within manufacturers_section do parse_formatted_integer find(".total_received_donations").text @@ -164,6 +168,22 @@ def total_inventory end end + def outstanding_section + find outstanding_selector + end + + def outstanding_requests + within outstanding_section do + all('tbody > tr') + end + end + + def outstanding_requests_link + within outstanding_section do + find('.card-footer a') + end + end + private def product_drives_section @@ -201,4 +221,8 @@ def org_logo_selector def purchases_section find "#purchases" end + + def outstanding_selector + "#outstanding" + end end diff --git a/spec/system/dashboard_system_spec.rb b/spec/system/dashboard_system_spec.rb index ddd6bef210..f7ac62a91d 100644 --- a/spec/system/dashboard_system_spec.rb +++ b/spec/system/dashboard_system_spec.rb @@ -812,6 +812,80 @@ def create_next_product_drive_distribution(date_picker:) end end end + + describe "Outstanding Requests" do + it "has a card" do + org_dashboard_page.visit + expect(org_dashboard_page).to have_outstanding_section + end + + context "when empty" do + before { org_dashboard_page.visit } + + it "displays a message" do + expect(org_dashboard_page.outstanding_section).to have_content "No outstanding requests!" + end + + it "has a See More link" do + expect(org_dashboard_page.outstanding_requests_link).to have_content "See more" + end + end + + context "with a pending request" do + let!(:request) { create :request, :pending } + let!(:outstanding_request) do + org_dashboard_page.visit + requests = org_dashboard_page.outstanding_requests + expect(requests.length).to eq 1 + requests.first + end + + it "displays the date" do + date = outstanding_request.find "td.date" + expect(date.text).to eq request.created_at.strftime("%m/%d/%Y") + end + + it "displays the partner" do + expect(outstanding_request).to have_content request.partner.name + end + + it "displays the requestor" do + expect(outstanding_request).to have_content request.partner_user.name + end + + it "displays the comment" do + expect(outstanding_request).to have_content request.comments + end + + it "links to the request" do + expect { outstanding_request.find('a').click } + .to change { page.current_path } + .to "/#{org_short_name}/requests/#{request.id}" + end + + it "has a See More link" do + expect(org_dashboard_page.outstanding_requests_link).to have_content "See more" + end + end + + it "does display a started request" do + create :request, :started + org_dashboard_page.visit + expect(org_dashboard_page.outstanding_requests.length).to eq 1 + end + + it "does not display a fulfilled request" do + create :request, :fulfilled + org_dashboard_page.visit + expect(org_dashboard_page.outstanding_requests).to be_empty + end + + it "does not display a discarded request" do + create :request, :discarded + org_dashboard_page.visit + expect(org_dashboard_page.outstanding_requests).to be_empty + end + end end def valid_bracketing_dates(date_range_info) From c302248ded1092b553897800a133dcadc6e1d508 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Sat, 29 Jul 2023 14:02:05 -0400 Subject: [PATCH 2/2] Limit Outstanding Requests to 25 A huge list of outstanding requests starts to overwhelm the page and make other things hard to find. Show 25 and a link that says how many other requests there are. --- app/views/dashboard/index.html.erb | 11 +++++++++-- spec/system/dashboard_system_spec.rb | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index a666437f76..fed9dbeb5f 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -117,19 +117,26 @@ <%= outstanding_type = @outstanding_requests.empty? ? :box : :table + outstanding_footer = + if @outstanding_requests.count > 25 + "And #{@outstanding_requests.count - 25} more..." + else + "See more..." + end render( "card", id: "outstanding", gradient: "warning", title: "Outstanding Requests", type: outstanding_type, - footer: link_to("See more...", requests_path), + footer: link_to(outstanding_footer, requests_path), footer_options: { class: "text-center" }, ) do if @outstanding_requests.empty? "No outstanding requests!" else - render "outstanding_requests", outstanding_requests: @outstanding_requests + render "outstanding_requests", + outstanding_requests: @outstanding_requests.take(25) end end %> diff --git a/spec/system/dashboard_system_spec.rb b/spec/system/dashboard_system_spec.rb index f7ac62a91d..1adb9ce7a7 100644 --- a/spec/system/dashboard_system_spec.rb +++ b/spec/system/dashboard_system_spec.rb @@ -885,6 +885,23 @@ def create_next_product_drive_distribution(date_picker:) org_dashboard_page.visit expect(org_dashboard_page.outstanding_requests).to be_empty end + + context "with many pending requests" do + let(:num_requests) { 50 } + let(:limit) { 25 } + before do + create_list :request, num_requests, :pending + org_dashboard_page.visit + end + + it "displays a limited number of requests" do + expect(org_dashboard_page.outstanding_requests.length).to eq limit + end + + it "has a link with the number of other requests" do + expect(org_dashboard_page.outstanding_requests_link).to have_content num_requests - limit + end + end end end