Skip to content

Commit

Permalink
refactor all cell types to load in via JS
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHuynh333 committed Jan 24, 2025
1 parent 5a9663c commit da941ba
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 40 deletions.
12 changes: 0 additions & 12 deletions app/components/nextflow/samplesheet/column_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,5 @@
id="<%= "metadata-#{header}-column" %>"
class="dark:bg-slate-700 bg-slate-50"
>
<% samples.each_with_index do |sample, index| %>
<div
style="content-visibility: auto;"
class="border table-td dark:border-slate-600 border-slate-100"
>
<%= fields_for "workflow_execution[samples_workflow_executions_attributes][#{index}]" do |s| %>
<%= s.fields_for "samplesheet_params" do |fields| %>
<%= render_cell_type(header, property, sample, fields, index, workflow_params) %>
<% end %>
<% end %>
</div>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/components/nextflow/samplesheet/column_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def filter_files_by_pattern(files, pattern)
end

def render_sample_cell(sample_identifier)
render(Samplesheet::SampleCellComponent.new(sample_identifier:))
# render(Samplesheet::SampleCellComponent.new(sample_identifier:))
end

def render_metadata_cell(sample, name, fields, index)
Expand Down
6 changes: 0 additions & 6 deletions app/components/nextflow/samplesheet/sample_cell_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ module Nextflow
module Samplesheet
# Render a single cell of a Nextflow samplesheet for a given sample
class SampleCellComponent < Component
erb_template <<~ERB
<div class="p-2.5 sticky left-0">
<%= @sample_identifier %>
</div>
ERB

def initialize(sample_identifier:)
@sample_identifier = sample_identifier
end
Expand Down
89 changes: 88 additions & 1 deletion app/components/nextflow/samplesheet_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<div class="hidden" data-nextflow--samplesheet-target="workflowAttributes">
<%= samples_workflow_executions_attributes %>
</div>
<div class="hidden" data-nextflow--samplesheet-target="samplesheetProperties">
<%= @properties.to_json %>
</div>
<label class="block mb-2 text-sm font-medium text-slate-900 dark:text-white"><%= t(".label") %></label>
<div
role="alert"
Expand Down Expand Up @@ -53,5 +56,89 @@
</div>
</template>
</div>

</div>

<template data-nextflow--samplesheet-target="cellContainer">
<div
style="content-visibility: auto;"
class="border table-td dark:border-slate-600 border-slate-100"
>
</div>
</template>

<template data-nextflow--samplesheet-target="sampleIdentifierCell">
<div class="p-2.5 sticky left-0">
CELL_PLACEHOLDER
</div>
</template>

<template data-nextflow--samplesheet-target="dropdownCell">
<select
aria-label="COLUMN_NAME_PLACEHOLDER"
class="
w-full focus:ring-primary-500 focus:border-primary-500 p-2.5 dark:bg-slate-700
bg-slate-50 border-none dark:border-none dark:placeholder-slate-400 text-inherit
text-sm dark:focus:ring-primary-500 dark:focus:border-primary-500 cursor-pointer
"
data-action="change->nextflow--samplesheet#updateEditableSamplesheetData"
name="workflow_execution[samples_workflow_executions_attributes][INDEX_PLACEHOLDER][samplesheet_params][COLUMN_NAME_PLACEHOLDER]"
id="workflow_execution_samples_workflow_executions_attributes_INDEX_PLACEHOLDER_samplesheet_params_COLUMN_NAME_PLACEHOLDER"
>
<option value="" label=" "></option>
</select>
</template>

<template data-nextflow--samplesheet-target="fileCell">
<div>
<%= link_to new_workflow_executions_file_selector_path(
"file_selector[attachable_id]": "ATTACHABLE_ID_PLACEHOLDER",
"file_selector[attachable_type]": "ATTACHABLE_TYPE_PLACEHOLDER",
"file_selector[index]": "INDEX_PLACEHOLDER",
"file_selector[selected_id]": "SELECTED_ID_PLACEHOLDER",
"file_selector[property]": "PROPERTY_PLACEHOLDER",
"file_selector[required_properties]": @required_properties,
"file_selector[file_type]": "FILE_TYPE_PLACEHOLDER",
"file_selector[file_selector_arguments]": {workflow_params:, patterns:}
),
data: {
turbo_stream: "true",
} do %>
<div
id="<%="ATTACHABLE_ID_PLACEHOLDER_PROPERTY_PLACEHOLDER" %>"
class="
w-full focus:ring-primary-500 focus:border-primary-500 p-2 dark:bg-inherit
bg-inherit dark:placeholder-slate-400 text-inherit text-sm
dark:focus:ring-primary-500 dark:focus:border-primary-500 cursor-pointer
hover:border-slate-300 border-transparent border-2
"
<% if @required_properties.present? && @required_properties.include?(@property) %>
data-file-missing="<%= @selected.empty? ? "true" : "false" %>"
<% end %>
>
<%# <%= @selected.empty? ? t(".no_selected_file") : @selected[:filename] %>
CELL_VALUE_PLACEHOLDER
</div>
<% end %>
</div>

</template>

<template data-nextflow--samplesheet-target="metadataCell">
<div class="p-2.5 text-nowrap">
<span class="h-3.5 inline-block">METADATA_VALUE_PLACEHOLDER</span>
</div>
</template>

<template data-nextflow--samplesheet-target="textCell">
<input
class="
bg-slate-50 border-0 text-slate-900 text-sm focus:ring-primary-500 block w-full
p-2.5 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400
dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500
"
data-action="change->nextflow--samplesheet#updateEditableSamplesheetData"
type="text"
name="NAME_PLACEHOLDER"
id="ID_PLACEHOLDER"
>
</template>
46 changes: 38 additions & 8 deletions app/components/nextflow/samplesheet_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
module Nextflow
# Render the contents of a Nextflow samplesheet to a table
class SamplesheetComponent < Component

Check warning on line 5 in app/components/nextflow/samplesheet_component.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Class has too many lines. [103/100] Raw Output: app/components/nextflow/samplesheet_component.rb:5:3: C: Metrics/ClassLength: Class has too many lines. [103/100]
attr_reader :properties, :samples, :required_properties, :metadata_fields, :namespace_id, :workflow_params
attr_reader :properties, :samples, :required_properties, :metadata_fields, :namespace_id, :workflow_params,
:patterns

FILE_CELL_TYPES = %w[fastq_cell file_cell].freeze

Expand All @@ -13,6 +14,7 @@ def initialize(schema:, samples:, fields:, namespace_id:, workflow_params:)
@metadata_fields = fields
@required_properties = schema['items']['required'] || []
@workflow_params = workflow_params
@patterns = {}
extract_properties(schema)
end

Expand All @@ -28,34 +30,62 @@ def samples_workflow_executions_attributes
def samples_workflow_execution_attributes(sample)
{
'sample_id' => sample.id,
'samplesheet_params' => sample_samplesheet_params(sample)
'samplesheet_params' => sample_samplesheet_params(sample),
'patterns' => {}
}
end

def sample_samplesheet_params(sample) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
@properties.to_h do |name, property|
case property['cell_type']
when 'sample_cell'
[name, sample.puid]
[name, { form_value: sample.puid, cell_type: 'sample_cell', cell_value: sample.puid }]
when 'sample_name_cell'
[name, sample.name]
[name, { form_value: sample.name, cell_type: 'sample_name_cell', cell_value: sample.name }]
when 'fastq_cell'
[name, sample.attachments.empty? ? '' : sample.most_recent_fastq_file(name, @workflow_params)[:global_id]]
[name,
file_samplesheet_values(sample.attachments.empty? ? nil : sample.most_recent_fastq_file(name,
@workflow_params))]
when 'file_cell'
[name, sample.most_recent_other_file(property['autopopulate'], property['pattern'])[:global_id]]
[name,
file_samplesheet_values(sample.most_recent_other_file(property['autopopulate'], property['pattern']))]
when 'metadata_cell'
[name, sample.metadata.fetch(name, '')]
[name, metadata_samplesheet_values(sample, name)]
when 'dropdown_cell' || 'input_cell'
[name, '']
[name, { form_value: '', cell_type: property['cell_type'], cell_value: '' }]
end
end
end

def file_samplesheet_values(file)
{ form_value: file.empty? ? '' : file[:global_id],
cell_type: 'file_cell',
cell_value: file.empty? ? I18n.t('nextflow.samplesheet.file_cell_component.no_selected_file') : file[:filename],
attachment_id: file.empty? ? '' : file[:id] }
end

def metadata_samplesheet_values(sample, name)
metadata = sample.metadata.fetch(name, '')
if metadata.empty?
{ form_value: '',
cell_type: 'text',
cell_value: nil }
else
{ form_value: metadata,
cell_type: 'metadata_cell',
cell_value: metadata }
end
end

def extract_properties(schema)

Check warning on line 80 in app/components/nextflow/samplesheet_component.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Assignment Branch Condition size for extract_properties is too high. [<7, 24, 5> 25.5/20] Raw Output: app/components/nextflow/samplesheet_component.rb:80:5: C: Metrics/AbcSize: Assignment Branch Condition size for extract_properties is too high. [<7, 24, 5> 25.5/20]
@properties = schema['items']['properties']
@properties.each do |property, entry|
@properties[property]['required'] = schema['items']['required'].include?(property)
@properties[property]['cell_type'] = identify_cell_type(property, entry)
if @properties[property]['pattern'] && %w[fastq_cell
file_cell].include?(@properties[property]['cell_type'])
@patterns[property] = @properties[property]['pattern']
end
end

if @required_properties.include?('fastq_1') && @required_properties.include?('fastq_2')
Expand Down
1 change: 1 addition & 0 deletions app/components/nextflow_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
data-nextflow--samplesheet-attachments-error-value="<%= t(".attachments_error") %>"
data-nextflow--samplesheet-submission-error-value="<%= t(".submission_error") %>"
data-nextflow--samplesheet-url-value="<%= url %>"
data-nextflow--samplesheet-workflow-value="<%= {name: @workflow.name, version: @workflow.version }.to_json%>"
data-action="
nextflow--autofilled-cell:sendAutofilledInputData->nextflow--samplesheet#updateAutofilledSamplesheetData
"
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/workflow_executions/file_selector_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class FileSelectorController < ApplicationController
before_action :listing_attachments, only: %i[new create]

def new
puts 'hihihhihi'

Check warning on line 11 in app/controllers/workflow_executions/file_selector_controller.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Do not write to stdout. Use Rails's logger if you want to log. Raw Output: app/controllers/workflow_executions/file_selector_controller.rb:11:7: C: Rails/Output: Do not write to stdout. Use Rails's logger if you want to log.
puts file_selector_params

Check warning on line 12 in app/controllers/workflow_executions/file_selector_controller.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Do not write to stdout. Use Rails's logger if you want to log. Raw Output: app/controllers/workflow_executions/file_selector_controller.rb:12:7: C: Rails/Output: Do not write to stdout. Use Rails's logger if you want to log.
render turbo_stream: turbo_stream.update('file_selector_dialog',
partial: 'file_selector_dialog',
locals: { file_selector_params:, open: true }), status: :ok
Expand All @@ -33,7 +35,7 @@ def file_selector_params
:file_type,
required_properties: [],
file_selector_arguments: [
:pattern, { workflow_params: %i[name version] }
{ patterns: {} }, { workflow_params: %i[name version] }
]
)
end
Expand All @@ -45,10 +47,10 @@ def listing_attachments # rubocop:disable Metrics/AbcSize
file_selector_params['property'], file_selector_params['file_selector_arguments']['workflow_params']
)
when 'other'
@listing_attachments = if file_selector_params['file_selector_arguments']['pattern']
@listing_attachments = if file_selector_params['file_selector_arguments']['patterns'][file_selector_params['property']]

Check warning on line 50 in app/controllers/workflow_executions/file_selector_controller.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Line is too long. [127/120] Raw Output: app/controllers/workflow_executions/file_selector_controller.rb:50:121: C: Layout/LineLength: Line is too long. [127/120]
@attachable.filter_files_by_pattern(
@attachable.sorted_files[:singles] || [],
file_selector_params['file_selector_arguments']['pattern']
file_selector_params['file_selector_arguments']['patterns'][file_selector_params['property']]

Check warning on line 53 in app/controllers/workflow_executions/file_selector_controller.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Line is too long. [128/120] Raw Output: app/controllers/workflow_executions/file_selector_controller.rb:53:121: C: Layout/LineLength: Line is too long. [128/120]
)
else
sample.sorted_files[:singles] || []
Expand Down Expand Up @@ -77,7 +79,7 @@ def attachments
byte_size: attachment.byte_size,
created_at: attachment.created_at,
metadata: attachment.metadata }
return unless file_selector_params['property'] == 'fastq_1' || file_selector_params['property'] == 'fastq_2'
return unless %w[fastq_1 fastq_2].include?(file_selector_params['property'])

assign_associated_attachment_params(attachment)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class extends Controller {
static values = { inputName: { type: String }, inputValue: { type: String } };

connect() {
console.log("autofilled");
this.sendAutofilledInputData();
}

Expand Down
Loading

0 comments on commit da941ba

Please sign in to comment.