Skip to content

Commit

Permalink
feat: Sample types extension updates #2058
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 0c9b13a
Author: Tasnim Mehzabin <[email protected]>
Date:   Tue Aug 6 16:18:52 2024 +0200

    refactor: eslint warnings

commit 8c59c36
Author: Tasnim Mehzabin <[email protected]>
Date:   Tue Aug 6 15:45:56 2024 +0200

    feat: add density field for the solid components in mixtures

commit b3c2ef1
Author: Tasnim Mehzabin <[email protected]>
Date:   Mon Jul 29 15:59:02 2024 +0200

    feat: add tooltip text for the "Total volume" field for Mixture

commit 52ee524
Author: Tasnim Mehzabin <[email protected]>
Date:   Tue Jul 23 16:05:37 2024 +0200

    fix: fetching of components after fetching the sample causing the sample appear as edited

commit 698bcab
Author: Tasnim Mehzabin <[email protected]>
Date:   Tue Jul 23 13:42:38 2024 +0200

    fix (UI): cannot create a single molecule

commit 7b04874
Author: fathia <[email protected]>
Date:   Thu Jun 20 12:08:00 2024 +0000

    disable savebtn for mixtures with 0 components

commit ce423c4
Author: Fathia Idiris <[email protected]>
Date:   Wed Jun 19 16:49:08 2024 +0200

    fix: solvent volume column only for mixture samples

commit 514c216
Author: Fathia Idiris <[email protected]>
Date:   Wed Jun 19 15:38:20 2024 +0200

    fix: fix update ratio

commit e51a82a
Author: Fathia Idiris <[email protected]>
Date:   Wed Jun 19 09:24:45 2024 +0200

    fix: fix ratio after setting purity

commit 209d730
Author: fathia <[email protected]>
Date:   Tue Jun 18 14:28:08 2024 +0000

    feat: comp. table calculations with purity

commit 9123440
Author: fathia <[email protected]>
Date:   Tue Jun 18 08:24:27 2024 +0000

    fix: update volume of a comp with a density in reactions table.

commit d273142
Author: Fathia Idiris <[email protected]>
Date:   Mon Jun 17 16:56:42 2024 +0200

    feat: comp. table calculations handles density & add purity field

commit e58dde6
Author: fathia <[email protected]>
Date:   Tue Jun 11 07:36:04 2024 +0000

    refactor: save/update components api endpoint

commit 96014bf
Author: fathia <[email protected]>
Date:   Mon Jun 10 09:43:17 2024 +0000

    fix: blank screen with get reference molarity val

commit 97d3bdc
Author: fathia <[email protected]>
Date:   Wed Jun 5 14:23:26 2024 +0000

    fix: fix display svg image before saving sample

commit 2a374af
Author: fathia <[email protected]>
Date:   Wed Jun 5 12:21:07 2024 +0000

    feat: mixture samples in reactions scheme

commit 085c451
Author: fathia <[email protected]>
Date:   Mon Jun 3 14:19:39 2024 +0000

    refactor: enable chem identifiers & correct sample types dropdown

commit 7cbdba8
Author: fathia <[email protected]>
Date:   Mon Jun 3 14:13:38 2024 +0000

    refactor: remove add component sample button

commit d2c14cd
Author: fathia <[email protected]>
Date:   Mon Jun 3 08:43:57 2024 +0000

    feat: calculate total MW for mixtures & use in reaction table

commit 2b29fab
Author: fathia <[email protected]>
Date:   Wed May 29 07:29:23 2024 +0000

    chore: remove unused files

commit c8edca7
Author: fathia <[email protected]>
Date:   Wed May 29 07:27:22 2024 +0000

    fix rebase error

commit d51c61d
Author: fathia <[email protected]>
Date:   Wed May 29 06:37:43 2024 +0000

    fix: fix set default reference component

commit 7365ef7
Author: fathia <[email protected]>
Date:   Fri May 24 13:52:29 2024 +0000

    feat: option to merge components

commit e15e3a5
Author: fathia <[email protected]>
Date:   Thu May 16 14:29:07 2024 +0000

    fix: fix create sample for mixture & store molfile

commit 489b74b
Author: fathia <[email protected]>
Date:   Thu May 16 13:46:50 2024 +0000

    feat: allow users to adjust comp. ratios

commit 5971234
Author: fathia <[email protected]>
Date:   Wed May 15 14:19:54 2024 +0000

    refactor: rename labels and fix alignments in UI

commit 886988a
Author: fathia <[email protected]>
Date:   Mon May 13 09:24:26 2024 +0000

    fix: move component between tables

commit 75afa87
Author: fathia <[email protected]>
Date:   Fri May 10 13:56:21 2024 +0000

    feat: two tables for mixture components

commit b523999
Author: fathia <[email protected]>
Date:   Tue May 7 12:56:42 2024 +0000

    feat: add component label/name text field

commit 047300d
Author: fathia <[email protected]>
Date:   Tue May 7 07:36:49 2024 +0000

    refactor: change class name to avoid conflicts with react component

commit 1d310e3
Author: fathia <[email protected]>
Date:   Mon May 6 15:00:11 2024 +0000

    refactor: handle components in sample subclass

commit 568f0bf
Author: fathia <[email protected]>
Date:   Fri May 3 14:17:06 2024 +0000

    refactor: separate reaction materials & components

commit 9adb2c2
Author: Fathia Idiris <[email protected]>
Date:   Tue Apr 30 17:11:17 2024 +0200

    feat: switch between set amount & set conc in comp table

commit d9fef47
Author: Fathia Idiris <[email protected]>
Date:   Tue Apr 30 14:48:30 2024 +0200

    refactor: stricter validation in save/update components endpoint

commit e607ecc
Author: Fathia Idiris <[email protected]>
Date:   Fri Apr 26 16:13:35 2024 +0200

    feat: swap positions of comps in table

commit 5f7c482
Author: Fathia Idiris <[email protected]>
Date:   Thu Apr 25 17:18:21 2024 +0200

    feat: drag n drop mixture into another mixture

commit eee87e8
Author: fathia <[email protected]>
Date:   Wed Apr 24 13:59:14 2024 +0000

    chore: remove old migrations

commit 163f7f1
Author: fathia <[email protected]>
Date:   Wed Apr 24 13:39:04 2024 +0000

    feat: fetch and update components

commit 5cac26c
Author: fathia <[email protected]>
Date:   Fri Apr 19 14:30:36 2024 +0000

    refactor: remove redundant code & change names

commit 2af7955
Author: fathia <[email protected]>
Date:   Thu Apr 18 14:23:44 2024 +0000

    feat: add components fetcher and api

commit 5e2e7ca
Author: fathia <[email protected]>
Date:   Thu Apr 18 09:16:51 2024 +0000

    refactor: store components in a separate table

commit f88ab26
Author: Fathia Idiris <[email protected]>
Date:   Tue Apr 16 15:39:20 2024 +0200

    feat: update smiles when a new comp is added via dragndrop

commit d244a61
Author: fathia <[email protected]>
Date:   Mon Apr 8 14:22:29 2024 +0000

    wip: split image by SMILES and store ket file

commit 532335c
Author: Fathia Idiris <[email protected]>
Date:   Tue Apr 2 15:22:28 2024 +0200

    fix: update comp volumes when total vol is updated & fix solv ratio

commit 85fbeca
Author: Fathia Idiris <[email protected]>
Date:   Tue Apr 2 10:48:04 2024 +0200

    fix: store stock molarity of each component

commit 81e1065
Author: Fathia Idiris <[email protected]>
Date:   Thu Mar 28 16:21:49 2024 +0100

    fix: component ratio calculation

commit 8de85e7
Author: Fathia Idiris <[email protected]>
Date:   Thu Mar 28 12:31:31 2024 +0100

    Feat: calculate amount of component required from target conc & volume

commit 2f5ed9b
Author: Fathia Idiris <[email protected]>
Date:   Thu Mar 28 11:53:49 2024 +0100

    feat: add solvent volume

commit 2629781
Author: Fathia Idiris <[email protected]>
Date:   Fri Mar 22 16:49:40 2024 +0100

    fix: fix update mixture samples and re-enable inventory label

commit 99100c7
Author: Fathia Idiris <[email protected]>
Date:   Thu Mar 21 17:46:09 2024 +0100

    feat: reconstruct RXN when the components list is updated

commit 6985bb7
Author: fathia <[email protected]>
Date:   Tue Mar 19 15:29:17 2024 +0000

    WIP: new sample from img instead of subsample

commit e79a71d
Author: fathia <[email protected]>
Date:   Mon Mar 18 14:31:08 2024 +0000

    refactor: splitmolfile and combine svg fetch calls

commit 6eb1227
Author: fathia <[email protected]>
Date:   Mon Mar 18 10:43:04 2024 +0000

    fix: fix missing C-bonds and order of fetch calls

commit f27bb28
Author: fathia <[email protected]>
Date:   Thu Mar 14 15:19:03 2024 +0000

    WIP: render combined sample svg w/o reaction arrow

commit 4b10f2a
Author: fathia <[email protected]>
Date:   Thu Mar 14 10:11:34 2024 +0000

    split Ketcher 2 rxn file into subsamples

commit 2b38280
Author: fathia <[email protected]>
Date:   Tue Mar 12 15:01:21 2024 +0000

    wip: split rxn file into mixture subsamples

commit d52d94f
Author: fathia <[email protected]>
Date:   Thu Mar 7 13:45:29 2024 +0000

    refactor: separate show reaction & show mixture material

commit c4dae18
Author: fathia <[email protected]>
Date:   Wed Mar 6 13:22:28 2024 +0000

    fix: fix url when clicking on a mixture component

commit 5bd89b9
Author: fathia <[email protected]>
Date:   Tue Mar 5 14:30:54 2024 +0000

    refactor: Hide unnecessary sections, improve table alignment, display parent sample short label

commit d663196
Author: fathia <[email protected]>
Date:   Mon Mar 4 14:40:51 2024 +0000

    hide subsamples in elements list & show stock sample on click material

commit 2265fca
Author: fathia <[email protected]>
Date:   Mon Mar 4 12:26:41 2024 +0000

    refactor: add sample to mixture via add sample btn

commit 38fc91a
Author: fathia <[email protected]>
Date:   Fri Mar 1 13:33:31 2024 +0000

    fix: update sample endpoint

commit d8f9ee6
Author: fathia <[email protected]>
Date:   Fri Mar 1 10:02:05 2024 +0000

    fix: reopen mixture sample after saving

commit f1c32a1
Author: fathia <[email protected]>
Date:   Thu Feb 29 08:29:52 2024 +0000

    fix: fix create mixture comp subsamples

commit 733173c
Author: fathia <[email protected]>
Date:   Wed Feb 28 10:08:03 2024 +0000

    fix: fix save stock & add sample type name attr.

commit b1e36c4
Author: fathia <[email protected]>
Date:   Tue Feb 27 09:39:20 2024 +0000

    fix: create button enabled for mixtures with comps

commit fcd184d
Author: fathia <[email protected]>
Date:   Tue Feb 27 09:29:52 2024 +0000

    fix: new comp short label  same as mixture label

commit a86f9ce
Author: Fathia Idiris <[email protected]>
Date:   Mon Feb 26 17:01:26 2024 +0100

    do not render structure editor & cas fast input for mixtures

commit f17169f
Author: Fathia Idiris <[email protected]>
Date:   Mon Feb 26 14:56:59 2024 +0100

    fix: disable unnecessary 'dropmaterial'

commit c9ab74b
Author: fathia <[email protected]>
Date:   Fri Feb 23 13:12:34 2024 +0000

    fix: add mixture component via add sample button

commit c8e2598
Author: fathia <[email protected]>
Date:   Fri Feb 23 08:31:24 2024 +0000

    fix: remove molarity and density tooltip

commit 101c04e
Author: fathia <[email protected]>
Date:   Thu Feb 22 15:01:51 2024 +0000

    feat: component table calculations

commit 39fd089
Author: fathia <[email protected]>
Date:   Wed Feb 21 15:16:04 2024 +0000

    fix: drag and drop samples in mixture comps table

commit 8bf29bc
Author: fathia <[email protected]>
Date:   Wed Feb 21 10:32:17 2024 +0000

    handle sample type changes

commit 87769e6
Author: Fathia Idiris <[email protected]>
Date:   Mon Feb 19 16:42:49 2024 +0100

    feat: add mixture components table in UI

commit 22d229c
Author: Fathia Idiris <[email protected]>
Date:   Mon Feb 19 11:17:09 2024 +0100

    feat: add select sample type dropdown

commit 2847ecb
Author: fathia <[email protected]>
Date:   Thu Feb 15 14:40:49 2024 +0000

    save mixture comps as subsample of stock solution

commit c07885d
Author: fathia <[email protected]>
Date:   Wed Feb 14 09:41:10 2024 +0000

    update sample types after create sample

commit 34ffaea
Author: fathia <[email protected]>
Date:   Tue Feb 13 09:48:37 2024 +0000

    remove outdated migration files

commit 05599d9
Author: fathia <[email protected]>
Date:   Mon Jan 29 15:29:19 2024 +0000

    refactor: refactor sample type models

commit 93825c6
Author: fathia <[email protected]>
Date:   Tue Jan 23 14:32:05 2024 +0000

    create sample mixture and sample components

commit 47bf220
Author: fathia <[email protected]>
Date:   Tue Jan 23 10:04:59 2024 +0000

    refactor: mixtures and components model

commit 6afa120
Author: fathia <[email protected]>
Date:   Mon Jan 22 14:10:58 2024 +0000

    create micromolecule by default & move fields

commit 7783241
Author: fathia <[email protected]>
Date:   Fri Jan 19 10:03:13 2024 +0000

    refactor: refactor mixture associations

commit 06766c9
Author: fathia <[email protected]>
Date:   Thu Jan 18 15:23:10 2024 +0000

    split sample model into micromolecule and mixture

Conflicts:
	app/packs/src/apps/mydb/elements/details/NumeralInputWithUnitsCompo.js
	app/packs/src/apps/mydb/elements/details/reactions/schemeTab/ReactionDetailsScheme.js
	db/schema.rb
  • Loading branch information
PiTrem committed Aug 6, 2024
1 parent d512291 commit 78639e8
Show file tree
Hide file tree
Showing 34 changed files with 2,489 additions and 152 deletions.
1 change: 1 addition & 0 deletions app/api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def to_json_camel_case(val)
mount Chemotion::InventoryAPI
mount Chemotion::AdminDeviceAPI
mount Chemotion::AdminDeviceMetadataAPI
mount Chemotion::ComponentAPI

if Rails.env.development?
add_swagger_documentation(info: {
Expand Down
75 changes: 75 additions & 0 deletions app/api/chemotion/component_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

module Chemotion
class ComponentAPI < Grape::API
resource :components do
desc 'Return components by sample_id'
params do
requires :sample_id, type: Integer, desc: 'sample id'
end

route_param :sample_id do
get do
components = Component.where(sample_id: params[:sample_id])
components_with_molecule_data = components.map do |component|
molecule_id = component.component_properties['molecule_id']
molecule = Molecule.find_by(id: molecule_id)
component.component_properties['molecule'] = molecule
component
end
present components_with_molecule_data
end
end

desc 'Save or update components for a given sample'
params do
requires :sample_id, type: Integer, desc: 'sample id'
requires :components, type: Array, desc: 'components' do
requires :id, types: [Integer, String], desc: 'Component ID'
optional :name, type: String, desc: 'Component name'
optional :position, type: Integer, desc: 'Component position in the table'
requires :component_properties, type: Hash, desc: 'Component properties' do
optional :amount_mol, type: Float, desc: 'Component moles'
optional :amount_l, type: Float, desc: 'Component volume'
optional :amount_g, type: Float, desc: 'Component mass'
optional :density, type: Float, desc: 'Density in g/ml'
optional :molarity_unit, type: String, desc: 'Molarity unit'
optional :molarity_value, type: Float, desc: 'Molarity value'
optional :starting_molarity_value, type: Float, desc: 'Starting molarity value'
optional :starting_molarity_unit, type: String, desc: 'Starting molarity unit'
requires :molecule_id, type: Integer, desc: 'Molecule ID'
optional :equivalent, types: [Float, String], desc: 'Equivalent'
optional :parent_id, type: Integer, desc: 'Parent ID'
optional :material_group, type: String, desc: 'type of component e.g. liquid'
optional :reference, type: Boolean, desc: 'reference comp. for ratio calculations'
optional :purity, type: Float, desc: 'Component purity'
end
end
end

put do
sample_id = params[:sample_id]
components_params = params[:components]

components_params.each do |component_params|
molecule_id = component_params[:component_properties][:molecule_id]

component = Component.where("sample_id = ? AND CAST(component_properties ->> 'molecule_id' AS INTEGER) = ?",
sample_id, molecule_id)
.first_or_initialize(sample_id: sample_id)

component.update(
name: component_params[:name],
position: component_params[:position],
component_properties: component_params[:component_properties],
)
end
# Delete components
molecule_ids_to_keep = components_params.map { |cp| cp[:component_properties][:molecule_id] }.compact
Component.where(sample_id: sample_id)
.where.not("CAST(component_properties ->> 'molecule_id' AS INTEGER) IN (?)", molecule_ids_to_keep)
&.destroy_all
end
end
end
end
32 changes: 29 additions & 3 deletions app/api/chemotion/sample_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ class SampleAPI < Grape::API
optional :molecular_mass, type: Float
optional :sum_formula, type: String
# use :root_container_params
optional :sample_type, type: String, default: 'Micromolecule'
optional :sample_details, type: Hash, desc: 'extra params for mixtures or polymers'
end

route_param :id do
Expand Down Expand Up @@ -393,7 +395,14 @@ class SampleAPI < Grape::API
attributes.delete(:melting_point_lowerbound)
attributes.delete(:melting_point_upperbound)

micro_att = {
name: params[:name],
molfile: params[:molfile],
stereo: params[:stereo],
}

@sample.update!(attributes)
@sample.micromolecule&.update(micro_att)
@sample.save_segments(segments: params[:segments], current_user_id: current_user.id)

# save to profile
Expand Down Expand Up @@ -453,6 +462,8 @@ class SampleAPI < Grape::API
optional :inventory_sample, type: Boolean, default: false
optional :molecular_mass, type: Float
optional :sum_formula, type: String
optional :sample_type, type: String, default: 'Micromolecule'
optional :sample_details, type: Hash, desc: 'extra params for mixtures or polymers'
end
post do
molecule_id = if params[:decoupled] && params[:molfile].blank?
Expand All @@ -475,7 +486,6 @@ class SampleAPI < Grape::API
dry_solvent: params[:dry_solvent],
solvent: params[:solvent],
location: params[:location],
molfile: params[:molfile],
molecule_id: molecule_id,
sample_svg_file: params[:sample_svg_file],
is_top_secret: params[:is_top_secret],
Expand All @@ -484,12 +494,20 @@ class SampleAPI < Grape::API
elemental_compositions: params[:elemental_compositions],
created_by: current_user.id,
xref: params[:xref],
stereo: params[:stereo],
molecule_name_id: params[:molecule_name_id],
decoupled: params[:decoupled],
inventory_sample: params[:inventory_sample],
molecular_mass: params[:molecular_mass],
sum_formula: params[:sum_formula],
sample_type: params[:sample_type],
molfile: params[:molfile],
stereo: params[:stereo],
sample_details: params[:sample_details],
}
micro_att = {
name: params[:name],
molfile: params[:molfile],
stereo: params[:stereo],
}

boiling_point_lowerbound = (params['boiling_point_lowerbound'].presence || -Float::INFINITY)
Expand Down Expand Up @@ -543,9 +561,15 @@ class SampleAPI < Grape::API
sample.collections << all_coll
end

case params[:sample_type]
when 'Micromolecule'
micromolecule = Micromolecule.new(micro_att)
micromolecule.samples << sample
micromolecule.save!
end

sample.container = update_datamodel(params[:container])
sample.save!

sample.save_segments(segments: params[:segments], current_user_id: current_user.id)

# save to profile
Expand All @@ -566,7 +590,9 @@ class SampleAPI < Grape::API

delete do
sample = Sample.find(params[:id])
micromolecule = Micromolecule.find_by(id: sample.micromolecule_id)
sample.destroy
micromolecule&.destroy
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/api/entities/sample_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class SampleEntity < ApplicationEntity
expose! :target_amount_value, unless: :displayed_in_list
expose! :user_labels
expose! :xref
expose! :sample_type
expose! :sample_details
end
# rubocop:enable Layout/LineLength, Layout/ExtraSpacing, Metrics/BlockLength

Expand Down
5 changes: 5 additions & 0 deletions app/models/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Component < ApplicationRecord
belongs_to :sample
end
5 changes: 5 additions & 0 deletions app/models/micromolecule.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Micromolecule < ApplicationRecord
has_many :samples
end
7 changes: 5 additions & 2 deletions app/models/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ class Sample < ApplicationRecord
Sample.where(id: samples.map(&:id))
}


before_save :auto_set_molfile_to_molecules_molfile
before_save :find_or_create_molecule_based_on_inchikey
before_save :update_molecule_name
Expand Down Expand Up @@ -201,6 +200,9 @@ class Sample < ApplicationRecord
has_many :private_notes, as: :noteable, dependent: :destroy
has_many :comments, as: :commentable, dependent: :destroy

belongs_to :micromolecule, optional: true
has_many :components, dependent: :destroy

belongs_to :fingerprint, optional: true
belongs_to :user, optional: true
belongs_to :molecule_name, optional: true
Expand Down Expand Up @@ -233,6 +235,7 @@ class Sample < ApplicationRecord

delegate :computed_props, to: :molecule, prefix: true
delegate :inchikey, to: :molecule, prefix: true, allow_nil: true
delegate :molfile, :molfile_version, :stereo, to: :micromolecule, prefix: true, allow_nil: true

attr_writer :skip_reaction_svg_update

Expand Down Expand Up @@ -583,7 +586,7 @@ def set_elem_composition_data d_type, d_values, loading = nil
end

def check_molfile_polymer_section
return if decoupled
return if decoupled || sample_type == 'Mixture'
return unless self.molfile.include? 'R#'

lines = self.molfile.lines
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { FormControl, ControlLabel, InputGroup, Button } from 'react-bootstrap';
import {
FormControl, ControlLabel, InputGroup, Button, OverlayTrigger, Tooltip
} from 'react-bootstrap';
import { metPreConv, metPrefSymbols } from 'src/utilities/metricPrefix';

export default class NumeralInputWithUnitsCompo extends Component {
Expand Down Expand Up @@ -126,7 +128,7 @@ export default class NumeralInputWithUnitsCompo extends Component {

render() {
const {
bsSize, bsStyle, disabled, label, unit, name
bsSize, bsStyle, disabled, label, unit, name, showInfoTooltip
} = this.props;
const {
showString, value, metricPrefix,
Expand Down Expand Up @@ -164,6 +166,20 @@ export default class NumeralInputWithUnitsCompo extends Component {
return (
<div className={`numeric-input-unit_${this.props.unit}`}>
{labelWrap}
{showInfoTooltip && (
<OverlayTrigger
placement="top"
overlay={(
<Tooltip id="info-total-volume">
It is only a value given manually, i.e. volume by definition - not (re)calculated
</Tooltip>
)}
>
<ControlLabel style={{ marginLeft: '5px' }}>
<span className="glyphicon glyphicon-info-sign" />
</ControlLabel>
</OverlayTrigger>
)}
<InputGroup>
<FormControl
type="text"
Expand Down Expand Up @@ -216,7 +232,8 @@ NumeralInputWithUnitsCompo.propTypes = {
label: PropTypes.node,
bsSize: PropTypes.string,
bsStyle: PropTypes.string,
name: PropTypes.string
name: PropTypes.string,
showInfoTooltip: PropTypes.bool,
};

NumeralInputWithUnitsCompo.defaultProps = {
Expand All @@ -227,5 +244,6 @@ NumeralInputWithUnitsCompo.defaultProps = {
block: false,
bsSize: 'small',
bsStyle: 'default',
name: ''
name: '',
showInfoTooltip: false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ class Material extends Component {
);
}


materialLoading(material, showLoadingColumn) {
if (!showLoadingColumn) {
return false;
Expand Down Expand Up @@ -522,7 +521,7 @@ class Material extends Component {
</div>
</OverlayTrigger>
</td>

<td>
<OverlayTrigger
delay="100"
Expand Down Expand Up @@ -599,9 +598,13 @@ class Material extends Component {
}

generateMolecularWeightTooltipText(sample, reaction) {
const isProduct = reaction.products.includes(sample);
const molecularWeight = sample.decoupled ?
const isProduct = reaction.products.includes(sample)
let molecularWeight = sample.decoupled ?
(sample.molecular_mass) : (sample.molecule && sample.molecule.molecular_weight);

if (sample.sample_type === 'Mixture' && sample.reference_molecular_weight) {
molecularWeight = sample.reference_molecular_weight.toFixed(4);
}
let theoreticalMassPart = "";
if (isProduct && sample.maxAmount) {
theoreticalMassPart = `, max theoretical mass: ${Math.round(sample.maxAmount * 10000) / 10} mg`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import {
ListGroup, ListGroupItem, FormGroup, ControlLabel, FormControl,
Expand Down Expand Up @@ -27,8 +27,10 @@ import TextTemplateActions from 'src/stores/alt/actions/TextTemplateActions';
import TextTemplateStore from 'src/stores/alt/stores/TextTemplateStore';
import ElementActions from 'src/stores/alt/actions/ElementActions';
import { parseNumericString } from 'src/utilities/MathUtils';
import ComponentsFetcher from 'src/fetchers/ComponentsFetcher';
import Component from 'src/models/Component';

export default class ReactionDetailsScheme extends Component {
export default class ReactionDetailsScheme extends React.Component {
constructor(props) {
super(props);

Expand Down Expand Up @@ -106,9 +108,34 @@ export default class ReactionDetailsScheme extends Component {
splitSample.reference = false;
}

this.insertSolventExtLabel(splitSample, tagGroup, extLabel);
reaction.addMaterialAt(splitSample, null, tagMaterial, tagGroup);
this.onReactionChange(reaction, { schemaChanged: true });
if (splitSample.sample_type === 'Mixture') {
ComponentsFetcher.fetchComponentsBySampleId(srcSample.id)
.then(async components => {
const sampleComponents = components.map(component => {
const { component_properties, ...rest } = component;
const sampleData = {
...rest,
...component_properties
};
return new Component(sampleData);
});
await splitSample.initialComponents(sampleComponents);
const comp = sampleComponents.find(component => component.amount_mol > 0 && component.molarity_value > 0);
if (comp) {
splitSample.target_amount_value = comp.amount_mol / comp.molarity_value;
splitSample.target_amount_unit = 'l';
}
reaction.addMaterialAt(splitSample, null, tagMaterial, tagGroup);
this.onReactionChange(reaction, { schemaChanged: true });
})
.catch((errorMessage) => {
console.log(errorMessage);
});
} else {
this.insertSolventExtLabel(splitSample, tagGroup, extLabel);
reaction.addMaterialAt(splitSample, null, tagMaterial, tagGroup);
this.onReactionChange(reaction, { schemaChanged: true });
}
}

insertSolventExtLabel(splitSample, materialGroup, external_label) {
Expand Down
Loading

0 comments on commit 78639e8

Please sign in to comment.