Skip to content

Commit

Permalink
avoid rendering pagination if only 1 page, add associated test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHuynh333 committed Jan 30, 2025
1 parent f99f68b commit aed494e
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 73 deletions.
90 changes: 46 additions & 44 deletions app/components/nextflow/samplesheet_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="sample-sheet">
<div class="hidden" data-nextflow--samplesheet-target="workflowAttributes">
<%= samples_workflow_executions_attributes %>
<%= samples_workflow_executions_attributes.to_json %>
</div>
<div class="hidden" data-nextflow--samplesheet-target="samplesheetProperties">
<%= @properties.to_json %>
Expand Down Expand Up @@ -59,49 +59,51 @@
</div>
</template>
</div>
<div class="flex items-center justify-end">
<nav aria-label="<%= t("viral.pagy.pagination_component.aria-label") %>">
<ul class="inline-flex h-10 text-base">
<li><button
type="button"
class="
flex items-center justify-center px-4 h-10 ms-0 leading-tight border
border-slate-300 dark:border-slate-700 cursor-default text-slate-600 bg-slate-50
dark:bg-slate-700 dark:text-slate-400 border-e-0 rounded-s-lg
"
data-action="click->nextflow--samplesheet#previousPage"
data-nextflow--samplesheet-target="previousBtn"
disabled="disabled"
><%= t(".previous") %></button>
</li>
<li><select
class="
flex items-center justify-center px-4 h-10 ms-0 leading-tight border
border-slate-300 dark:border-slate-700 text-slate-500 bg-white
hover:bg-slate-100 hover:text-slate-700 dark:bg-slate-800 dark:text-slate-400
dark:hover:bg-slate-700 dark:hover:text-white cursor-pointer border-transparent
focus:border-transparent focus:ring-0
"
data-nextflow--samplesheet-target="pageNum"
data-action="change->nextflow--samplesheet#pageSelected"
aria-label="<%= t(".page_selection.aria_label") %>"
><option value="1" selected="selected">1</option></select>
</li>
<li><button
class="
flex items-center justify-center px-4 h-10 ms-0 leading-tight border
border-slate-300 dark:border-slate-700 text-slate-500 bg-white
hover:bg-slate-100 hover:text-slate-700 dark:bg-slate-800 dark:text-slate-400
dark:hover:bg-slate-700 dark:hover:text-white rounded-e-lg
"
type="button"
data-nextflow--samplesheet-target="nextBtn"
data-action="click->nextflow--samplesheet#nextPage"
><%= t(".next") %></button>
</li>
</ul>
</nav>
</div>
<% if samples_workflow_executions_attributes.count > 5 %>
<div id="samplesheet_pagination" class="flex items-center justify-end">
<nav aria-label="<%= t("viral.pagy.pagination_component.aria-label") %>">
<ul class="inline-flex h-10 text-base">
<li><button
type="button"
class="
flex items-center justify-center px-4 h-10 ms-0 leading-tight border
border-slate-300 dark:border-slate-700 cursor-default text-slate-600 bg-slate-50
dark:bg-slate-700 dark:text-slate-400 border-e-0 rounded-s-lg
"
data-action="click->nextflow--samplesheet#previousPage"
data-nextflow--samplesheet-target="previousBtn"
disabled="disabled"
><%= t(".previous") %></button>
</li>
<li><select
class="
flex items-center justify-center px-4 h-10 ms-0 leading-tight border
border-slate-300 dark:border-slate-700 text-slate-500 bg-white
hover:bg-slate-100 hover:text-slate-700 dark:bg-slate-800 dark:text-slate-400
dark:hover:bg-slate-700 dark:hover:text-white cursor-pointer border-transparent
focus:border-transparent focus:ring-0
"
data-nextflow--samplesheet-target="pageNum"
data-action="change->nextflow--samplesheet#pageSelected"
aria-label="<%= t(".page_selection.aria_label") %>"
><option value="1" selected="selected">1</option></select>
</li>
<li><button
class="
flex items-center justify-center px-4 h-10 ms-0 leading-tight border
border-slate-300 dark:border-slate-700 text-slate-500 bg-white
hover:bg-slate-100 hover:text-slate-700 dark:bg-slate-800 dark:text-slate-400
dark:hover:bg-slate-700 dark:hover:text-white rounded-e-lg
"
type="button"
data-nextflow--samplesheet-target="nextBtn"
data-action="click->nextflow--samplesheet#nextPage"
><%= t(".next") %></button>
</li>
</ul>
</nav>
</div>
<% end %>
</div>

<template data-nextflow--samplesheet-target="cellContainer">
Expand Down
3 changes: 1 addition & 2 deletions app/components/nextflow/samplesheet_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ def initialize(schema:, samples:, fields:, namespace_id:, workflow_params:)
end

def samples_workflow_executions_attributes
attributes = samples.each_with_index.to_h do |sample, index|
samples.each_with_index.to_h do |sample, index|
[index, samples_workflow_execution_attributes(sample)]
end
attributes.to_json
end

private
Expand Down
6 changes: 2 additions & 4 deletions app/javascript/controllers/nextflow/samplesheet_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default class extends Controller {
this.#samplesheetAttributes = JSON.parse(
this.workflowAttributesTarget.innerText,
);

// clear the now unnecessary DOM element
this.workflowAttributesTarget.remove();
this.#columnNames = Object.keys(this.#samplesheetProperties);
Expand All @@ -106,10 +107,7 @@ export default class extends Controller {
);

// disable dropdown and next button if only 1 page of samples, otherwise create the dropdown page options
if (this.#lastPage == 1) {
this.#disablePaginationButton(this.nextBtnTarget);
this.#disablePaginationButton(this.pageNumTarget);
} else {
if (this.#lastPage > 1) {
this.#generatePageNumberDropdown();
}
// render samplesheet table
Expand Down
7 changes: 3 additions & 4 deletions test/components/nextflow_samplesheet_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ class NextflowSamplesheetComponentTest < ApplicationSystemTestCase
@sample2 = samples(:sample44)
end
test 'default' do
sample = Sample.first
visit('/rails/view_components/nextflow_component/default')
visit("/rails/view_components/nextflow_samplesheet_component/default?sample_ids[]=#{@sample1.id}&sample_ids[]=#{@sample2.id}")

Check warning on line 14 in test/components/nextflow_samplesheet_component_test.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Line is too long. [130/120] Raw Output: test/components/nextflow_samplesheet_component_test.rb:14:121: C: Layout/LineLength: Line is too long. [130/120]

assert_selector '.samplesheet-table' do |table|
table.assert_selector '.table-header', count: 5
table.assert_selector '.table-column:last-of-type .table-header', text: 'STRANDEDNESS (REQUIRED)'
table.assert_selector '.table-column:first-of-type .table-td', count: 2
table.assert_selector '.table-column:first-of-type .table-td:first-of-type', text: sample.puid
table.assert_selector '.table-column:nth-of-type(2) .table-td:first-of-type', text: sample.name
table.assert_selector '.table-column:first-of-type .table-td:first-of-type', text: @sample1.puid
table.assert_selector '.table-column:nth-of-type(2) .table-td:first-of-type', text: @sample1.name
table.assert_selector '.table-column:last-of-type .table-td:first-of-type select option', count: 4
table.assert_selector '.table-column:last-of-type .table-td:first-of-type select option:nth-of-type(2)',
text: 'forward'
Expand Down
15 changes: 12 additions & 3 deletions test/components/previews/nextflow_samplesheet_component_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

class NextflowSamplesheetComponentPreview < ViewComponent::Preview
# @param schema_file select :schema_file_options
def default(schema_file: 'samplesheet_schema.json', sample_ids: [Sample.first.id, Sample.second.id])
def default(schema_file: 'nextflow_schema.json', sample_ids: [Sample.first.id, Sample.second.id])
samples = Sample.where(id: sample_ids)

entry = {
name: 'phac-nml/iridanextexample',
description: 'IRIDA Next Example Pipeline',
url: 'https://github.com/phac-nml/iridanextexample'
}.with_indifferent_access

workflow = Irida::Pipeline.new(entry, '1.0.1',
Rails.root.join('test/fixtures/files/nextflow/', schema_file),
Rails.root.join('test/fixtures/files/nextflow/samplesheet_schema.json'))

render_with_template(locals: {
schema_file:,
samples:,
fields: %w[insdc_accession country metadata_3]
workflow:
})
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
<%= render Nextflow::SamplesheetComponent.new(
schema:
JSON.parse(
File.read(
Rails.root.join("test", "fixtures", "files", "nextflow", schema_file),
),
),
<%= render NextflowComponent.new(
workflow:,
url: "no_where",
samples:,
fields:,
fields: [],
namespace_id: "SDFSDFSDF",
workflow_params: {
name: "workflow-name",
version: "workflow-version",
},
) %>
54 changes: 50 additions & 4 deletions test/system/workflow_executions/submissions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class SubmissionsTest < ApplicationSystemTestCase
@sample22 = samples(:sample22)
@sample43 = samples(:sample43)
@sample44 = samples(:sample44)
@sample46 = samples(:sample46)
@project2 = projects(:project2)
@project = projects(:project37)
@group1 = groups(:group_one)
Expand Down Expand Up @@ -669,7 +670,6 @@ class SubmissionsTest < ApplicationSystemTestCase
login_as user
fwd_attachment = attachments(:attachmentPEFWD43)
rev_attachment = attachments(:attachmentPEREV43)
sample46 = samples(:sample46)
visit namespace_project_samples_url(namespace_id: @namespace.path, project_id: @project.path)
# verify samples table loaded
assert_text strip_tags(I18n.t(:'viral.pagy.limit_component.summary', from: 1, to: 3, count: 3,
Expand Down Expand Up @@ -701,9 +701,9 @@ class SubmissionsTest < ApplicationSystemTestCase
assert_selector "div[id='#{@sample44.id}_fastq_2']",
text: I18n.t('nextflow.samplesheet.file_cell_component.no_selected_file')

assert_selector "div[id='#{sample46.id}_fastq_1']",
assert_selector "div[id='#{@sample46.id}_fastq_1']",
text: I18n.t('nextflow.samplesheet.file_cell_component.no_selected_file')
assert_selector "div[id='#{sample46.id}_fastq_2']",
assert_selector "div[id='#{@sample46.id}_fastq_2']",
text: I18n.t('nextflow.samplesheet.file_cell_component.no_selected_file')
# verify error msg has not rendered
assert_no_text I18n.t('nextflow.samplesheet_component.data_missing_error')
Expand All @@ -716,7 +716,7 @@ class SubmissionsTest < ApplicationSystemTestCase
within('div[data-nextflow--samplesheet-target="error"]') do
assert_text "#{I18n.t('nextflow_component.data_missing_error')}"

Check warning on line 717 in test/system/workflow_executions/submissions_test.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Prefer `to_s` over string interpolation. Raw Output: test/system/workflow_executions/submissions_test.rb:717:23: C: Style/RedundantInterpolation: Prefer `to_s` over string interpolation.
assert_text "- #{@sample44.puid}: fastq_1"
assert_text "- #{sample46.puid}: fastq_1"
assert_text "- #{@sample46.puid}: fastq_1"
end
### VERIFY END ###
end
Expand Down Expand Up @@ -858,5 +858,51 @@ class SubmissionsTest < ApplicationSystemTestCase
end
### VERIFY END ###
end

test 'pagination does not render if only one page of samples' do
### SETUP START ###
user = users(:john_doe)
login_as user
visit namespace_project_samples_url(namespace_id: @namespace.path, project_id: @project.path)
# verify samples table loaded
assert_text strip_tags(I18n.t(:'viral.pagy.limit_component.summary', from: 1, to: 3, count: 3,
locale: user.locale))
# select samples
click_button I18n.t(:'projects.samples.index.select_all_button')
# launch workflow execution dialog
click_on I18n.t(:'projects.samples.index.workflows.button_sr')

assert_selector '#dialog'
within %(turbo-frame[id="samples_dialog"]) do
assert_selector '.dialog--header', text: I18n.t(:'workflow_executions.submissions.pipeline_selection.title')
assert_button text: 'phac-nml/iridanextexample', count: 3
first('button', text: 'phac-nml/iridanextexample').click
end
### SETUP END ###

### ACTIONS START ###
within '#dialog' do
# verify samples samplesheet loaded
assert_selector 'div.sample-sheet'
within('#metadata-sample-column') do
assert_text @sample43.puid
assert_text @sample44.puid
assert_text @sample46.puid
end
### ACTIONS END ###

### VERIFY START ###
# verify no pagination buttons rendered
assert_no_selector '#samplesheet_pagination'
assert_no_selector 'button[data-action="click->nextflow--samplesheet#previousPage"][disabled]',
text: I18n.t('nextflow.samplesheet_component.previous')
assert_no_selector 'select[data-action="change->nextflow--samplesheet#pageSelected"]', text: '1'

assert_no_selector 'button[data-action="click->nextflow--samplesheet#nextPage"]',
text: I18n.t('nextflow.samplesheet_component.next')

### VERIFY END ###
end
end
end
end

0 comments on commit aed494e

Please sign in to comment.