diff --git a/app/packs/src/apps/mydb/elements/details/reactions/schemeTab/Material.js b/app/packs/src/apps/mydb/elements/details/reactions/schemeTab/Material.js index 0974905f8b..8f2f8432b8 100644 --- a/app/packs/src/apps/mydb/elements/details/reactions/schemeTab/Material.js +++ b/app/packs/src/apps/mydb/elements/details/reactions/schemeTab/Material.js @@ -279,7 +279,7 @@ class Material extends Component { yieldOrConversionRate(material) { const { reaction, displayYieldField } = this.props; - if (displayYieldField) { + if (displayYieldField === true || displayYieldField === null) { return (
{ const { displayYieldField } = this.state; - this.setState({ displayYieldField: !displayYieldField }); - } + this.setState({ displayYieldField: shouldDisplayYield ?? !displayYieldField }); + }; handleOnConditionSelect(eventKey) { const { reaction } = this.props; @@ -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 (
diff --git a/app/packs/src/components/common/ToggleButton.js b/app/packs/src/components/common/ToggleButton.js index 8e8a873c5f..b66b991c01 100644 --- a/app/packs/src/components/common/ToggleButton.js +++ b/app/packs/src/components/common/ToggleButton.js @@ -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'; @@ -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;