From 6b1438478040eb356be4dcc80152d3c7b3f965a4 Mon Sep 17 00:00:00 2001 From: Lan Le Date: Tue, 10 Oct 2023 10:11:06 +0200 Subject: [PATCH] fix: hide spectra button when only uploading an image (#1568) Co-authored-by: Lan Le --- .../analysesTab/ReactionDetailsContainers.js | 40 ++++++----- .../ResearchPlanDetailsContainers.js | 68 +++++++++---------- .../components/generic/EditorAnalysisBtn.js | 14 ++-- .../components/generic/GenericContainer.js | 4 +- 4 files changed, 60 insertions(+), 66 deletions(-) diff --git a/app/packs/src/apps/mydb/elements/details/reactions/analysesTab/ReactionDetailsContainers.js b/app/packs/src/apps/mydb/elements/details/reactions/analysesTab/ReactionDetailsContainers.js index c21c9051d2..94e5d04352 100644 --- a/app/packs/src/apps/mydb/elements/details/reactions/analysesTab/ReactionDetailsContainers.js +++ b/app/packs/src/apps/mydb/elements/details/reactions/analysesTab/ReactionDetailsContainers.js @@ -42,7 +42,7 @@ const nmrMsg = (reaction, container) => { }; const SpectraEditorBtn = ({ - element, spcInfo, hasJcamp, hasChemSpectra, + element, spcInfos, hasJcamp, hasChemSpectra, toggleSpectraModal, confirmRegenerate, toggleNMRDisplayerModal, hasNMRium, }) => ( @@ -50,8 +50,8 @@ const SpectraEditorBtn = ({ Spectra Editor {!spcInfo ? ': Reprocess' : ''}} - >{spcInfo ? ( + overlay={Spectra Editor {spcInfos.length > 0 ? '' : ': Reprocess'}} + >{spcInfos.length > 0 ? ( } onToggle={(open, event) => { if (event) { event.stopPropagation(); } }} onClick={toggleSpectraModal} - disabled={!spcInfo || !hasChemSpectra} + disabled={!(spcInfos.length > 0) || !hasChemSpectra} > - ) : ( - )} @@ -117,10 +117,7 @@ const SpectraEditorBtn = ({ SpectraEditorBtn.propTypes = { element: PropTypes.object, hasJcamp: PropTypes.bool, - spcInfo: PropTypes.oneOfType([ - PropTypes.object, - PropTypes.bool, - ]), + spcInfos: PropTypes.array, hasChemSpectra: PropTypes.bool, toggleSpectraModal: PropTypes.func.isRequired, confirmRegenerate: PropTypes.func.isRequired, @@ -130,7 +127,7 @@ SpectraEditorBtn.propTypes = { SpectraEditorBtn.defaultProps = { hasJcamp: false, - spcInfo: false, + spcInfos: [], element: {}, hasChemSpectra: false, hasEditedJcamp: false, @@ -223,12 +220,13 @@ export default class ReactionDetailsContainers extends Component { SpectraActions.Regenerate(jcampIds, this.handleChange); } }; - const spcInfo = BuildSpcInfos(reaction, container); + + const spcInfos = BuildSpcInfos(reaction, container); const { hasChemSpectra, hasNmriumWrapper } = UIStore.getState(); const toggleSpectraModal = (e) => { e.stopPropagation(); SpectraActions.ToggleModal(); - SpectraActions.LoadSpectra.defer(spcInfo); + SpectraActions.LoadSpectra.defer(spcInfos); }; //process open NMRium @@ -257,7 +255,7 @@ export default class ReactionDetailsContainers extends Component { ( - Spectra Editor {!spcInfo ? ': Reprocess' : ''}} - >{spcInfo ? ( - - } - onToggle={(open, event) => { if (event) { event.stopPropagation(); } }} - onClick={toggleSpectraModal} - disabled={!spcInfo || !hasChemSpectra} - > - Spectra Editor {spcInfos.length > 0 ? '' : ': Reprocess'}} + >{spcInfos.length > 0 ? ( + + } + onToggle={(open, event) => { if (event) { event.stopPropagation(); } }} + onClick={toggleSpectraModal} + disabled={!(spcInfos.length > 0) || !hasChemSpectra} + > + { @@ -52,15 +52,15 @@ const SpectraEditorBtn = ({ - ) : ( - )} @@ -88,17 +88,13 @@ const SpectraEditorBtn = ({ ) : null } - ); SpectraEditorBtn.propTypes = { element: PropTypes.object, hasJcamp: PropTypes.bool, - spcInfo: PropTypes.oneOfType([ - PropTypes.object, - PropTypes.bool, - ]), + spcInfos: PropTypes.array, hasChemSpectra: PropTypes.bool, toggleSpectraModal: PropTypes.func.isRequired, confirmRegenerate: PropTypes.func.isRequired, @@ -108,7 +104,7 @@ SpectraEditorBtn.propTypes = { SpectraEditorBtn.defaultProps = { hasJcamp: false, - spcInfo: false, + spcInfos: PropTypes.array, element: {}, hasChemSpectra: false, hasNMRium: false, @@ -194,12 +190,12 @@ export default class ResearchPlanDetailsContainers extends Component { SpectraActions.Regenerate(jcampIds, this.handleChange); } }; - const spcInfo = BuildSpcInfos(researchPlan, container); + const spcInfos = BuildSpcInfos(researchPlan, container); const { hasChemSpectra, hasNmriumWrapper } = UIStore.getState(); const toggleSpectraModal = (e) => { e.stopPropagation(); SpectraActions.ToggleModal(); - SpectraActions.LoadSpectra.defer(spcInfo); + SpectraActions.LoadSpectra.defer(spcInfos); }; //process open NMRium @@ -227,7 +223,7 @@ export default class ResearchPlanDetailsContainers extends Component { ( Spectra Editor {spcInfo.length > 0 ? ': Reprocess' : ''}} - >{spcInfo.length > 0 ? ( + overlay={Spectra Editor {spcInfos.length > 0 ? '' : ': Reprocess'}} + >{spcInfos.length > 0 ? ( } onToggle={(open, event) => { if (event) { event.stopPropagation(); } }} onClick={toggleSpectraModal} - disabled={!(spcInfo.length > 0) || !hasChemSpectra} + disabled={!(spcInfos.length > 0) || !hasChemSpectra} > @@ -55,7 +55,7 @@ const EditorAnalysisBtn = ({ EditorAnalysisBtn.propTypes = { element: PropTypes.object, hasJcamp: PropTypes.bool, - spcInfo: PropTypes.array, + spcInfos: PropTypes.array, hasChemSpectra: PropTypes.bool, toggleSpectraModal: PropTypes.func.isRequired, confirmRegenerate: PropTypes.func.isRequired, @@ -63,7 +63,7 @@ EditorAnalysisBtn.propTypes = { EditorAnalysisBtn.defaultProps = { hasJcamp: false, - spcInfo: [], + spcInfos: [], element: {}, hasChemSpectra: false, }; diff --git a/app/packs/src/components/generic/GenericContainer.js b/app/packs/src/components/generic/GenericContainer.js index 9a142da29c..dccacc1931 100644 --- a/app/packs/src/components/generic/GenericContainer.js +++ b/app/packs/src/components/generic/GenericContainer.js @@ -29,7 +29,7 @@ const headerBtnGroup = (props) => { SpectraActions.Regenerate(jcampIds, fnChange); } }; - const spcInfo = BuildSpcInfos(generic, container); + const spcInfos = BuildSpcInfos(generic, container); const { hasChemSpectra } = UIStore.getState(); const toggleSpectraModal = (e) => { SpectraActions.ToggleModal(); @@ -49,7 +49,7 @@ const headerBtnGroup = (props) => {