Skip to content

Commit

Permalink
Display search metadata on search results pages
Browse files Browse the repository at this point in the history
Regardless of a match for the search criteria, replay the criteria in
the results content and add a searched at timestamp in the breadcrumbs.
  • Loading branch information
steventux committed Mar 25, 2024
1 parent 4887e43 commit f0311b2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/controllers/searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def show
if @search_form.valid?
result_returned = record.present?

SearchLog.create!(
@search = SearchLog.create!(
dsi_user: current_dsi_user,
last_name: @search_form.last_name,
date_of_birth: @search_form.date_of_birth.to_fs(:db),
result_returned:
result_returned:,
)

render :no_record and return unless result_returned
Expand Down
2 changes: 1 addition & 1 deletion app/forms/search_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class SearchForm
include ActiveModel::Model
include ActiveModel::Validations::Callbacks

attr_accessor :last_name, :day, :month, :year
attr_accessor :last_name, :day, :month, :year, :searched_at

validates :last_name, presence: true
validates :date_of_birth, presence: true
Expand Down
16 changes: 7 additions & 9 deletions app/views/searches/no_record.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<% content_for :page_title, "No record found" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { "Home" => root_path, "Search results" => nil }) %>
<% content_for :breadcrumbs do %>
<%= govuk_breadcrumbs(breadcrumbs: { "Home" => root_path, "Search results" => nil }) %>
<span class="govuk-caption-m">
Searched at <%= @search.created_at.to_fs(:time_on_date_long) %>
</span>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">No record found on the Children’s Barred List</h1>

<%= govuk_summary_list(
rows: [
{ key: { text: "Last name" }, value: { text: @search_form.last_name } },
{ key: { text: "Date of birth" }, value: { text: @search_form.date_of_birth.to_fs(:long_uk) } }
])
%>

<p class="govuk_body">
There is no record on the children’s barred list with this last name and date of birth.
No record found for <%= @search.last_name %> born on <%= Date.parse(@search.date_of_birth).to_fs(:long_uk) %>
</p>

<p class="govuk_body">
Expand Down
16 changes: 7 additions & 9 deletions app/views/searches/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<% content_for :page_title, "Possible match with the children’s barred list" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { "Home" => root_path, "Search results" => nil }) %>
<% content_for :breadcrumbs do %>
<%= govuk_breadcrumbs(breadcrumbs: { "Home" => root_path, "Search results" => nil }) %>
<span class="govuk-caption-m">
Searched at <%= @search.created_at.to_fs(:time_on_date_long) %>
</span>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Possible match with the children’s barred list</h1>

<%= govuk_summary_list(
rows: [
{ key: { text: "Last name" }, value: { text: @record.last_name } },
{ key: { text: "Date of birth" }, value: { text: Date.parse(@record.date_of_birth).to_fs(:long_uk) } }
])
%>

<p class="govuk-body">
There’s a record on the children’s barred list with this last name and date of birth.
There’s a record on the children’s barred list with the last name <%= @search.last_name %> and date of birth <%= Date.parse(@search.date_of_birth).to_fs(:long_uk) %>.
</p>

<p class="govuk-body">
Expand Down
1 change: 1 addition & 0 deletions config/initializers/date_formats.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Date::DATE_FORMATS[:long_uk] = "%e %B %Y"
Time::DATE_FORMATS[:time_on_date_long] = "%-I:%M%P on %-d %B %Y"
4 changes: 3 additions & 1 deletion spec/system/user_searches_with_matching_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ def and_i_click_search
end

def then_i_see_a_result
expect(page).to have_content "Searched at #{SearchLog.last.created_at.to_fs(:time_on_date_long)}"
expect(page).to have_content "Possible match with the children’s barred list"
expect(page).to have_content @record.last_name
expect(page).to have_content("There’s a record on the children’s barred list with the last name #{@record.last_name} \
and date of birth #{Date.parse(@record.date_of_birth).to_fs(:long_uk)}")
end

def and_my_search_is_logged
Expand Down
4 changes: 3 additions & 1 deletion spec/system/user_searches_with_no_matching_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ def and_i_click_search
end

def then_i_see_the_no_record_page
expect(page).to have_content "Searched at #{SearchLog.last.created_at.to_fs(:time_on_date_long)}"
expect(page).to have_content "No record found"
expect(page).to have_content "Random name"
expect(page).to have_content(
"No record found for Random name born on #{Date.parse(@record.date_of_birth).to_fs(:long_uk)}")
end

def and_my_search_is_logged
Expand Down

0 comments on commit f0311b2

Please sign in to comment.