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-190-3: Use SS v2 for TagLayoutTemplates #1835

Merged
merged 19 commits into from
Aug 8, 2024

Conversation

sdjmchattie
Copy link
Contributor

Closes #1818

Changes proposed in this pull request

  • Switch to using SS v2 for TagLayoutTemplate
  • There is one remaining instance of v1 used for TagLayoutTemplate which I have been unable to work around yet. I plan to fix this by also implementing TagLayout in SS v2 and then I can push the creation through the correct endpoint.

Instructions for Reviewers

[All PRs] - Confirm PR template filled
[Feature Branches] - Review code

Copy link

codecov bot commented Aug 6, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.47%. Comparing base (e0a87c9) to head (98fa7a1).
Report is 201 commits behind head on develop-Y24-190.

Files Patch % Lines
...escape/sequencescape/api/v2/tag_layout_template.rb 91.66% 2 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           develop-Y24-190    #1835      +/-   ##
===================================================
+ Coverage            91.40%   91.47%   +0.06%     
===================================================
  Files                  377      379       +2     
  Lines                 7657     7763     +106     
===================================================
+ Hits                  6999     7101     +102     
- Misses                 658      662       +4     
Flag Coverage Δ
javascript 93.72% <ø> (+0.06%) ⬆️
pull_request 91.44% <92.85%> (?)
push 91.40% <92.85%> (+<0.01%) ⬆️
ruby 91.16% <92.85%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@KatyTaylor KatyTaylor left a comment

Choose a reason for hiding this comment

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

Looks good I think, just a couple of questions.

#### Request stubbing for the Sequencescape v2 API

The V2 API uses `JsonApiClient::Resource` sub-classes to represent the records in memory.
Generally these are quite dynamic so you don't need to explicitly specify every property the API will respond with.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for writing this documentation.

Generally these are quite dynamic so you don't need to explicitly specify every property the API will respond with.

Not quite sure what this sentence means. How will the record have the property if you haven't specified it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Magic. Basically the resources mostly look like this:

# frozen_string_literal: true

class Sequencescape::Api::V2::Project < Sequencescape::Api::V2::Base
end

but even so, that's just a template for the client gem to know that it should load a resource from that endpoint and the attributes from the API will be available to you when you use this class. They are dynamically assigned.

The exception is for relationships. If the API supports a resource having associated other resources, you do need to specify has_one, has_many etc in order for it to make those accessible via the client gem.

You can also add custom logic to these, like I did for TagLayoutTemplate, so you can change the named algorithms into implementations of that algorithm on the Limber side.

# TODO: {Y24-190} Work out a way to call the `create!` method on TagLayoutTemplate model in Sequencescape
# using the V2 API. I think either we need to misuse the PATCH method with some kind of
# attributes telling Sequencescape to run the `create!` method, or we need to create a new
# endpoint associated with a TagLayoutTemplate that will run the `create!` method.
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought you were planning to redesign it so that you could call create! on TagLayout instead, and that pulled info from the TagLayoutTemplate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but we don't have TagLayout in V2 yet. I plan to do that in a soon pull request. This comment was written before we came across that solution. I'm not sure it's worth updating since it's coming out in the next week.

extend("limber/tag_layout_template/walk_#{walking_by.gsub(/\s+/, '_')}".camelize.constantize)
rescue NameError => e
Rails.logger.warn("Unrecognised layout options: #{e.message}")
extend Unsupported
Copy link
Contributor

Choose a reason for hiding this comment

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

So this method and the one below are taken from the existing app > models > limber > tag_layout_template.rb file... is that file needed any more?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm leaving removal of V1 until the end. It's still unclear how tightly tied they are into the system and I do still need it until we remove the TODO items.

sequence(:name) { |index| "TagGroup#{index}" }
tags { v2_tags.map { |t| { index: t.map_id, oligo: t.oligo } } }
Copy link
Contributor

Choose a reason for hiding this comment

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

So v2_tags get passed into this factory as instances of Sequencescape::Api::V2::Tag, but this data structure seems to change them into a simple hash? Is that how it appears in real API results too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I wouldn't have done it this way as it's not how V1 works, but the V2 endpoint was pre-existing with this and if I change it, who knows what else might break.

One of the biggest (and possibly least obvious) issues with APIs is that they're even harder to change than other aspects of systems. You're setting up a contract with people outside your team's scope for how they can interface with your application. Making decisions about API implementations should never be taken lightly. Deploying a bad decision has to be maintained until the next version of the API.

@sdjmchattie sdjmchattie merged commit 4fc7eeb into develop-Y24-190 Aug 8, 2024
8 checks passed
@sdjmchattie sdjmchattie deleted the Y24-190-3-use-ss-v2-for-labware-creators branch August 8, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants