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-051 hide pool tab if not relevant #2189

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions app/models/presenters/minimal_stock_plate_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
# frozen_string_literal: true

module Presenters
# A stock plate presenter is used for plates just entering the pipeline.
# It shows a preview of the plate, but prevents well failure and state changes.
# In addition it also detects common scenarios which may indicate problems
# with the submission.
# State of stock plates is a little complicated currently, as it can't depend
# on transfer requests into the plate. As a result, wells on stock plates may
# have a state of 'unknown.' As a result, stock wells inherit their styling
# from the plate itself.
#
# This minimal version has a simpler GUI with fewer tabs.
class MinimalStockPlatePresenter < MinimalPlatePresenter
include Presenters::StockBehaviour

# Determine if we should display the pooling tab in the Presenter views
# See partial _common_tabbed_pages.html.erb
def show_pooling_tab?
# do not show the pooling tab for stock plates
false

Check warning on line 21 in app/models/presenters/minimal_stock_plate_presenter.rb

View check run for this annotation

Codecov / codecov/patch

app/models/presenters/minimal_stock_plate_presenter.rb#L21

Added line #L21 was not covered by tests
end
end
end
25 changes: 24 additions & 1 deletion app/models/presenters/plate_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ class PlatePresenter

class_attribute :aliquot_partial, :allow_well_failure_in_states, :style_class, :samples_partial

POOLING_TAB_PATH = 'plates/pooling_tab'

self.summary_partial = 'labware/plates/standard_summary'
self.aliquot_partial = 'standard_aliquot'
self.pooling_tab = 'plates/pooling_tab'
self.samples_partial = 'plates/samples_tab'

# Initializes `summary_items` with a hash mapping display names to their corresponding plate attributes.
Expand Down Expand Up @@ -156,6 +157,22 @@ def qc_thresholds
@qc_thresholds ||= Presenters::QcThresholdPresenter.new(labware, purpose_config.fetch(:qc_thresholds, {}))
end

# Determine if we should display the pooling tab in the Presenter views
# See partial _common_tabbed_pages.html.erb
def show_pooling_tab?
# if pooling_tab field is present, show the tab (allows override)
return true if pooling_tab.present?

# if the labware has a multiplexing submission order, show the pooling tab
if labware_is_multiplexed
self.pooling_tab = POOLING_TAB_PATH
return true
end

# do not show the pooling tab by default
false
end

private

def libraries_passable?
Expand All @@ -175,6 +192,12 @@ def number_of_filled_wells
def passable_request_types
wells.flat_map { |well| well.requests_in_progress.select(&:passable?).map(&:request_type_key) }
end

# This is determined in Sequencescape by accessing the submission orders and checking if any of them are
# multiplexed
def labware_is_multiplexed
@labware_is_multiplexed ||= labware.active_requests.map(&:submission).uniq&.first&.multiplexed? || false
end
end
# rubocop:enable Metrics/ClassLength
end
11 changes: 11 additions & 0 deletions app/models/presenters/presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ def child_assets
nil
end

# Determine if we should display the pooling tab in the Presenter views
# See partial _common_tabbed_pages.html.erb
# Overridden in the PlatePresenter
def show_pooling_tab?
# if pooling_tab field is present, show the tab (allows override)
return true if pooling_tab.present?

# do not show the pooling tab by default
false
end

private

def active_pipelines
Expand Down
7 changes: 7 additions & 0 deletions app/models/presenters/stock_plate_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@

validates_with Validators::SuboptimalValidator
validates_with Validators::ActiveRequestValidator

# Determine if we should display the pooling tab in the Presenter views
# See partial _common_tabbed_pages.html.erb
def show_pooling_tab?
# do not show the pooling tab for stock plates
false

Check warning on line 28 in app/models/presenters/stock_plate_presenter.rb

View check run for this annotation

Codecov / codecov/patch

app/models/presenters/stock_plate_presenter.rb#L28

Added line #L28 was not covered by tests
end
end
end
3 changes: 2 additions & 1 deletion app/sequencescape/sequencescape/api/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ def self.minimal_labware_by_barcode(barcode, select: :uuid)
end

# sample_description added into includes here for use in bioscan plate label creation
# multiplexed? added into includes here is used for deciding if the pooling tab should be shown
def self.plate_for_presenter(query)
Plate
.includes(*PLATE_PRESENTER_INCLUDES)
.select(
submissions: 'lanes_of_sequencing',
submissions: %w[lanes_of_sequencing multiplexed?],
sample_metadata: %w[sample_common_name collected_by sample_description]
)
.find(query)
Expand Down
1 change: 1 addition & 0 deletions app/sequencescape/sequencescape/api/v2/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Sequencescape::Api::V2::Submission < Sequencescape::Api::V2::Base
property :created_at, type: :time
property :updated_at, type: :time
property :lanes_of_sequencing, type: :integer
property :multiplexed?, type: :boolean

delegate :building?, :pending?, :processing?, :ready?, :failed?, :cancelled?, to: :state

Expand Down
4 changes: 2 additions & 2 deletions app/views/plates/_common_tabbed_pages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<li class="nav-item">
<a class="nav-link" href="#relatives_tab" data-toggle="tab" role="tab" data-plate-view="pools-view">Relatives</a>
</li>
<% if @presenter.pooling_tab.present? %>
<% if @presenter.show_pooling_tab? %>
<li class="nav-item">
<a class="nav-link" href="#pooling_tab" data-toggle="tab" role="tab" data-plate-view="pools-view">Pooling</a>
</li>
Expand All @@ -30,7 +30,7 @@
<div class="tab-pane active" id='summary_tab' role="tabpanel">
<%= render partial: 'summary', locals: { presenter: presenter } %>
</div>
<% if @presenter.pooling_tab.present? %>
<% if @presenter.show_pooling_tab? %>
<div class="tab-pane" id='pooling_tab' role="tabpanel">
<%= render partial: @presenter.pooling_tab, locals: { plate_presenter: presenter } %>
</div>
Expand Down
67 changes: 67 additions & 0 deletions spec/models/presenters/plate_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,73 @@
end
end

context 'showing the pooling tab' do
let(:request1) { double('Request', submission: submission1) }
let(:request2) { double('Request', submission: submission2) }
let(:submission1) { double('Submission', multiplexed?: true) }
let(:submission2) { double('Submission', multiplexed?: false) }

describe '#show_pooling_tab?' do
context 'when pooling_tab in the presenter has a value' do
it 'returns true' do
presenter.pooling_tab = 'some_value'
expect(presenter.show_pooling_tab?).to be true
end
end

context 'when labware has a multiplexing submission order' do
before { allow(labware).to receive(:active_requests).and_return([request1, request2]) }

it 'returns true and sets pooling_tab' do
expect(presenter.show_pooling_tab?).to be true
expect(presenter.pooling_tab).to eq('plates/pooling_tab')
end
end

context 'when labware does not have a multiplexing submission order' do
before { allow(labware).to receive(:active_requests).and_return([request2]) }

it 'returns false' do
expect(presenter.show_pooling_tab?).to be false
end
end

context 'when labware has no active requests' do
before { allow(labware).to receive(:active_requests).and_return([]) }

it 'returns false' do
expect(presenter.show_pooling_tab?).to be false
end
end
end

describe '#labware_is_multiplexed' do
context 'when labware has active requests with multiplexed submissions' do
before { allow(labware).to receive(:active_requests).and_return([request1, request2]) }

it 'returns true' do
expect(presenter.send(:labware_is_multiplexed)).to be true
end
end

context 'when labware has active requests with non-multiplexed submissions' do
before { allow(labware).to receive(:active_requests).and_return([request2]) }

it 'returns false' do
expect(presenter.send(:labware_is_multiplexed)).to be false
end
end

context 'when labware has no active requests' do
before { allow(labware).to receive(:active_requests).and_return([]) }

it 'returns false' do
expect(presenter.send(:labware_is_multiplexed)).to be false
end
end
end
end

context 'where the cycles differs from the default' do
let(:warnings) { { 'pcr_cycles_not_in' => ['6'] } }

Expand Down
28 changes: 28 additions & 0 deletions spec/models/presenters/presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Presenters::Presenter, type: :model do
# Presenter is a module so we need a dummy class
let(:dummy_class) { Class.new { include Presenters::Presenter } }

let(:presenter) { dummy_class.new }

describe '#show_pooling_tab?' do
context 'when pooling_tab in the presenter has a value' do
before { presenter.pooling_tab = 'some_value' }

it 'returns true' do
expect(presenter.show_pooling_tab?).to be true
end
end

context 'when pooling_tab in the presenter has no value' do
before { presenter.pooling_tab = '' }

it 'returns false' do
expect(presenter.show_pooling_tab?).to be false
end
end
end
end
2 changes: 1 addition & 1 deletion spec/sequencescape/api/v2/plate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
query: {
fields: {
sample_metadata: 'sample_common_name,collected_by,sample_description',
submissions: 'lanes_of_sequencing'
submissions: 'lanes_of_sequencing,multiplexed?'
},
filter: {
uuid: '8681e102-b737-11ec-8ace-acde48001122'
Expand Down
Loading