From 84a0589fdd4545491ee4864c5ccfbb53ba3bcefd Mon Sep 17 00:00:00 2001 From: Katherine Thiessen Date: Tue, 30 Jul 2024 10:26:32 -0500 Subject: [PATCH] starting to create the new sample_name_cell_component --- .../nextflow/samplesheet/column_component.rb | 10 ++++++++-- .../sample_name_cell_component.html.erb | 4 ++++ .../samplesheet/sample_name_cell_component.rb | 15 +++++++++++++++ app/components/nextflow/samplesheet_component.rb | 2 ++ .../nextflow_samplesheet_component_test.rb | 2 +- .../files/nextflow/samplesheet_schema.json | 6 ++++++ test/fixtures/files/nextflow/schema_input.json | 6 ++++++ 7 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 app/components/nextflow/samplesheet/sample_name_cell_component.html.erb create mode 100644 app/components/nextflow/samplesheet/sample_name_cell_component.rb diff --git a/app/components/nextflow/samplesheet/column_component.rb b/app/components/nextflow/samplesheet/column_component.rb index 08912ede49..bebbf273c5 100644 --- a/app/components/nextflow/samplesheet/column_component.rb +++ b/app/components/nextflow/samplesheet/column_component.rb @@ -3,7 +3,7 @@ module Nextflow module Samplesheet # Renders a column in the sample sheet table - class ColumnComponent < Component + class ColumnComponent < Component # , attr_reader :namespace_id, :header, :property, :samples # rubocop:disable Metrics/ParameterLists @@ -18,10 +18,12 @@ def initialize(namespace_id:, header:, property:, samples:, metadata_fields:, re # rubocop:enable Metrics/ParameterLists - def render_cell_type(property, entry, sample, fields, index) + def render_cell_type(property, entry, sample, fields, index) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity case entry['cell_type'] when 'sample_cell' render_sample_cell(sample, fields) + when 'sample_name_cell' + render_sample_name_cell(sample, fields) when 'fastq_cell' render_fastq_cell(sample, property, entry, fields, index) when 'file_cell' @@ -71,6 +73,10 @@ def render_sample_cell(sample, fields) render(Samplesheet::SampleCellComponent.new(sample:, fields:)) end + def render_sample_name_cell(sample, fields) + render(Samplesheet::SampleNameCellComponent.new(sample:, fields:)) + end + def render_metadata_cell(sample, name, fields) render(Samplesheet::MetadataCellComponent.new(sample:, name:, form: fields)) end diff --git a/app/components/nextflow/samplesheet/sample_name_cell_component.html.erb b/app/components/nextflow/samplesheet/sample_name_cell_component.html.erb new file mode 100644 index 0000000000..fcb32d982b --- /dev/null +++ b/app/components/nextflow/samplesheet/sample_name_cell_component.html.erb @@ -0,0 +1,4 @@ +
+ <%= sample.name %> + <%= fields.hidden_field :sample_name, value: sample.name %> +
diff --git a/app/components/nextflow/samplesheet/sample_name_cell_component.rb b/app/components/nextflow/samplesheet/sample_name_cell_component.rb new file mode 100644 index 0000000000..7de93135ef --- /dev/null +++ b/app/components/nextflow/samplesheet/sample_name_cell_component.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Nextflow + module Samplesheet + # Component to render a cell with the sample name into the sample sheet + class SampleNameCellComponent < Component + attr_reader :sample, :fields + + def initialize(sample:, fields:) + @sample = sample + @fields = fields + end + end + end +end diff --git a/app/components/nextflow/samplesheet_component.rb b/app/components/nextflow/samplesheet_component.rb index 75a24f090a..03c2d3c361 100644 --- a/app/components/nextflow/samplesheet_component.rb +++ b/app/components/nextflow/samplesheet_component.rb @@ -30,6 +30,8 @@ def extract_properties(schema) def identify_cell_type(property, entry) return 'sample_cell' if property == 'sample' + return 'sample_name_cell' if property == 'sample_name' + return 'fastq_cell' if property.match(/fastq_\d+/) return 'file_cell' if check_for_file(entry) diff --git a/test/components/nextflow_samplesheet_component_test.rb b/test/components/nextflow_samplesheet_component_test.rb index de262158bb..14266b9e64 100644 --- a/test/components/nextflow_samplesheet_component_test.rb +++ b/test/components/nextflow_samplesheet_component_test.rb @@ -9,7 +9,7 @@ class NextflowSamplesheetComponentTest < ApplicationSystemTestCase visit("/rails/view_components/nextflow_samplesheet_component/default?sample_ids[]=#{sample1.id}&sample_ids[]=#{sample2.id}") # rubocop:disable Layout/LineLength assert_selector '.samplesheet-table' do |table| - table.assert_selector '.table-header', count: 4 + 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: sample1.puid diff --git a/test/fixtures/files/nextflow/samplesheet_schema.json b/test/fixtures/files/nextflow/samplesheet_schema.json index 24b1a7638b..744ba29a78 100644 --- a/test/fixtures/files/nextflow/samplesheet_schema.json +++ b/test/fixtures/files/nextflow/samplesheet_schema.json @@ -10,6 +10,12 @@ "pattern": "^\\S+$", "errorMessage": "Sample name must be provided and cannot contain spaces" }, + "sample_name": { + "type": "string", + "pattern": "^\\S+$", + "meta": ["name"], + "errorMessage": "Sample name must be provided and cannot contain spaces" + }, "fastq_1": { "type": "string", "pattern": "^\\S+\\.f(ast)?q\\.gz$", diff --git a/test/fixtures/files/nextflow/schema_input.json b/test/fixtures/files/nextflow/schema_input.json index 3b6cb059a9..d23fe68b65 100644 --- a/test/fixtures/files/nextflow/schema_input.json +++ b/test/fixtures/files/nextflow/schema_input.json @@ -12,6 +12,12 @@ "pattern": "^\\S+$", "meta": ["id"], "unique": true, + "errorMessage": "Sample id must be provided and cannot contain spaces" + }, + "sample_name": { + "type": "string", + "pattern": "^\\S+$", + "meta": ["name"], "errorMessage": "Sample name must be provided and cannot contain spaces" }, "fastq_1": {