Skip to content

Commit

Permalink
fix: fix add and remove multiplicity peak is disable (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
baolanlequang authored Nov 17, 2023
1 parent cfba776 commit d2c92c2
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/components/cmd_bar/05_multiplicity.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const mapStateToProps = (state, props) => (
disableRmMpySt: _cfg.default.btnCmdMpy(state.layout),
isFocusAddPeakSt: state.ui.sweepType === _list_ui.LIST_UI_SWEEP_TYPE.MULTIPLICITY_PEAK_ADD,
isFocusRmPeakSt: state.ui.sweepType === _list_ui.LIST_UI_SWEEP_TYPE.MULTIPLICITY_PEAK_RM,
disableMpyPeakSt: _cfg.default.btnCmdMpyPeak(state.layout, state.multiplicity.present),
disableMpyPeakSt: _cfg.default.btnCmdMpyPeak(state.layout, state.multiplicity.present, state.curve.curveIdx),
curveSt: state.curve
});
const mapDispatchToProps = dispatch => (0, _redux.bindActionCreators)({
Expand Down
15 changes: 12 additions & 3 deletions dist/helpers/cfg.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ const btnCmdSetRef = layoutSt => !_format.default.isNmrLayout(layoutSt);
const btnCmdIntg = layoutSt => !(_format.default.isNmrLayout(layoutSt) || _format.default.isHplcUvVisLayout(layoutSt)); // eslint-disable-line

const btnCmdMpy = layoutSt => !_format.default.isNmrLayout(layoutSt);
const btnCmdMpyPeak = (layoutSt, mpySt) => {
const btnCmdMpyPeak = function (layoutSt, mpySt) {
let curveIdx = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
const {
smExtext
multiplicities
} = mpySt;
return btnCmdMpy(layoutSt) || !smExtext;
let smExtextVal = false;
if (multiplicities) {
const selectedMultiplicity = multiplicities[curveIdx];
const {
smExtext
} = selectedMultiplicity;
smExtextVal = smExtext;
}
return btnCmdMpy(layoutSt) || !smExtextVal;
};
const hideCmdThres = layoutSt => _format.default.isMsLayout(layoutSt);
const btnCmdThres = thresVal => !thresVal;
Expand Down
2 changes: 1 addition & 1 deletion dist/sagas/saga_multiplicity.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function* addUiPeakToStack(action) {
const newMultiplicities = [...multiplicities];
newMultiplicities[curveIdx] = newSelectedMulti;
const payload = Object.assign({}, mpySt, {
multiplicities: newSelectedMulti
multiplicities: newMultiplicities
}); // eslint-disable-line

yield (0, _effects.put)({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@complat/react-spectra-editor",
"version": "1.0.0-rc19",
"version": "1.0.0-rc20",
"description": "An editor to View and Edit Chemical Spectra data (NMR, IR and MS, CV, UIVIS, XRD).",
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/units/helpers/cfg.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('Test Config helper', () => {
})

describe('Add and remove multiplicity peak button', () => {
const mpySt = {smExtext: true}
const mpySt = {"selectedIdx":0,"multiplicities":[{"stack":[{"js":[1.7728561010112571],"mpyType":"quint","xExtent":{"xL":6.18942577177587,"xU":6.559753568068116},"yExtent":{"yL":20286604,"yU":61276677},"peaks":[{"x":6.422977415781519,"y":20286604},{"x":6.418393960239213,"y":44041878},{"x":6.4138105046969045,"y":61276677},{"x":6.409227049154596,"y":44393311},{"x":6.404949157315109,"y":21143741}]},{"js":[0.6724626590039406,2.0173879770127314,37.41337702824512],"mpyType":"ddd","xExtent":{"xL":7.788569415813955,"xU":8.31039593286588},"yExtent":{"yL":3675585,"yU":4004335},"peaks":[{"x":8.101133271671815,"y":3689696},{"x":8.099605453157713,"y":3869072},{"x":8.095938688723866,"y":3880744},{"x":8.094410870209764,"y":3675585},{"x":8.007630778608736,"y":3706408},{"x":8.005797396391813,"y":4004335},{"x":8.002741759363607,"y":3915159},{"x":8.000908377146684,"y":3706677}]},{"js":[],"mpyType":"s","xExtent":{"xL":14.706972135774421,"xU":15.195132390935767},"yExtent":{"yL":16276328,"yU":16276328},"peaks":[{"x":14.948510288176845,"y":16276328}]},{"peaks":[{"x":11.440944543500096,"y":26450300},{"x":11.420777339113942,"y":28797799},{"x":11.298857421688554,"y":34032080},{"x":11.280523599519324,"y":24725861},{"x":11.27838465359958,"y":40013064},{"x":11.190687870890091,"y":37931375},{"x":11.184576596833681,"y":38611682},{"x":11.028739108395214,"y":14764010},{"x":11.02568347136701,"y":15806310},{"x":11.011016413631625,"y":22918651},{"x":11.00826634030624,"y":31715857},{"x":11.005821830683676,"y":16826172},{"x":10.990849209245471,"y":19172963},{"x":10.988099135920086,"y":18223303},{"x":10.904069117644443,"y":35864429}],"xExtent":{"xL":8.630543435939886,"xU":12.328690131870278},"yExtent":{"yL":-16852818.03512673,"yU":72852232.91555789},"mpyType":"m","js":[]}],"shift":0,"smExtext":{"xL":8.630543435939886,"xU":12.328690131870278}}]}

beforeEach(()=> {
layoutShouldView = [LIST_LAYOUT.C13, LIST_LAYOUT.H1, LIST_LAYOUT.F19, LIST_LAYOUT.P31, LIST_LAYOUT.N15, LIST_LAYOUT.Si29]
Expand All @@ -162,14 +162,14 @@ describe('Test Config helper', () => {

it('Show add and remove multiplicity peak button when wrong layout but has smsExtent value', () => {
layoutShouldHide.forEach(layout => {
const isShow = Config.btnCmdMpyPeak(layout, mpySt)
const isShow = Config.btnCmdMpyPeak(layout, mpySt, 0)
expect(isShow).toEqual(true)
})
})

it('Hide add and remove multiplicity peak button', () => {
layoutShouldView.forEach(layout => {
const isShow = Config.btnCmdMpyPeak(layout, mpySt)
const isShow = Config.btnCmdMpyPeak(layout, mpySt, 0)
expect(isShow).toEqual(false)
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/cmd_bar/05_multiplicity.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const mapStateToProps = (state, props) => ( // eslint-disable-line
disableRmMpySt: Cfg.btnCmdMpy(state.layout),
isFocusAddPeakSt: state.ui.sweepType === LIST_UI_SWEEP_TYPE.MULTIPLICITY_PEAK_ADD,
isFocusRmPeakSt: state.ui.sweepType === LIST_UI_SWEEP_TYPE.MULTIPLICITY_PEAK_RM,
disableMpyPeakSt: Cfg.btnCmdMpyPeak(state.layout, state.multiplicity.present),
disableMpyPeakSt: Cfg.btnCmdMpyPeak(state.layout, state.multiplicity.present, state.curve.curveIdx),
curveSt: state.curve,
}
);
Expand Down
12 changes: 9 additions & 3 deletions src/helpers/cfg.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ const btnCmdIntg = (layoutSt) => !(Format.isNmrLayout(layoutSt)|| Format.isHplcU

const btnCmdMpy = (layoutSt) => !Format.isNmrLayout(layoutSt);

const btnCmdMpyPeak = (layoutSt, mpySt) => {
const { smExtext } = mpySt;
return btnCmdMpy(layoutSt) || !smExtext;
const btnCmdMpyPeak = (layoutSt, mpySt, curveIdx = 0) => {
const { multiplicities } = mpySt;
let smExtextVal = false;
if (multiplicities) {
const selectedMultiplicity = multiplicities[curveIdx];
const { smExtext } = selectedMultiplicity;
smExtextVal = smExtext;
}
return btnCmdMpy(layoutSt) || !smExtextVal;
};

const hideCmdThres = (layoutSt) => Format.isMsLayout(layoutSt);
Expand Down
4 changes: 2 additions & 2 deletions src/sagas/saga_multiplicity.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ function* addUiPeakToStack(action) {
});
if (isDuplicate) return;

const newSelectedMulti = Object.assign({}, selectedMulti,{ stack: newStack }); // eslint-disable-line
const newSelectedMulti = Object.assign({}, selectedMulti, { stack: newStack }); // eslint-disable-line
const newMultiplicities = [...multiplicities];
newMultiplicities[curveIdx] = newSelectedMulti;

const payload = Object.assign({}, mpySt, { multiplicities: newSelectedMulti }); // eslint-disable-line
const payload = Object.assign({}, mpySt, { multiplicities: newMultiplicities }); // eslint-disable-line

yield put({
type: MULTIPLICITY.PEAK_ADD_BY_UI_RDC,
Expand Down

0 comments on commit d2c92c2

Please sign in to comment.