Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Y24-268 - Create a presenter for automated submission for WGS branch on Adp Lig plate #1982

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d8c4a08
feat: add wgs branch initial plate purpose
StephenHulme Oct 1, 2024
db07ab5
Merge branch 'develop' into y24-268-adp-lig-plate-automated-submission
StephenHulme Oct 8, 2024
9e5cf02
wip: lcmt
StephenHulme Oct 9, 2024
3478941
refactor: allow combining of sidebar elements using a parent container
StephenHulme Oct 11, 2024
856acef
fix: change choose-workflow message when there is an active workflow
StephenHulme Oct 11, 2024
1823148
feat: create a new PermissiveSubmissionPlatePresenter and state machine
StephenHulme Oct 11, 2024
fc0507b
fix: allow plates to be passed in PermissiveSubmissionPlatePresenter
StephenHulme Oct 11, 2024
9ffc791
style: clean-up comments
StephenHulme Oct 11, 2024
531230d
style: clean-up another comment
StephenHulme Oct 11, 2024
2f2b8a2
fix: add temporary request options
StephenHulme Oct 14, 2024
d15c05e
refactor: pull out submission behviour into a separate module
StephenHulme Oct 14, 2024
9d5ad09
fix: allow new presenter to be independent of SubmissionPlatePresenter
StephenHulme Oct 14, 2024
25c46ff
tests: add tests for PermissiveSubmissionPlatePresenter
StephenHulme Oct 14, 2024
06a88de
style: lint
StephenHulme Oct 14, 2024
29150e1
Merge branch 'develop' into y24-268-adp-lig-plate-automated-submission
StephenHulme Oct 14, 2024
13bb548
style: remove old comment
StephenHulme Oct 14, 2024
a132f2d
style: update documentation comments
StephenHulme Oct 14, 2024
af888f7
tests: it_behaves_like a stock presenter becomes it allows state change
StephenHulme Oct 14, 2024
a154da1
fix: only allow a new submission if none are currently active or pending
StephenHulme Oct 15, 2024
dd447a1
fix: clean up display of existing submissions card
StephenHulme Oct 15, 2024
44817ff
fix: keep it simple by generalising the workflows message
StephenHulme Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# frozen_string_literal: true

require_dependency 'presenters/statemachine'
module Presenters::Statemachine
#
# Presenters::Statemachine::PermissiveSubmission can be included in a class to
# provide a state machine with the following behaviour:
# - When plates are 'passed', a combined default and submission sidebar will
# be displayed. This sidebar allows the user to build a submission for the
# plate, while still allowing child plates to be created.
# - When plates are 'pending', only the default sidebar will be displayed,
# allowing the user to create the child plates.
# - In all other states the default sidebar will be used.
# - In all states the library passing is not permitted.
#
# Typically this state machine should be used in conjunction with an input
# plate purpose. {file:docs/purposes_yaml_files.md See the purposes yaml configuration.}
# Purposes with input_plate set to true use the PlatePurpose::Input class in sequencescape.
# These plates show the following states:
# Pending: No submission made, or some wells with samples have no submissions
# Passed: Submissions made, and the plate is ready to proceed
# Cancelled/Failed: Seen when all requests out of the plate have these states.
#
# Other states: Typically not seen in standard scenarios.
module PermissiveSubmission
extend ActiveSupport::Concern
included do
include Shared

# The state machine for plates which has knock-on effects on the plates that can be created
state_machine :state, initial: :pending do
StateTransitions.inject(self)

# These are the states, which are really the only things we need ...
state :pending do
include StateAllowsChildCreation
include DoesNotAllowLibraryPassing
def sidebar_partial
'default'
end
end

state :started do
include StateAllowsChildCreation
include DoesNotAllowLibraryPassing
end

state :processed_1 do
include StateAllowsChildCreation
include DoesNotAllowLibraryPassing
end

state :processed_2 do
include StateAllowsChildCreation
include DoesNotAllowLibraryPassing
end

state :processed_3 do
include StateAllowsChildCreation
include DoesNotAllowLibraryPassing
end

state :processed_4 do
include StateAllowsChildCreation
include DoesNotAllowLibraryPassing
end

state :passed do
include StateAllowsChildCreation
include DoesNotAllowLibraryPassing

def sidebar_partial
'submission_default'
end
end
Comment on lines +68 to +75
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'submission_default' shows the newly combined sidebar


state :qc_complete, human_name: 'QC Complete' do
include StateAllowsChildCreation
include DoesNotAllowLibraryPassing
end

state :cancelled do
include StateDoesNotAllowChildCreation
include DoesNotAllowLibraryPassing
end

state :failed do
include StateDoesNotAllowChildCreation
include DoesNotAllowLibraryPassing
end
end
end
end
end
45 changes: 45 additions & 0 deletions app/models/concerns/presenters/submission_behaviour.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

# Include in a presenter to add support for creating a submission
module Presenters::SubmissionBehaviour
def each_submission_option
purpose_config.submission_options.each do |button_text, options|
submission_options = options.to_hash
submission_options[:asset_groups] = asset_groups
submission_options[:labware_barcode] = labware.labware_barcode.human
yield button_text, SequencescapeSubmission.new(submission_options)
end
end

def submissions
labware.direct_submissions
end

def pending_submissions?
submissions.any? { |submission| submission.building_in_progress?(ready_buffer: 20.seconds) }
end

# Determine whether the Choose Workflow buttons should be displayed
def allow_new_submission?
# No more than one submission of a type can be active at time for a given labware.
# Prevent new submissions if any are currently in progress, as the submission type
# is currently not available.
submissions_in_progress = pending_submissions? || active_submissions?
submissions_in_progress == false
end

private

def asset_groups
@asset_groups ||=
labware
.wells
.compact_blank
.group_by(&:order_group)
.map { |_, wells| { assets: wells.map(&:uuid), autodetect_studies: true, autodetect_projects: true } }
end

def active_submissions?
submissions.any?(&:ready?)
end
end
43 changes: 43 additions & 0 deletions app/models/presenters/permissive_submission_plate_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

module Presenters
#
# The PermissiveSubmissionPlatePresenter is used when a pipeline needs to
# branch, but also needs to allow plates to be created in advance. Currently
# this is only used for the EMSeq pipeline's split to the WGS branch (and it
# is hoped that other use cases will be avoided in future). It presents the
# user with a selection of workflows, and allows them to generate
# corresponding Sequencescape submissions. Once these submissions are passed,
# the plate behaves like a standard stock plate. Otherwise it includes aspects
# of the PermissivePresenter and allows plates to be created even when the
# plate is pending.
#
# Submission options are defined by the submission_options config in the
# purposes/*.yml file. Structure is:
# <button text>:
# template_name: <submission template name>
# request_options:
# <request_option_key>: <request_option_value>
# ...
class PermissiveSubmissionPlatePresenter < PlatePresenter
include Presenters::Statemachine::PermissiveSubmission
include Presenters::SubmissionBehaviour

validates_with Validators::SuboptimalValidator
validates_with Validators::ActiveRequestValidator

self.allow_well_failure_in_states = []

# Stock style class causes well state to inherit from plate state.
self.style_class = 'stock'

self.summary_items = {
'Barcode' => :barcode,
'Number of wells' => :number_of_wells,
'Plate type' => :purpose_name,
'Current plate state' => :state,
'Input plate barcode' => :input_barcode,
'Created on' => :created_on
}
end
end
34 changes: 4 additions & 30 deletions app/models/presenters/submission_plate_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ module Presenters
class SubmissionPlatePresenter < PlatePresenter
include Presenters::Statemachine::Submission
include Presenters::Statemachine::DoesNotAllowLibraryPassing
include Presenters::SubmissionBehaviour
include Presenters::StateChangeless

self.allow_well_failure_in_states = []

# Stock style class causes well state to inherit from plate state.
self.style_class = 'stock'

self.summary_items = {
Expand All @@ -29,35 +33,5 @@ class SubmissionPlatePresenter < PlatePresenter
'Input plate barcode' => :input_barcode,
'Created on' => :created_on
}

self.allow_well_failure_in_states = []

def each_submission_option
purpose_config.submission_options.each do |button_text, options|
submission_options = options.to_hash
submission_options[:asset_groups] = asset_groups
submission_options[:labware_barcode] = labware.labware_barcode.human
yield button_text, SequencescapeSubmission.new(submission_options)
end
end

def pending_submissions?
submissions.any? { |submission| submission.building_in_progress?(ready_buffer: 20.seconds) }
end

def submissions
labware.direct_submissions
end

private

def asset_groups
@asset_groups ||=
labware
.wells
.compact_blank
.group_by(&:order_group)
.map { |_, wells| { assets: wells.map(&:uuid), autodetect_studies: true, autodetect_projects: true } }
end
end
end
7 changes: 3 additions & 4 deletions app/views/plates/_choose_workflow.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<%= vite_javascript_tag 'entrypoints/pages/choose_workflow.js', defer: true %>
<%= card title:'Choose workflow', id: 'choose_workflow_card', css_class: 'suggested-actions logged_in_only' do %>
<p class="lead">
This plate can be processed via multiple workflows and there are currently
no active workflows associated with the plate. Please select a workflow.
This will build the necessary submissions in Sequencescape, and will allow
you to proceed.
A new workflow can be created for this plate. Please choose a workflow to
continue. This will build the necessary submissions in Sequencescape,
allowing you to proceed.
</p>

<div id="submission_forms">
Expand Down
5 changes: 3 additions & 2 deletions app/views/plates/_pending_submissions.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<% if presenter.submissions.present? %>
<%# presenter.submissions returns a JsonApiClient::Query::Builder at this point #%>
<% if presenter.submissions.present? and presenter.submissions.size > 0 %>
<%= card title:'Submissions', css_class: 'suggested-actions', without_block: true do %>
<% if presenter.pending_submissions? %>
<div class="card-body">
<p class="lead">There are currently submissions being built, This page will refresh in
<p class="lead">There are currently submissions being built, the page will refresh in
<span id="refresh_time" data-reload-time="5">5</span> seconds.</p>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/plates/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
<% end %>
<% end %>

<%= render "plates/sidebars/#{@presenter.sidebar_partial}", presenter: @presenter %>
<%= render "plates/sidebars/container", presenter: @presenter %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/plates/sidebars/_container.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= sidebar do %>
<%= render 'logged_out_warning' %>
<%= render "plates/sidebars/#{@presenter.sidebar_partial}", presenter: @presenter %>
<% end %>
Loading
Loading