Skip to content

Commit

Permalink
Samples Table: Fixes preserving page size when searching (#745)
Browse files Browse the repository at this point in the history
* adding limit param to sample search

* fixing tests

* adding new tests

* renaming samples table limit id

* fixing unpermitted parameters errors

* removing unused turbo_frame_tag

* replacing limit component id

* making the limit component easier to read
  • Loading branch information
ksierks authored Sep 11, 2024
1 parent 005efb2 commit 6ea1e7d
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
5 changes: 4 additions & 1 deletion app/components/viral/pagy/limit_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<div
class="inline-flex items-center mt-4 space-x-2 text-slate-500 dark:text-slate-400"
id="limit-component"
class="
inline-flex items-center mt-4 space-x-2 text-slate-500 dark:text-slate-400
"
>
<span><%= t(".items", items: @item) %></span>
<%= viral_dropdown(label: @pagy.limit) do |dropdown| %>
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/groups/samples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
end

def search
redirect_to group_samples_path
redirect_to group_samples_path(request.request_parameters.slice(:limit))
end

def select
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/projects/samples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
end

def search
redirect_to namespace_project_samples_path
redirect_to namespace_project_samples_path(request.request_parameters.slice(:limit))
end

def show
Expand Down
4 changes: 2 additions & 2 deletions app/views/groups/samples/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
class:
"flex items-center px-4 py-2 bg-slate-100 text-slate-600 dark:bg-slate-600 dark:text-slate-300
border-slate-100 dark:border-slate-600 pointer-events-none cursor-not-allowed",
border-slate-100 dark:border-slate-600 pointer-events-none cursor-not-allowed",
) %>
<% else %>
<% dropdown.with_item(
Expand Down Expand Up @@ -89,9 +89,9 @@
</div>
<div class="float-right">
<%= search_form_for @q, url: search_group_samples_url, html: { method: :post, "data-controller": "filters", "data-turbo-action": "replace", "data-filters-selection-outlet": "#samples-table", class: "filters" } do |f| %>
<%= turbo_frame_tag "group_samples_hidden_values" %>
<div class="flex flex-row-reverse items-center mb-4 space-x-2">
<input type="hidden" name="format" value="turbo_stream"/>
<input type="hidden" name="limit" value="<%=@pagy.limit%>"/>

<%= render partial: "projects/samples/shared/metadata_toggle", locals: { form: f } %>
<%= render ListFilterComponent.new(
Expand Down
5 changes: 3 additions & 2 deletions app/views/projects/samples/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
class:
"flex items-center px-4 py-2 bg-slate-100 text-slate-600 dark:bg-slate-600 dark:text-slate-300
border-slate-100 dark:border-slate-600 pointer-events-none cursor-not-allowed",
border-slate-100 dark:border-slate-600 pointer-events-none cursor-not-allowed",
) %>
<% else %>
<% dropdown.with_item(
Expand Down Expand Up @@ -144,9 +144,10 @@
</div>
<div class="float-right">
<%= search_form_for @q, url: search_namespace_project_samples_url, html: { method: :post, "data-controller": "filters", "data-turbo-action": "replace", "data-filters-selection-outlet": "#samples-table" }, class: "filters" do |f| %>
<%= turbo_frame_tag "project_samples_hidden_values" %>
<div class="flex flex-row-reverse items-center mb-4 space-x-2">
<input type="hidden" name="format" value="turbo_stream"/>
<input type="hidden" name="limit" value="<%=@pagy.limit%>"/>

<%= render partial: "projects/samples/shared/metadata_toggle", locals: { form: f } %>
<%= render ListFilterComponent.new(
form: f,
Expand Down
25 changes: 25 additions & 0 deletions test/system/groups/samples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,31 @@ def retrieve_puids
assert_selector 'table tbody tr:first-child td:nth-child(2)', text: @sample1.name
end

test 'can change pagination and then filter by puid' do
visit group_samples_url(@group)

within('div#limit-component') do
find('button').click
find('a[href="?limit=10"]').click
end

assert_text strip_tags(I18n.t(:'viral.pagy.limit_component.summary', from: 1, to: 10, count: 26,
locale: @user.locale))
assert_selector 'table tbody tr', count: 10
within('table tbody tr:first-child th') do
assert_text @sample1.puid
end

fill_in placeholder: I18n.t(:'groups.samples.index.search.placeholder'), with: @sample1.puid

assert_text strip_tags(I18n.t(:'viral.pagy.limit_component.summary', from: 1, to: 1, count: 1,
locale: @user.locale))
assert_selector 'table tbody tr', count: 1
assert_text @sample1.name
assert_no_text @sample2.name
assert_selector 'div#limit-component button div span', text: '10'
end

test 'can sort and then filter the list of samples by name' do
visit group_samples_url(@group)

Expand Down
24 changes: 24 additions & 0 deletions test/system/projects/samples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,30 @@ class SamplesTest < ApplicationSystemTestCase
assert_no_text @sample3.name
end

test 'can change pagination and then filter by name' do
visit namespace_project_samples_url(@namespace, @project)

within('div#limit-component') do
find('button').click
find('a[href="?limit=10"]').click
end

assert_text strip_tags(I18n.t(:'viral.pagy.limit_component.summary', from: 1, to: 3, count: 3,
locale: @user.locale))
assert_selector '#samples-table table tbody tr', count: 3
assert_text @sample1.name
assert_text @sample2.name

fill_in placeholder: I18n.t(:'projects.samples.index.search.placeholder'), with: @sample1.name

assert_text strip_tags(I18n.t(:'viral.pagy.limit_component.summary', from: 1, to: 1, count: 1,
locale: @user.locale))
assert_selector 'table tbody tr', count: 1
assert_text @sample1.name
assert_no_text @sample2.name
assert_selector 'div#limit-component button div span', text: '10'
end

test 'can sort samples by column' do
visit namespace_project_samples_url(@namespace, @project)

Expand Down

0 comments on commit 6ea1e7d

Please sign in to comment.