From 97192d3bf09d9bb2cae50fabdf882dfce3a66307 Mon Sep 17 00:00:00 2001 From: Tasnim Mehzabin Date: Wed, 14 Aug 2024 16:18:43 +0200 Subject: [PATCH] feat: change component table for liquid components when volume given, calculate the amount when amount is given, calculate the volume handle the calculation when the starting conc. or density being locked recalculate the entire row when starting conc. or density is updated except total concentration, the reference, and the ratio test: add test codes for Component model --- .../samples/propertiesTab/SampleComponent.js | 54 ++- .../propertiesTab/SampleComponentsGroup.js | 48 +-- .../propertiesTab/SampleDetailsComponents.js | 21 +- .../samples/propertiesTab/SampleForm.js | 44 ++- app/packs/src/models/Component.js | 206 ++++++----- app/packs/src/models/_Component.js | 346 ++++++++++++++++++ .../packs/src/models/Component.spec.js | 168 +++++++++ 7 files changed, 713 insertions(+), 174 deletions(-) create mode 100644 app/packs/src/models/_Component.js create mode 100644 spec/javascripts/packs/src/models/Component.spec.js diff --git a/app/packs/src/apps/mydb/elements/details/samples/propertiesTab/SampleComponent.js b/app/packs/src/apps/mydb/elements/details/samples/propertiesTab/SampleComponent.js index f4888613ce..29f3d0c569 100644 --- a/app/packs/src/apps/mydb/elements/details/samples/propertiesTab/SampleComponent.js +++ b/app/packs/src/apps/mydb/elements/details/samples/propertiesTab/SampleComponent.js @@ -87,16 +87,16 @@ class SampleComponent extends Component { handleAmountChange(e, value, concType, lockColumn) { if (e.value === value) return; + const { materialGroup } = this.props; if (this.props.onChange && e) { const event = { amount: e, type: 'amountChanged', - materialGroup: this.props.materialGroup, + materialGroup, sampleID: this.componentId(), concType, - updateVolume: !lockColumn, - + lockColumn, }; this.props.onChange(event); } @@ -111,8 +111,7 @@ class SampleComponent extends Component { type: 'densityChanged', materialGroup: this.props.materialGroup, sampleID: this.componentId(), - updateVolume: lockColumn, - + lockColumn, }; this.props.onChange(event); } @@ -209,16 +208,14 @@ class SampleComponent extends Component { handleRatioChange(e, value) { if (e.value === value) return; - const adjustAmount = this.props.materialGroup === 'liquid' ? this.props.lockAmountColumn : this.props.lockAmountColumnSolids; + const { materialGroup } = this.props; if (this.props.onChange && e) { const event = { newRatio: e.value, type: 'ratioChanged', sampleID: this.componentId(), - materialGroup: this.props.materialGroup, - adjustAmount, - + materialGroup, }; this.props.onChange(event); } @@ -247,7 +244,7 @@ class SampleComponent extends Component { if (material.contains_residues) { return notApplicableInput(); } const { - sample, lockAmountColumn, enableComponentLabel, enableComponentPurity + sample, enableComponentLabel, enableComponentPurity } = this.props; const metricPrefixes = ['m', 'n', 'u']; const metric = (material.metrics && material.metrics.length > 2 && metricPrefixes.indexOf(material.metrics[1]) > -1) ? material.metrics[1] : 'm'; @@ -263,7 +260,7 @@ class SampleComponent extends Component { metricPrefix={metric} metricPrefixes={metricPrefixes} precision={3} - disabled={!permitOn(sample) || lockAmountColumn} + disabled={!permitOn(sample)} onChange={(e) => this.handleAmountChange(e, material.amount_l)} onMetricsChange={this.handleMetricsChange} bsStyle={material.amount_unit === 'l' ? 'success' : 'default'} @@ -302,9 +299,8 @@ class SampleComponent extends Component { componentMol(material, metricMol, metricPrefixesMol) { const { - sample, materialGroup, lockAmountColumn, lockAmountColumnSolids, enableComponentLabel, enableComponentPurity + sample, enableComponentLabel, enableComponentPurity } = this.props; - const lockColumn = materialGroup === 'liquid' ? lockAmountColumn : lockAmountColumnSolids; return ( this.handleAmountChange(e, material.amount_mol)} onMetricsChange={this.handleMetricsChange} bsStyle={material.amount_unit === 'mol' ? 'success' : 'default'} @@ -327,10 +323,7 @@ class SampleComponent extends Component { } componentConc(material, metricMolConc, metricPrefixesMolConc) { - const { - materialGroup, lockAmountColumn, lockAmountColumnSolids, sample - } = this.props; - const lockColumn = materialGroup === 'liquid' ? lockAmountColumn : lockAmountColumnSolids; + const { sample } = this.props; return ( this.handleAmountChange(e, material.concn, 'targetConc', lockColumn)} + disabled={!permitOn(sample)} + onChange={(e) => this.handleAmountChange(e, material.concn, 'targetConc')} onMetricsChange={this.handleMetricsChange} /> @@ -349,7 +342,8 @@ class SampleComponent extends Component { } componentStartingConc(material, metricMolConc, metricPrefixesMolConc) { - const lockColumn = this.props.materialGroup === 'liquid' ? this.props.lockAmountColumn : this.props.lockAmountColumnSolids; + const { sample, lockAmountColumn } = this.props; + return ( this.handleAmountChange(e, material.startingConc, 'startingConc', lockColumn)} + disabled={!permitOn(sample) || lockAmountColumn} + onChange={(e) => this.handleAmountChange(e, material.startingConc, 'startingConc', lockAmountColumn)} onMetricsChange={this.handleMetricsChange} /> @@ -383,7 +377,11 @@ class SampleComponent extends Component { } componentDensity(material) { - const lockColumn = this.props.materialGroup === 'liquid' ? this.props.lockAmountColumn : this.props.lockAmountColumnSolids; + const { + sample, materialGroup, lockAmountColumn, lockAmountColumnSolids + } = this.props; + const lockColumn = materialGroup === 'liquid' ? lockAmountColumn : lockAmountColumnSolids; + return ( this.handleDensityChange(e, material.density, lockColumn)} /> @@ -435,9 +433,8 @@ class SampleComponent extends Component { - {this.componentStartingConc(material, metricMolConc, metricPrefixesMolConc)} - - {this.componentDensity(material)} + {activeTab === 'concentration' && this.componentStartingConc(material, metricMolConc, metricPrefixesMolConc)} + {activeTab === 'density' && this.componentDensity(material)} {this.materialVolume(material)} @@ -606,6 +603,7 @@ export default compose( )(SampleComponent); SampleComponent.propTypes = { + sample: PropTypes.object.isRequired, material: PropTypes.instanceOf(Sample).isRequired, materialGroup: PropTypes.string.isRequired, deleteMaterial: PropTypes.func.isRequired, diff --git a/app/packs/src/apps/mydb/elements/details/samples/propertiesTab/SampleComponentsGroup.js b/app/packs/src/apps/mydb/elements/details/samples/propertiesTab/SampleComponentsGroup.js index a7f674849e..104eff2d51 100644 --- a/app/packs/src/apps/mydb/elements/details/samples/propertiesTab/SampleComponentsGroup.js +++ b/app/packs/src/apps/mydb/elements/details/samples/propertiesTab/SampleComponentsGroup.js @@ -67,13 +67,19 @@ const SampleComponentsGroup = ({ const switchAmountTooltip = () => ( - Lock/unlock amounts
(mass/volume/mol) + + Lock/unlock amounts + + + (mass/stock/density) +
); const SwitchAmountButton = (lockAmountColumn, switchAmount, materialGroup) => (