-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat: Incorporate "Gas Scheme" feature in reaction variations table #2250
base: main
Are you sure you want to change the base?
Conversation
@@ -60,23 +60,25 @@ def variations | |||
'startingMaterials' => variation_materials(var, :startingMaterials), | |||
'reactants' => variation_materials(var, :reactants), | |||
'solvents' => variation_materials(var, :solvents), | |||
'products' => variation_products(var), | |||
'products' => variation_materials(var, :products), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/ClassLength: Class has too many lines. [626/200]
(v[:aux][:isReference] ? '; Ref' : '') | ||
end | ||
end | ||
variation[type].map do |_, vi| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/CyclomaticComplexity: Cyclomatic complexity for variation_materials is too high. [8/7]
LCOV of commit
|
807bd3d
to
2efc953
Compare
LCOV of commit
|
2efc953
to
c02afd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Jan, Thanks for the feature. I posted some suggestions and potential bug that you can check later.
db/schema.rb
Outdated
@@ -10,7 +10,7 @@ | |||
# | |||
# It's strongly recommended that you check this file into your version control system. | |||
|
|||
ActiveRecord::Schema.define(version: 2024_07_26_064022) do | |||
ActiveRecord::Schema.define(version: 2024_11_29_093956) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the timestamp change needed in this PR? - updating the timestamp might seem unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the timestamp is meant to ensure that we run the migration that's necessary for this PR to work.
See db/migrate/20241129093956_add_gas_materials_to_reaction_variations.rb
.
variations.each do |variation| | ||
SAMPLES_TYPES.each do |key| | ||
variation[key].each_value do |material| | ||
material['aux'].delete('materialType') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
many repeated code in this block, especially: material.delete
suggestion: combine all keys to be deleted in one array and loop over the array to delete elements in a separate method
keys_to_delete = %w[duration temperature concentration turnoverNumber turnoverFrequency]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like a one-off migration is not the place to save LOC.
In this case I believe it doesn't hurt to keep the code explicit.
end | ||
|
||
class AddGasMaterialsToReactionVariations < ActiveRecord::Migration[6.1] | ||
def up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure what these migrations are used for, especially the down migration. can you explain the design concept here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration is modifying the variations
column of the reaction table.
Note that the migration does not add or remove columns in the table.
Instead it updates the existing data in the variations
column to accommodate the gas feature.
Accommodating the gas feature consists of adding new entries to materials (such as aux.gasType
).
It also means some restructuring of the materials' data to make the overall data structure more uniform.
The down migration undoes all changes related to the gas feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how did it exist at the first place? - the gas phase feature was not there before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I don't understand the question. What's "it" referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how come these attributes (such as: turnoverFrequency, turnoverNumber, concentration, temperature, duration, and gasType) are deleted from the reactions variations, if there are not supposed to be there at the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The attributes related to the gas feature are deleted in the down
migration because the down
migration is reverting the up
migration where they're added.
material.delete('duration') | ||
material.delete('temperature') | ||
material.delete('concentration') | ||
material.delete('turnoverNumber') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it better to adhere to ruby's standard naming convention about using snake case and also to match the attribute names in the the gas_phase_data column in reactions_samples table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reaction-variations data-structure is exclusively handled on the client (JS) side, that's why I stuck with camelCase.
@@ -27,158 +27,182 @@ | |||
variations: [{ id: '1', | |||
analyses: [1, 2], | |||
notes: '', | |||
products: { '47': { aux: { yield: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it would be nice to have factory reaction_with_variations defined in factories/reactions.rb. This would make it easier to create reactions with variations consistently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I avoided doing this so far tbh. See bf86a76.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, good. Did I miss the utilization of reaction_with_variations to test the functionality of updating a value or unit (e.g., in the gas phase) and verifying the recalculation of affected material values or units? Additionally, do we have a validation mechanism in the backend to ensure the accuracy of values submitted from the client to the server before they are saved in the database?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did I miss the utilization of reaction_with_variations to test the functionality of updating a value or unit (e.g., in the gas phase) and verifying the recalculation of affected material values or units?
Do the tests under spec/javascripts/packs/src/apps/mydb/elements/details/reactions/variationsTab/
cover what you have in mind?
ensure the accuracy of values submitted from the client to the server before they are saved in the database?
What do you mean with "accuracy"?
} | ||
|
||
function MaterialFormatter({ value: cellData, colDef }) { | ||
const { currentEntry, displayUnit } = colDef.entryDefs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c02afd0
to
bf86a76
Compare
@@ -60,23 +60,25 @@ def variations | |||
'startingMaterials' => variation_materials(var, :startingMaterials), | |||
'reactants' => variation_materials(var, :reactants), | |||
'solvents' => variation_materials(var, :solvents), | |||
'products' => variation_products(var), | |||
'products' => variation_materials(var, :products), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/ClassLength: Class has too many lines. [627/200]
LCOV of commit
|
bf86a76
to
90944aa
Compare
(v[:aux][:isReference] ? '; Ref' : '') | ||
end | ||
end | ||
variation[type].map do |_, vi| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/CyclomaticComplexity: Cyclomatic complexity for variation_materials
is too high. [8/7]
LCOV of commit
|
LCOV of commit
|
Chemotion.dev.13.webm |
Chemotion.dev.14.webm |
Chemotion.dev.15.webm |
sometimes there is miscalculations: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The review comment pertaining to Chemotion.dev.13.webm
and Chemotion.dev.14.webm
is:
"when I tried to change the value mmol of feedstock, it did not get changed (sometimes change happens, sometimes not)"
The sorting is enabled for the column that's being changed.
This is why the edited row shifts as soon as the edit is concluded.
Observe how the row IDs shift as soon as the cell edit is concluded.
Unrelated to (but inspired by) the review comment, I observed that the column sorting is in lexicographic order (1, 10, 2), not, as expected in numeric order (1, 2, 10).
I changed the sorting from lexicographic to numeric in 126d6b5.
Hi Jan, thanks for the feedback. I did not notice this. could you provide some info about the arrows and x buttons made for the order functionality on hover over? .. it is not clear to the user what are these buttons expected to d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The review comment pertaining to Chemotion.dev.15.webm
is:
"When I select one field in a column, and then click on a column header to switch the header >> this leads to false behavior where the initial field value is intact and shown for the wrong column header. Also clicking somewhere else in the table leads to an error"
I fixed the problem in d97c2c6 according to https://www.ag-grid.com/react-data-grid/cell-editing-start-stop/#stop-editing-when-grid-loses-focus.
styling issues: happens on reload of the page |
Fixed with 52ad4e1. |
In conversation with @adambasha0, we identified the missing calculation: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adambasha0, I've fixed all functional problems you've pointed out, thanks for the thorough review! I'll defer all request regarding styling to the next round of "cosmetic" updates to not bloat this PR any further.
The example of the reaction variations data structure is unnecessarily verbose and prone to be outdated.
Prior to this commit the formatters returned strings, which caused sorting to be in lexicographic, not, as expected, in numeric order.
f72fa0a
to
52ad4e1
Compare
This PR addresses #2213.
See also https://docs.google.com/document/d/1Jd6V5zqRv0cfw_xAJE-oHDYzSuBMQyBBz3wQQBxRGJo/edit and https://www.chemotion.net/docs/eln/ui/elements/reactions?_highlight=gas#gas-phase-reaction-scheme.
The review is partly conducted here: https://docs.google.com/document/d/1b9zMBb4yf_we1B7tal7MAS4FlZtWq_urM-8tuvUA-8Q/edit?tab=t.0.