Skip to content

Commit

Permalink
fix: hide spectra button when only uploading an image (#1568)
Browse files Browse the repository at this point in the history
Co-authored-by: Lan Le <[email protected]>
  • Loading branch information
baolanlequang and Lan Le authored Oct 10, 2023
1 parent 10ef1f1 commit 6b14384
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ const nmrMsg = (reaction, container) => {
};

const SpectraEditorBtn = ({
element, spcInfo, hasJcamp, hasChemSpectra,
element, spcInfos, hasJcamp, hasChemSpectra,
toggleSpectraModal, confirmRegenerate,
toggleNMRDisplayerModal, hasNMRium,
}) => (
<span>
<OverlayTrigger
placement="bottom"
delayShow={500}
overlay={<Tooltip id="spectra">Spectra Editor {!spcInfo ? ': Reprocess' : ''}</Tooltip>}
>{spcInfo ? (
overlay={<Tooltip id="spectra">Spectra Editor {spcInfos.length > 0 ? '' : ': Reprocess'}</Tooltip>}
>{spcInfos.length > 0 ? (
<ButtonGroup className="button-right">
<SplitButton
id="spectra-editor-split-button"
Expand All @@ -61,7 +61,7 @@ const SpectraEditorBtn = ({
title={<i className="fa fa-area-chart" />}
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleSpectraModal}
disabled={!spcInfo || !hasChemSpectra}
disabled={!(spcInfos.length > 0) || !hasChemSpectra}
>
<MenuItem
id="regenerate-spectra"
Expand All @@ -76,15 +76,15 @@ const SpectraEditorBtn = ({
</MenuItem>
</SplitButton>
</ButtonGroup>
) : (
<Button
bsStyle="warning"
bsSize="xsmall"
className="button-right"
onClick={confirmRegenerate}
disabled={false}
>
<i className="fa fa-area-chart" /><i className="fa fa-refresh " />
) : (
<Button
bsStyle="warning"
bsSize="xsmall"
className="button-right"
onClick={confirmRegenerate}
disabled={!hasJcamp || !element.can_update || !hasChemSpectra}
>
<i className="fa fa-area-chart" /><i className="fa fa-refresh " />
</Button>
)}
</OverlayTrigger>
Expand Down Expand Up @@ -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,
Expand All @@ -130,7 +127,7 @@ SpectraEditorBtn.propTypes = {

SpectraEditorBtn.defaultProps = {
hasJcamp: false,
spcInfo: false,
spcInfos: [],
element: {},
hasChemSpectra: false,
hasEditedJcamp: false,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -257,7 +255,7 @@ export default class ReactionDetailsContainers extends Component {
<SpectraEditorBtn
element={reaction}
hasJcamp={hasJcamp}
spcInfo={spcInfo}
spcInfos={spcInfos}
hasChemSpectra={hasChemSpectra}
toggleSpectraModal={toggleSpectraModal}
confirmRegenerate={confirmRegenerate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ import NMRiumDisplayer from 'src/components/nmriumWrapper/NMRiumDisplayer';
import TextTemplateActions from 'src/stores/alt/actions/TextTemplateActions';

const SpectraEditorBtn = ({
element, spcInfo, hasJcamp, hasChemSpectra,
element, spcInfos, hasJcamp, hasChemSpectra,
toggleSpectraModal, confirmRegenerate,
toggleNMRDisplayerModal, hasNMRium,
}) => (
<span>
<OverlayTrigger
placement="bottom"
delayShow={500}
overlay={<Tooltip id="spectra">Spectra Editor {!spcInfo ? ': Reprocess' : ''}</Tooltip>}
>{spcInfo ? (
<ButtonGroup className="button-right">
<SplitButton
id="spectra-editor-split-button"
pullRight
bsStyle="info"
bsSize="xsmall"
title={<i className="fa fa-area-chart" />}
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleSpectraModal}
disabled={!spcInfo || !hasChemSpectra}
>
<MenuItem
<OverlayTrigger
placement="bottom"
delayShow={500}
overlay={<Tooltip id="spectra">Spectra Editor {spcInfos.length > 0 ? '' : ': Reprocess'}</Tooltip>}
>{spcInfos.length > 0 ? (
<ButtonGroup className="button-right">
<SplitButton
id="spectra-editor-split-button"
pullRight
bsStyle="info"
bsSize="xsmall"
title={<i className="fa fa-area-chart" />}
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleSpectraModal}
disabled={!(spcInfos.length > 0) || !hasChemSpectra}
>
<MenuItem
id="regenerate-spectra"
key="regenerate-spectra"
onSelect={(eventKey, event) => {
Expand All @@ -52,15 +52,15 @@ const SpectraEditorBtn = ({
</MenuItem>
</SplitButton>
</ButtonGroup>
) : (
<Button
bsStyle="warning"
bsSize="xsmall"
className="button-right"
onClick={confirmRegenerate}
disabled={false}
>
<i className="fa fa-area-chart" /><i className="fa fa-refresh " />
) : (
<Button
bsStyle="warning"
bsSize="xsmall"
className="button-right"
onClick={confirmRegenerate}
disabled={!hasJcamp || !element.can_update || !hasChemSpectra}
>
<i className="fa fa-area-chart" /><i className="fa fa-refresh " />
</Button>
)}
</OverlayTrigger>
Expand Down Expand Up @@ -88,17 +88,13 @@ const SpectraEditorBtn = ({
) : null
}
</span>

);


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,
Expand All @@ -108,7 +104,7 @@ SpectraEditorBtn.propTypes = {

SpectraEditorBtn.defaultProps = {
hasJcamp: false,
spcInfo: false,
spcInfos: PropTypes.array,
element: {},
hasChemSpectra: false,
hasNMRium: false,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -227,7 +223,7 @@ export default class ResearchPlanDetailsContainers extends Component {
<SpectraEditorBtn
element={researchPlan}
hasJcamp={hasJcamp}
spcInfo={spcInfo}
spcInfos={spcInfos}
hasChemSpectra={hasChemSpectra}
toggleSpectraModal={toggleSpectraModal}
confirmRegenerate={confirmRegenerate}
Expand Down
14 changes: 7 additions & 7 deletions app/packs/src/components/generic/EditorAnalysisBtn.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import uuid from 'uuid';
import { Tooltip, Button, OverlayTrigger, SplitButton, ButtonGroup, MenuItem } from 'react-bootstrap';

const EditorAnalysisBtn = ({
element, spcInfo, hasJcamp, hasChemSpectra,
element, spcInfos, hasJcamp, hasChemSpectra,
toggleSpectraModal, confirmRegenerate,
}) => (
<OverlayTrigger
placement="bottom"
delayShow={500}
overlay={<Tooltip id="spectra">Spectra Editor {spcInfo.length > 0 ? ': Reprocess' : ''}</Tooltip>}
>{spcInfo.length > 0 ? (
overlay={<Tooltip id="spectra">Spectra Editor {spcInfos.length > 0 ? '' : ': Reprocess'}</Tooltip>}
>{spcInfos.length > 0 ? (
<ButtonGroup className="button-right">
<SplitButton
id="spectra-editor-split-button"
Expand All @@ -23,7 +23,7 @@ const EditorAnalysisBtn = ({
title={<i className="fa fa-area-chart" />}
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleSpectraModal}
disabled={!(spcInfo.length > 0) || !hasChemSpectra}
disabled={!(spcInfos.length > 0) || !hasChemSpectra}
>
<MenuItem
id="regenerate-spectra"
Expand All @@ -44,7 +44,7 @@ const EditorAnalysisBtn = ({
bsSize="xsmall"
className="button-right"
onClick={confirmRegenerate}
disabled={false}
disabled={!hasJcamp || !element.can_update || !hasChemSpectra}
>
<i className="fa fa-area-chart" /><i className="fa fa-refresh " />
</Button>
Expand All @@ -55,15 +55,15 @@ 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,
};

EditorAnalysisBtn.defaultProps = {
hasJcamp: false,
spcInfo: [],
spcInfos: [],
element: {},
hasChemSpectra: false,
};
Expand Down
4 changes: 2 additions & 2 deletions app/packs/src/components/generic/GenericContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -49,7 +49,7 @@ const headerBtnGroup = (props) => {
<EditorAnalysisBtn
element={generic}
hasJcamp={hasJcamp}
spcInfo={spcInfo}
spcInfos={spcInfos}
hasChemSpectra={hasChemSpectra}
toggleSpectraModal={toggleSpectraModal}
confirmRegenerate={confirmRegenerate}
Expand Down

0 comments on commit 6b14384

Please sign in to comment.