Skip to content

Commit

Permalink
refactor: show conversion field by default if value exists for all pr…
Browse files Browse the repository at this point in the history
…oduct materials in reaction scheme
  • Loading branch information
adambasha0 committed Oct 29, 2024
1 parent 3f82f54 commit 1b279f8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class Material extends Component {

yieldOrConversionRate(material) {
const { reaction, displayYieldField } = this.props;
if (displayYieldField) {
if (displayYieldField === true || displayYieldField === null) {
return (
<div>
<FormControl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,14 @@ function GeneralMaterialGroup({
+ ' The conversion will not be displayed as part of the reaction scheme';
const yieldText = 'Click to switch to yield field.'
+ ' The yield will be displayed as part of the reaction scheme';
let conversionOrYield = displayYieldField;
if (displayYieldField || displayYieldField === null) {
conversionOrYield = true;
}
return (
<div>
<ToggleButton
isToggledInitial={displayYieldField}
isToggledInitial={conversionOrYield}
onToggle={switchYield}
onLabel="Yield"
offLabel="Conv."
Expand Down Expand Up @@ -365,13 +369,13 @@ SolventsMaterialGroup.propTypes = {
MaterialGroup.defaultProps = {
showLoadingColumn: false,
lockEquivColumn: false,
displayYieldField: true
displayYieldField: null
};

GeneralMaterialGroup.defaultProps = {
showLoadingColumn: false,
lockEquivColumn: false,
displayYieldField: true
displayYieldField: null
};

export { MaterialGroup, GeneralMaterialGroup, SolventsMaterialGroup };
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class ReactionDetailsScheme extends Component {
this.state = {
reaction,
lockEquivColumn: false,
displayYieldField: true,
displayYieldField: null,
cCon: false,
reactionDescTemplate: textTemplate.toJS(),
open: true,
Expand Down Expand Up @@ -139,10 +139,10 @@ export default class ReactionDetailsScheme extends Component {
this.setState({ lockEquivColumn: !lockEquivColumn });
}

switchYield() {
switchYield = (shouldDisplayYield) => {
const { displayYieldField } = this.state;
this.setState({ displayYieldField: !displayYieldField });
}
this.setState({ displayYieldField: shouldDisplayYield ?? !displayYieldField });
};

handleOnConditionSelect(eventKey) {
const { reaction } = this.props;
Expand Down Expand Up @@ -1214,6 +1214,15 @@ export default class ReactionDetailsScheme extends Component {
reaction.markSampleAsReference(refM.id);
}

if (displayYieldField === null) {
const allHaveNoConversion = reaction.products.every(
(material) => material.conversion_rate && material.conversion_rate !== 0
);
if (allHaveNoConversion) {
this.switchYield(!allHaveNoConversion);
}
}

const headReactants = reaction.starting_materials.length ?? 0;
return (
<div>
Expand Down
6 changes: 5 additions & 1 deletion app/packs/src/components/common/ToggleButton.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { Button, OverlayTrigger, Tooltip } from 'react-bootstrap';
import PropTypes from 'prop-types';

Expand All @@ -15,6 +15,10 @@ export default function ToggleButton({
if (onChange) onChange(newToggledState);
};

useEffect(() => {
setIsToggled(isToggledInitial);
}, [isToggledInitial]);

const buttonColor = isToggled ? onColor : offColor;
const toolTipMessage = isToggled ? tooltipOn : tooltipOff;

Expand Down

0 comments on commit 1b279f8

Please sign in to comment.