Browse Source
* Update query message * Add clear search link * Set input value * Use gem component * Move to list partial pattern * Partial path * Update spec * Rubocop * Unit test filter module * Rubocop * Add search result to page title if searched * Add missing horizontal rule * Use form_group attributes for search input Co-authored-by: Paul Robert Lloyd <me+git@paulrobertlloyd.com>pull/619/head
10 changed files with 141 additions and 89 deletions
@ -1,16 +1,15 @@ |
|||||||
<%= form_with model: @user, url: path(current_user), method: "get", local: true do |f| %> |
<%= form_with model: @user, url: path(current_user), method: "get", local: true do |f| %> |
||||||
<div class="app-search govuk-!-margin-bottom-4"> |
<div class="app-search govuk-!-margin-bottom-4"> |
||||||
<div class="govuk-form-group app-search__form-group"> |
<%= f.govuk_text_field :search, |
||||||
<label class="govuk-label govuk-!-margin-bottom-2" for="search-field"> |
form_group: { |
||||||
<%= label %> |
class: "app-search__form-group", |
||||||
</label> |
}, |
||||||
|
label: { text: search_label }, |
||||||
|
type: "search", |
||||||
|
value:, |
||||||
|
autocomplete: "off", |
||||||
|
class: "app-search__input" %> |
||||||
|
|
||||||
<input class="govuk-input app-search__input" id="search-field" name="search-field" type="search" autocomplete="off"> |
<%= f.govuk_submit "Search", classes: "app-search__button" %> |
||||||
</div> |
</div> |
||||||
|
|
||||||
<button class="govuk-button app-search__button undefined" data-module="govuk-button"> |
|
||||||
Search |
|
||||||
</button> |
|
||||||
|
|
||||||
</div> |
|
||||||
<% end %> |
<% end %> |
||||||
|
@ -0,0 +1,53 @@ |
|||||||
|
<%= govuk_table do |table| %> |
||||||
|
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> |
||||||
|
<span class="govuk-!-margin-right-4"> |
||||||
|
<% if searched.present? %> |
||||||
|
<strong><%= pagy.count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_user_count %></strong> total users. <%= govuk_link_to("Clear search", request.path) %> |
||||||
|
<% else %> |
||||||
|
<strong><%= pagy.count %></strong> total users. |
||||||
|
<% end %> |
||||||
|
</span> |
||||||
|
<% if current_user.support? %> |
||||||
|
<%= govuk_link_to "Download (CSV)", "/users.csv", type: "text/csv" %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<%= table.head do |head| %> |
||||||
|
<%= head.row do |row| %> |
||||||
|
<% row.cell(header: true, text: "Name and email adress", html_attributes: { |
||||||
|
scope: "col", |
||||||
|
}) %> |
||||||
|
<% row.cell(header: true, text: "Organisation and role", html_attributes: { |
||||||
|
scope: "col", |
||||||
|
}) %> |
||||||
|
<% row.cell(header: true, text: "Last logged in", html_attributes: { |
||||||
|
scope: "col", |
||||||
|
}) %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% users.each do |user| %> |
||||||
|
<%= table.body do |body| %> |
||||||
|
<%= body.row do |row| %> |
||||||
|
<% row.cell(header: true, html_attributes: { |
||||||
|
scope: "row", |
||||||
|
}) do %> |
||||||
|
<%= simple_format(user_cell(user), {}, wrapper_tag: "span") %> |
||||||
|
<% if user.is_data_protection_officer? || user.is_key_contact? %> |
||||||
|
<br> |
||||||
|
<% end %> |
||||||
|
<%= user.is_data_protection_officer? ? govuk_tag( |
||||||
|
classes: "app-tag--small", |
||||||
|
colour: "turquoise", |
||||||
|
text: "Data protection officer", |
||||||
|
) : "" %> |
||||||
|
<%= user.is_key_contact? ? govuk_tag( |
||||||
|
classes: "app-tag--small", |
||||||
|
colour: "turquoise", |
||||||
|
text: "Key contact", |
||||||
|
) : "" %> |
||||||
|
<% end %> |
||||||
|
<% row.cell(text: simple_format(org_cell(user), {}, wrapper_tag: "div")) %> |
||||||
|
<% row.cell(text: user.last_sign_in_at&.to_formatted_s(:govuk_date)) %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
@ -0,0 +1,31 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe Modules::UsersFilter do |
||||||
|
describe "filtered_users" do |
||||||
|
subject(:instance) { Class.new.include(described_class).new } |
||||||
|
|
||||||
|
before do |
||||||
|
FactoryBot.create_list(:user, 5) |
||||||
|
FactoryBot.create(:user, name: "Joe Blogg") |
||||||
|
FactoryBot.create(:user, name: "Tom Blogg", active: false) |
||||||
|
end |
||||||
|
|
||||||
|
let(:user_list) { User.all } |
||||||
|
|
||||||
|
context "when given a search term" do |
||||||
|
let(:search_term) { "Blogg" } |
||||||
|
|
||||||
|
it "filters the collection on search term and active users" do |
||||||
|
expect(instance.filtered_users(user_list, search_term).count).to eq(1) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when not given a search term" do |
||||||
|
let(:search_term) { nil } |
||||||
|
|
||||||
|
it "filters the collection on active users" do |
||||||
|
expect(instance.filtered_users(user_list, search_term).count).to eq(6) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue