Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve bulk search UI #847

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/components/tabbed_pagination_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

class TabbedPaginationComponent < GovukComponent::PaginationComponent
def initialize(fragment: nil, **kwargs)
self.fragment = fragment
super(**kwargs)
end

private

attr_accessor :fragment

def build_items
pagy.series.map { |i| with_item(number: i, href: pagy_url_for(pagy, i, fragment:), from_pagy: true) }
end

def build_next
return unless pagy&.next

kwargs = {
href: pagy_url_for(pagy, pagy.next, fragment:),
text: @next_text,
}

with_next_page(**kwargs.compact)
end

def build_previous
return unless pagy&.prev

kwargs = {
href: pagy_url_for(pagy, pagy.prev, fragment:),
text: @previous_text,
}

with_previous_page(**kwargs.compact)
end
end
6 changes: 5 additions & 1 deletion app/controllers/check_records/bulk_searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def show
QualificationsApi::Teacher.new(teacher['api_data'])
end
@not_found = data['not_found'].map {|record| Hashie::Mash.new(record) }
@pagy, @results = pagy_array(@results)
@pagy, @results = pagy_array(@results, limit: 10)
@pagy_not_found, @not_found =
pagy_array(@not_found, limit: 10, page_param: :page_not_found, anchor_string: '#records-not-found')

@bulk_search_response.update!(expires_at: 30.minutes.from_now)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/views/check_records/bulk_searches/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
must be in DD/MM/YYYY format.
</p>
<p class="govuk-body">
You can add a maximum of 20 people.
You can add a maximum of 100 people.
</p>
</li>
<li>
Expand Down
5 changes: 4 additions & 1 deletion app/views/check_records/bulk_searches/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<% content_for :page_title, "Bulk Search Results" %>
<% content_for :breadcrumbs do %>
<%= govuk_breadcrumbs(breadcrumbs: { "Home" => check_records_search_path, "Find multiple records" => new_check_records_bulk_search_path, "Results" => nil }) %>
<%= render ActionAtComponent.new(action: "searched") %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<%= render ActionAtComponent.new(action: "searched") %>
<h1 class="govuk-heading-l"><%= pluralize(@total, 'teacher record') %> found</h1>
<p class="govuk-body govuk-!-margin-bottom-6">
We found <%= pluralize(@total, 'teacher record') %> out of the <%= pluralize(@results.count + @not_found.count, 'entry') %> you uploaded.
</p>
<%= govuk_tabs do |tabs|
if @results.any?
tabs.with_tab(label: "Records found", id: "records-found") do %>
Expand Down
19 changes: 14 additions & 5 deletions app/views/check_records/search/_not_found.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="no-results--table">
<%= govuk_table do |table|
table.with_caption(size: 'm', text: 'No records found')
<% if not_found.any? %>
<%= govuk_table do |table|
table.with_caption(size: 'm', text: 'No records found')

table.with_head do |head|
head.with_row do |row|
Expand All @@ -13,9 +14,17 @@
not_found.each do |record|
body.with_row do |row|
row.with_cell(text: record.trn)
row.with_cell(text: record.date_of_birth.to_date.to_fs(:long_uk))
row.with_cell(text: record.date_of_birth.to_date.to_fs(:long_uk))
end
end
end
end
end %>
end %>
<% end %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<div class="app-pagination">
<%= render TabbedPaginationComponent.new(pagy: @pagy_not_found, fragment: '#records-not-found') if @pagy_not_found.pages.positive? %>
</div>
</div>
</div>
</div>
17 changes: 17 additions & 0 deletions spec/system/check_records/user_searches_with_a_valid_csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
when_i_click_find_records
then_i_see_results
and_my_search_is_logged
when_i_wait_for_the_search_to_expire
then_i_see_the_expired_search_message
end

private
Expand Down Expand Up @@ -44,4 +46,19 @@ def and_my_search_is_logged
expect(search_log.query_count).to eq 2
expect(search_log.result_count).to eq 1
end

def when_i_wait_for_the_search_to_expire
travel 29.minutes
page.refresh
travel 2.minutes
page.refresh
expect(page).not_to have_content "Bulk search expired"
travel 31.minutes
page.refresh
end

def then_i_see_the_expired_search_message
expect(page).to have_content "Bulk search expired"
travel_back
end
end
Loading