-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #825 from DFE-Digital/pagination-bulk-search
Add pagination for the bulk search results
- Loading branch information
Showing
16 changed files
with
171 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
module ApplicationHelper | ||
include Pagy::Frontend | ||
|
||
def current_namespace | ||
request.path.split("/").second | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class BulkSearchResponse < ApplicationRecord | ||
belongs_to :dsi_user | ||
|
||
before_create :expire_other_responses | ||
|
||
private | ||
|
||
def expire_other_responses | ||
BulkSearchResponse.where(dsi_user:) | ||
.where('expires_at > ?', Time.current) | ||
.update_all(expires_at: Time.current) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<% 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"> | ||
<h1 class="govuk-heading-l"><%= pluralize(@total, 'teacher record') %> found</h1> | ||
<%= govuk_tabs do |tabs| | ||
if @results.any? | ||
tabs.with_tab(label: "Records found", id: "records-found") do %> | ||
<%= render "check_records/search/results_table", teachers: @results %> | ||
<% end %> | ||
<% end %> | ||
<% if @not_found.any? %> | ||
<% tabs.with_tab(label: "Not found", id: "records-not-found") do %> | ||
<%= render "check_records/search/not_found", not_found: @not_found %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= govuk_link_to "Search again", new_check_records_bulk_search_path %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateBulkSearchResponses < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :bulk_search_responses, id: :uuid do |t| | ||
t.jsonb :body | ||
t.datetime :expires_at | ||
t.references :dsi_user, null: false, foreign_key: true | ||
t.integer :total | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FactoryBot.define do | ||
factory :bulk_search_response do | ||
association :dsi_user | ||
body { { results: [], not_found: [] } } | ||
total { 0 } | ||
expires_at { 30.minutes.from_now } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe BulkSearchResponse, type: :model do | ||
describe 'callbacks' do | ||
describe '#expire_other_responses' do | ||
let(:dsi_user) { create(:dsi_user) } | ||
let!(:old_response) { create(:bulk_search_response, dsi_user:, expires_at: 1.hour.from_now) } | ||
|
||
it 'expires other responses for the same user' do | ||
expect { | ||
create(:bulk_search_response, dsi_user:) | ||
}.to change { old_response.reload.expires_at }.to be_within(1.second).of(Time.current) | ||
end | ||
|
||
it 'does not expire responses for other users' do | ||
other_user = create(:dsi_user) | ||
other_response = create(:bulk_search_response, dsi_user: other_user, expires_at: 1.hour.from_now) | ||
|
||
expect { | ||
create(:bulk_search_response, dsi_user:) | ||
}.not_to(change { other_response.reload.expires_at }) | ||
end | ||
|
||
it 'does not affect already expired responses' do | ||
expired_response = create(:bulk_search_response, dsi_user:, expires_at: 1.hour.ago) | ||
|
||
expect { | ||
create(:bulk_search_response, dsi_user:) | ||
}.not_to(change { expired_response.reload.expires_at }) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters