Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add-nmrium-button-for-reaction-and-researchplan #1471

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/packs/src/apps/mydb/elements/details/ViewSpectra.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ class ViewSpectra extends React.Component {
buildOpsByLayout(et) {
if (this.props.sample && this.props.sample instanceof ResearchPlan) {
return [
{ name: 'write & save', value: this.writeOp },
{ name: 'write, save & close', value: this.writeCloseOp },
{ name: 'write & save', value: this.saveOp },
{ name: 'write, save & close', value: this.saveCloseOp },
];
}
const updatable = this.props.sample && this.props.sample.can_update;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import { hNmrCount, cNmrCount, instrumentText } from 'src/utilities/ElementUtils
import { contentToText } from 'src/utilities/quillFormat';
import { chmoConversions } from 'src/components/OlsComponent';
import { previewContainerImage } from 'src/utilities/imageHelper';
import { JcampIds, BuildSpcInfos } from 'src/utilities/SpectraHelper';
import { JcampIds, BuildSpcInfos, BuildSpcInfosForNMRDisplayer, isNMRKind } from 'src/utilities/SpectraHelper';
import UIStore from 'src/stores/alt/stores/UIStore';
import UserStore from 'src/stores/alt/stores/UserStore';
import SpectraActions from 'src/stores/alt/actions/SpectraActions';
import LoadingActions from 'src/stores/alt/actions/LoadingActions';
import ViewSpectra from 'src/apps/mydb/elements/details/ViewSpectra';
import NMRiumDisplayer from 'src/components/nmriumWrapper/NMRiumDisplayer';

import TextTemplateActions from 'src/stores/alt/actions/TextTemplateActions';

Expand All @@ -42,48 +44,74 @@ const nmrMsg = (reaction, container) => {
const SpectraEditorBtn = ({
element, spcInfo, hasJcamp, hasChemSpectra,
toggleSpectraModal, confirmRegenerate,
toggleNMRDisplayerModal, hasNMRium,
}) => (
<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"
<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
id="regenerate-spectra"
key="regenerate-spectra"
onSelect={(eventKey, event) => {
event.stopPropagation();
confirmRegenerate(event);
}}
disabled={!hasJcamp || !element.can_update}
>
<i className="fa fa-refresh" /> Reprocess
</MenuItem>
</SplitButton>
</ButtonGroup>
) : (
<Button
bsStyle="warning"
bsSize="xsmall"
title={<i className="fa fa-area-chart" />}
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleSpectraModal}
disabled={!spcInfo || !hasChemSpectra}
className="button-right"
onClick={confirmRegenerate}
disabled={false}
>
<MenuItem
id="regenerate-spectra"
key="regenerate-spectra"
onSelect={(eventKey, event) => {
event.stopPropagation();
confirmRegenerate(event);
}}
disabled={!hasJcamp || !element.can_update}
<i className="fa fa-area-chart" /><i className="fa fa-refresh " />
</Button>
)}
</OverlayTrigger>
{
hasNMRium ? (
<OverlayTrigger
placement="top"
delayShow={500}
overlay={<Tooltip id="spectra_nmrium_wrapper">Process with NMRium</Tooltip>}
>
<i className="fa fa-refresh" /> Reprocess
</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>
)}
</OverlayTrigger>
<ButtonGroup className="button-right">
<Button
id="spectra-editor-split-button"
pullRight
bsStyle="info"
bsSize="xsmall"
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleNMRDisplayerModal}
disabled={!hasJcamp || !element.can_update}
>
<i className="fa fa-bar-chart"/>
</Button>
</ButtonGroup>
</OverlayTrigger>
) : null
}
</span>
);

SpectraEditorBtn.propTypes = {
Expand All @@ -96,13 +124,17 @@ SpectraEditorBtn.propTypes = {
hasChemSpectra: PropTypes.bool,
toggleSpectraModal: PropTypes.func.isRequired,
confirmRegenerate: PropTypes.func.isRequired,
toggleNMRDisplayerModal: PropTypes.func.isRequired,
hasNMRium: PropTypes.bool,
};

SpectraEditorBtn.defaultProps = {
hasJcamp: false,
spcInfo: false,
element: {},
hasChemSpectra: false,
hasEditedJcamp: false,
hasNMRium: false,
};

export default class ReactionDetailsContainers extends Component {
Expand Down Expand Up @@ -192,13 +224,23 @@ export default class ReactionDetailsContainers extends Component {
}
};
const spcInfo = BuildSpcInfos(reaction, container);
const { hasChemSpectra } = UIStore.getState();
const { hasChemSpectra, hasNmriumWrapper } = UIStore.getState();
const toggleSpectraModal = (e) => {
e.stopPropagation();
SpectraActions.ToggleModal();
SpectraActions.LoadSpectra.defer(spcInfo);
};

//process open NMRium
const toggleNMRDisplayerModal = (e) => {
const spcInfosForNMRDisplayer = BuildSpcInfosForNMRDisplayer(reaction, container);
e.stopPropagation();
SpectraActions.ToggleModalNMRDisplayer();
SpectraActions.LoadSpectraForNMRDisplayer.defer(spcInfosForNMRDisplayer); // going to fetch files base on spcInfos
}

const { chmos } = UserStore.getState();
const hasNMRium = isNMRKind(container, chmos) && hasNmriumWrapper;

return (
<div className="upper-btn">
Expand All @@ -219,6 +261,8 @@ export default class ReactionDetailsContainers extends Component {
hasChemSpectra={hasChemSpectra}
toggleSpectraModal={toggleSpectraModal}
confirmRegenerate={confirmRegenerate}
toggleNMRDisplayerModal={toggleNMRDisplayerModal}
hasNMRium={hasNMRium}
/>
</div>
);
Expand Down Expand Up @@ -388,6 +432,11 @@ export default class ReactionDetailsContainers extends Component {
handleSampleChanged={this.handleSpChange}
handleSubmit={this.props.handleSubmit}
/>
<NMRiumDisplayer
sample={reaction}
handleSampleChanged={this.handleSpChange}
handleSubmit={this.props.handleSubmit}
/>
</Panel.Body>
</Panel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,88 @@ import QuillViewer from 'src/components/QuillViewer';
import ImageModal from 'src/components/common/ImageModal';
import { instrumentText } from 'src/utilities/ElementUtils';
import { previewContainerImage } from 'src/utilities/imageHelper';
import { JcampIds, BuildSpcInfos } from 'src/utilities/SpectraHelper';
import { JcampIds, BuildSpcInfos, BuildSpcInfosForNMRDisplayer, isNMRKind } from 'src/utilities/SpectraHelper';
import UIStore from 'src/stores/alt/stores/UIStore';
import UserStore from 'src/stores/alt/stores/UserStore';
import SpectraActions from 'src/stores/alt/actions/SpectraActions';
import LoadingActions from 'src/stores/alt/actions/LoadingActions';
import ViewSpectra from 'src/apps/mydb/elements/details/ViewSpectra';
import NMRiumDisplayer from 'src/components/nmriumWrapper/NMRiumDisplayer';

import TextTemplateActions from 'src/stores/alt/actions/TextTemplateActions';

const SpectraEditorBtn = ({
element, spcInfo, hasJcamp, hasChemSpectra,
toggleSpectraModal, confirmRegenerate,
toggleNMRDisplayerModal, hasNMRium,
}) => (
<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"
<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
id="regenerate-spectra"
key="regenerate-spectra"
onSelect={(eventKey, event) => {
event.stopPropagation();
confirmRegenerate(event);
}}
disabled={!hasJcamp || !element.can_update}
>
<i className="fa fa-refresh" /> Reprocess
</MenuItem>
</SplitButton>
</ButtonGroup>
) : (
<Button
bsStyle="warning"
bsSize="xsmall"
title={<i className="fa fa-area-chart" />}
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleSpectraModal}
disabled={!spcInfo || !hasChemSpectra}
className="button-right"
onClick={confirmRegenerate}
disabled={false}
>
<MenuItem
id="regenerate-spectra"
key="regenerate-spectra"
onSelect={(eventKey, event) => {
event.stopPropagation();
confirmRegenerate(event);
}}
disabled={!hasJcamp || !element.can_update}
<i className="fa fa-area-chart" /><i className="fa fa-refresh " />
</Button>
)}
</OverlayTrigger>
{
hasNMRium ? (
<OverlayTrigger
placement="top"
delayShow={500}
overlay={<Tooltip id="spectra_nmrium_wrapper">Process with NMRium</Tooltip>}
>
<i className="fa fa-refresh" /> Reprocess
</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>
)}
</OverlayTrigger>
<ButtonGroup className="button-right">
<Button
id="spectra-editor-split-button"
pullRight
bsStyle="info"
bsSize="xsmall"
onToggle={(open, event) => { if (event) { event.stopPropagation(); } }}
onClick={toggleNMRDisplayerModal}
disabled={!hasJcamp}
>
<i className="fa fa-bar-chart"/>
</Button>
</ButtonGroup>
</OverlayTrigger>
) : null
}
</span>

);


Expand All @@ -73,13 +102,16 @@ SpectraEditorBtn.propTypes = {
hasChemSpectra: PropTypes.bool,
toggleSpectraModal: PropTypes.func.isRequired,
confirmRegenerate: PropTypes.func.isRequired,
toggleNMRDisplayerModal: PropTypes.func.isRequired,
hasNMRium: PropTypes.bool,
};

SpectraEditorBtn.defaultProps = {
hasJcamp: false,
spcInfo: false,
element: {},
hasChemSpectra: false,
hasNMRium: false,
};

export default class ResearchPlanDetailsContainers extends Component {
Expand Down Expand Up @@ -163,12 +195,24 @@ export default class ResearchPlanDetailsContainers extends Component {
}
};
const spcInfo = BuildSpcInfos(researchPlan, container);
const { hasChemSpectra } = UIStore.getState();
const { hasChemSpectra, hasNmriumWrapper } = UIStore.getState();
const toggleSpectraModal = (e) => {
e.stopPropagation();
SpectraActions.ToggleModal();
SpectraActions.LoadSpectra.defer(spcInfo);
};

//process open NMRium
const toggleNMRDisplayerModal = (e) => {
const spcInfosForNMRDisplayer = BuildSpcInfosForNMRDisplayer(researchPlan, container);
e.stopPropagation();
SpectraActions.ToggleModalNMRDisplayer();
SpectraActions.LoadSpectraForNMRDisplayer.defer(spcInfosForNMRDisplayer); // going to fetch files base on spcInfos
}

const { chmos } = UserStore.getState();
const hasNMRium = isNMRKind(container, chmos) && hasNmriumWrapper;

return (
<div className="upper-btn">
<Button
Expand All @@ -187,6 +231,8 @@ export default class ResearchPlanDetailsContainers extends Component {
hasChemSpectra={hasChemSpectra}
toggleSpectraModal={toggleSpectraModal}
confirmRegenerate={confirmRegenerate}
toggleNMRDisplayerModal={toggleNMRDisplayerModal}
hasNMRium={hasNMRium}
/>
</div>
);
Expand Down Expand Up @@ -349,6 +395,11 @@ export default class ResearchPlanDetailsContainers extends Component {
handleSampleChanged={this.handleSpChange}
handleSubmit={this.props.handleSubmit}
/>
<NMRiumDisplayer
sample={this.props.researchPlan}
handleSampleChanged={this.handleSpChange}
handleSubmit={this.props.handleSubmit}
/>
</Panel.Body>
</Panel>
);
Expand Down
Loading
Loading