Skip to content

Commit 58ad6ab

Browse files
committed
refactor: Enhance LCMS state management and improve threshold value handling in Threshold component
1 parent d927c5b commit 58ad6ab

7 files changed

Lines changed: 76 additions & 10 deletions

File tree

src/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const store = compose(
2222
applyMiddleware(...middlewares),
2323
)(createStore)(reducers);
2424

25+
FN.setLcmsStateGetter(() => store.getState().hplcMs);
26+
2527
try {
2628
sagaMiddleware.run(sagas);
2729
} catch (error) {

src/components/cmd_bar/r03_threshold.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import HowToRegOutlinedIcon from '@mui/icons-material/HowToRegOutlined';
1515
import RefreshOutlinedIcon from '@mui/icons-material/RefreshOutlined';
1616

1717
import Cfg from '../../helpers/cfg';
18+
import Format from '../../helpers/format';
1819
import {
1920
updateThresholdValue, resetThresholdValue, toggleThresholdIsEdit,
2021
} from '../../actions/threshold';
@@ -89,10 +90,18 @@ const restoreTp = (hasEdit, isEdit) => (
8990

9091
const Threshold = ({
9192
classes, feature, hasEdit,
92-
hideThresSt, thresValSt, isEditSt, curveSt, hplcMsSt,
93+
hideThresSt, thresValSt, isEditSt, curveSt, hplcMsSt, layoutSt,
9394
updateThresholdValueAct, resetThresholdValueAct, toggleThresholdIsEditAct,
9495
}) => {
95-
const thresVal = thresValSt || (feature ? feature.thresRef : hplcMsSt.threshold.value);
96+
const isLcMs = Format.isLCMsLayout(layoutSt);
97+
let thresVal;
98+
if (isLcMs) {
99+
thresVal = hplcMsSt?.threshold?.value != null
100+
? hplcMsSt.threshold.value
101+
: (feature?.thresRef ?? thresValSt ?? 5);
102+
} else {
103+
thresVal = thresValSt || (feature ? feature.thresRef : hplcMsSt?.threshold?.value);
104+
}
96105

97106
return (
98107
<span className={classes.groupRight}>
@@ -144,6 +153,7 @@ const mapStateToProps = (state, props) => ( // eslint-disable-line
144153
thresValSt: parseFloat(state.threshold.list[state.curve.curveIdx].value) || 0,
145154
curveSt: state.curve,
146155
hplcMsSt: state.hplcMs,
156+
layoutSt: state.layout,
147157
}
148158
);
149159

@@ -167,6 +177,11 @@ Threshold.propTypes = {
167177
resetThresholdValueAct: PropTypes.func.isRequired,
168178
toggleThresholdIsEditAct: PropTypes.func.isRequired,
169179
hplcMsSt: PropTypes.object.isRequired,
180+
layoutSt: PropTypes.string,
181+
};
182+
183+
Threshold.defaultProps = {
184+
layoutSt: undefined,
170185
};
171186

172187
export default connect(

src/components/cmd_bar/r05_submit_btn.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import {
1515
Convert2Scan, Convert2Thres,
1616
} from '../../helpers/chem';
1717
import { MuButton, commonStyle } from './common';
18-
import { extractPeaksEdit, formatLcmsPeaksForBackend, formatLcmsIntegralsForBackend } from '../../helpers/extractPeaksEdit';
18+
import {
19+
extractPeaksEdit,
20+
formatLcmsPeaksForBackend,
21+
formatLcmsIntegralsForBackend,
22+
getLcmsMzPageData,
23+
} from '../../helpers/extractPeaksEdit';
1924
import Format from '../../helpers/format';
2025

2126
const styles = () => (
@@ -29,7 +34,10 @@ const getAxesSelection = (axesUnitsSt, curveIdx) => {
2934
const axes = axesUnitsSt?.axes;
3035
if (!Array.isArray(axes) || axes.length === 0) return { xUnit: '', yUnit: '' };
3136
const idx = Number.isFinite(curveIdx) ? curveIdx : 0;
32-
return axes[idx] || axes[0] || { xUnit: '', yUnit: '' };
37+
return axes[idx] || axes[0] || {
38+
xUnit: '',
39+
yUnit: '',
40+
};
3341
};
3442

3543
const resolveAxisLabels = (xLabel, yLabel, axesUnitsSt, curveIdx) => {
@@ -178,7 +186,11 @@ const onClickCb = (
178186
) => (
179187
() => {
180188
const defaultCurves = feature ? [{ feature }] : [];
181-
const curves = Array.isArray(curveList) && curveList.length > 0 ? curveList : defaultCurves;
189+
let curves = Array.isArray(curveList) && curveList.length > 0 ? curveList : defaultCurves;
190+
if (layoutSt === 'LC/MS') {
191+
curves = curves.filter((c) => c.lcmsKind === 'uvvis');
192+
if (curves.length === 0) curves = defaultCurves;
193+
}
182194
const fallbackIdx = Number.isFinite(curveSt?.curveIdx) ? curveSt.curveIdx : 0;
183195
const indicesToSend = curves.length > 0
184196
? curves.map((_, index) => index)
@@ -216,6 +228,7 @@ const onClickCb = (
216228
payload.lcms_peaks_text = Format.formatedLCMS(hplcMsSt, isAscend, decimalSt);
217229
payload.lcms_uvvis_wavelength = hplcMsSt?.uvvis?.selectedWaveLength ?? null;
218230
payload.lcms_mz_page = hplcMsSt?.tic?.currentPageValue ?? null;
231+
payload.lcms_mz_page_data = getLcmsMzPageData(hplcMsSt);
219232
}
220233
if (Number.isFinite(curveSt?.curveIdx)) {
221234
payload.curveSt = { curveIdx: curveSt.curveIdx };

src/helpers/compass.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Format from './format';
22
import { Convert2DValue } from './chem';
3+
import { LIST_UI_SWEEP_TYPE } from '../constants/list_ui';
34

45
const d3 = require('d3');
56

@@ -122,6 +123,9 @@ const MouseMove = (event, focus) => {
122123
const ClickCompass = (event, focus) => {
123124
event.stopPropagation();
124125
event.preventDefault();
126+
const isPeakGroupSelect = focus.uiSt?.sweepType === LIST_UI_SWEEP_TYPE.PEAK_GROUP_SELECT;
127+
const isMsGraph = focus.graphIndex === 2;
128+
if (isPeakGroupSelect && isMsGraph) return;
125129
const { xt, yt } = TfRescale(focus);
126130
let pt = fetchPt(event, focus, xt);
127131
const { layout, cyclicvoltaSt, jcampIdx } = focus;

src/helpers/extractEntityLCMS.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ export function getLcMsInfo(entity = {}) {
4444

4545
const categories = collectCategories(entity);
4646
const normalizedCategories = categories.map(String).map((category) => category.toUpperCase());
47-
const hasNeg = normalizedCategories.some((category) => category.includes('NEGATIVE'));
48-
const hasPos = normalizedCategories.some((category) => category.includes('POSITIVE'));
47+
const hasNeg = normalizedCategories.some(
48+
(category) => category.includes('NEGATIVE') || category.startsWith('NEGATIV'),
49+
);
50+
const hasPos = normalizedCategories.some(
51+
(category) => category.includes('POSITIVE') || category.startsWith('POSITIV'),
52+
);
4953
let polarity = 'neutral';
5054
if (hasNeg) {
5155
polarity = 'negative';

src/helpers/extractPeaksEdit.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ function formatLcmsIntegralsForBackend(hplcMsSt) {
5353
return allIntegrals;
5454
}
5555

56+
function getLcmsMzPageData(hplcMsSt) {
57+
const tic = hplcMsSt?.tic;
58+
const ms = hplcMsSt?.ms;
59+
if (!tic || !ms) return null;
60+
const polarity = tic.polarity || 'positive';
61+
let polarityKey = 'neutral';
62+
if (polarity === 'negative') polarityKey = 'negative';
63+
else if (polarity === 'positive') polarityKey = 'positive';
64+
const ticDataX = tic[polarityKey]?.data?.x;
65+
if (!Array.isArray(ticDataX) || !Number.isFinite(tic.currentPageValue)) return null;
66+
const currentIndex = ticDataX.findIndex(
67+
(x) => Math.abs(x - tic.currentPageValue) < 1e-6,
68+
);
69+
if (currentIndex < 0) return null;
70+
const peaks = ms[polarityKey]?.peaks?.[currentIndex];
71+
return Array.isArray(peaks) ? peaks : null;
72+
}
73+
5674
function extractPeaksEdit(hplcMsSt) {
5775
if (!hplcMsSt || !hplcMsSt.uvvis || !hplcMsSt.uvvis.spectraList) return [];
5876
return hplcMsSt.uvvis.spectraList.flatMap((spectrum) => spectrum.peaks || []);
@@ -92,4 +110,4 @@ const extractAreaUnderCurve = (allIntegrationSt, presentIntegrationSt, layoutSt)
92110
return null;
93111
};
94112

95-
export { extractPeaksEdit, extractAreaUnderCurve, extractAutoPeaks, formatLcmsPeaksForBackend, formatLcmsIntegralsForBackend }; // eslint-disable-line
113+
export { extractPeaksEdit, extractAreaUnderCurve, extractAutoPeaks, formatLcmsPeaksForBackend, formatLcmsIntegralsForBackend, getLcmsMzPageData }; // eslint-disable-line

src/helpers/format.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { ToXY, IsSame } from './converter';
55
import { LIST_LAYOUT } from '../constants/list_layout';
66
import { calcMpyCenter } from './multiplicity_calc';
77

8+
let lcmsStateGetter = null;
9+
function getLcmsState() {
10+
return typeof lcmsStateGetter === 'function' ? lcmsStateGetter() : undefined;
11+
}
12+
813
const spectraDigit = (layout) => {
914
switch (layout) {
1015
case LIST_LAYOUT.IR:
@@ -199,7 +204,7 @@ const formatedLCMS = (hplcMsSt, isAscend, decimal) => {
199204
if (currentIndex >= 0 && ms[polarityKey].peaks[currentIndex]) {
200205
const peaks = ms[polarityKey].peaks[currentIndex];
201206
const maxIntensity = Math.max(...peaks.map((p) => p.y)) || 1;
202-
const thresholdValue = threshold?.value ?? 5;
207+
const thresholdValue = (threshold?.value != null) ? threshold.value : 5;
203208

204209
const filtered = peaks.filter(
205210
(peak) => (peak.y / maxIntensity) * 100 >= thresholdValue,
@@ -461,7 +466,8 @@ const peaksBody = ({
461466
const maxY = Math.max(...ordered.map((o) => o.y));
462467

463468
if (layout === LIST_LAYOUT.LC_MS) {
464-
return formatedLCMS(hplcMsSt, isAscend, decimal);
469+
const lcmsState = hplcMsSt ?? getLcmsState();
470+
return formatedLCMS(lcmsState, isAscend, decimal);
465471
}
466472
if (layout === LIST_LAYOUT.MS) {
467473
return formatedMS(ordered, maxY, decimal, isAscend);
@@ -687,6 +693,10 @@ const inlineNotation = (layout, data, sampleName = '') => {
687693
};
688694

689695
const Format = {
696+
setLcmsStateGetter(getter) {
697+
lcmsStateGetter = getter;
698+
},
699+
getLcmsState,
690700
toPeakStr,
691701
extractUvvisLcmsPeaks,
692702
buildData,

0 commit comments

Comments
 (0)