Skip to content

Commit

Permalink
Fix crash and undo redo function (#150)
Browse files Browse the repository at this point in the history
* fix: fixed crash when select multiplicity on panel (#146)

* fix: fix cannot undo redo peaks, integrations and multiplicities (#149)
  • Loading branch information
baolanlequang authored Sep 5, 2023
1 parent 506c2f9 commit e996036
Show file tree
Hide file tree
Showing 28 changed files with 269 additions and 253 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Testing

on: push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.10.0
- run: yarn install
- run: yarn test
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

An editor to View and Edit Chemical Spectra data (NMR, IR and MS).

![Testing](https://github.com/ComPlat/react-spectra-editor/actions/workflows/testing.yml/badge.svg)

### Usage

#### Installing from npm
Expand Down
2 changes: 1 addition & 1 deletion dist/components/cmd_bar/r01_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const layoutSelect = (classes, layoutSt, updateLayoutAct) => {
value: _list_layout.LIST_LAYOUT.AIF
}, /*#__PURE__*/_react.default.createElement("span", {
className: (0, _classnames.default)(classes.txtOpt, 'option-sv-bar-layout')
}, "AIF")), /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
}, "SOPTION-DESORPTION")), /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
value: _list_layout.LIST_LAYOUT.EMISSIONS
}, /*#__PURE__*/_react.default.createElement("span", {
className: (0, _classnames.default)(classes.txtOpt, 'option-sv-bar-layout')
Expand Down
6 changes: 4 additions & 2 deletions dist/components/cmd_bar/r06_predict_btn.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ const BtnPredict = _ref => {
realCount = (0, _carbonFeatures.carbonFeatures)(peaksEdit, multiplicitySt).length;
} else {
const {
selectedIdx,
curveIdx
} = curveSt;
const {
multiplicities
} = multiplicitySt;
const selectedMultiplicity = multiplicities[selectedIdx];
const selectedMultiplicity = multiplicities[curveIdx];
const {
stack
} = selectedMultiplicity;
Expand Down
4 changes: 2 additions & 2 deletions dist/components/panel/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ const InfoPanel = _ref => {
className: (0, _classnames.default)(classes.tTxt, classes.tHead, 'txt-sv-panel-txt')
}, "Area under curve (AUC):"), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("span", {
className: (0, _classnames.default)(classes.tTxt, classes.tTxtSim, 'txt-sv-panel-txt')
}, aucValue(integration))) : null), /*#__PURE__*/_react.default.createElement(_reactQuill.default, {
}, aucValue(integration))) : null), !_format.default.isCyclicVoltaLayout(layoutSt) ? /*#__PURE__*/_react.default.createElement(_reactQuill.default, {
className: (0, _classnames.default)(classes.quill, 'card-sv-quill'),
value: descriptions,
modules: {
toolbar: false
},
onChange: onDescriptionChanged,
readOnly: canChangeDescription !== undefined ? !canChangeDescription : true
}), /*#__PURE__*/_react.default.createElement("div", null, !editorOnly && _format.default.isNmrLayout(layoutSt) ? /*#__PURE__*/_react.default.createElement("div", {
}) : null, /*#__PURE__*/_react.default.createElement("div", null, !editorOnly && _format.default.isNmrLayout(layoutSt) ? /*#__PURE__*/_react.default.createElement("div", {
className: (0, _classnames.default)(classes.rowRoot, classes.rowOddSim)
}, /*#__PURE__*/_react.default.createElement("span", {
className: (0, _classnames.default)(classes.tTxt, classes.tHead, 'txt-sv-panel-txt')
Expand Down
6 changes: 5 additions & 1 deletion dist/components/panel/multiplicity.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ const mpyList = (classes, digits, multiplicitySt, curveSt, clickMpyOneAct, rmMpy
const onClick = e => {
e.stopPropagation();
e.preventDefault();
clickMpyOneAct(xExtent);
const payload = {
curveIdx,
payloadData: xExtent
};
clickMpyOneAct(payload);
};
return createData(idx, xExtent, peaks, shift, smExtext, mpyType, js, onClick, onRefresh);
});
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class DemoWriteIr extends _react.default.Component {
margin: '0 10px 0 10px'
},
onClick: this.onClick('aif')
}, "AIF"), /*#__PURE__*/_react.default.createElement(_Button.default, {
}, "SOPTION-DESORPTION"), /*#__PURE__*/_react.default.createElement(_Button.default, {
variant: "contained",
style: {
margin: '0 10px 0 10px'
Expand Down
35 changes: 21 additions & 14 deletions dist/reducers/reducer_edit_peak.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ const addToPos = (state, action) => {
const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, {
neg
});
peaks[curveIdx] = newSelectedEditPeaks;
const newPeaks = [...peaks];
newPeaks[curveIdx] = newSelectedEditPeaks;
return Object.assign({}, state, {
peaks
peaks: newPeaks
});
}
const idxP = oriPosState.findIndex(p => (0, _calc.almostEqual)(p.x, dataToAdd.x));
Expand All @@ -60,9 +61,10 @@ const addToPos = (state, action) => {
const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, {
pos
});
peaks[curveIdx] = newSelectedEditPeaks;
const newPeaks = [...peaks];
newPeaks[curveIdx] = newSelectedEditPeaks;
return Object.assign({}, state, {
peaks,
peaks: newPeaks,
selectedIdx: curveIdx
});
}
Expand All @@ -80,9 +82,10 @@ const rmFromPos = (state, action) => {
const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, {
pos
});
peaks[selectedIdx] = newSelectedEditPeaks;
const newPeaks = [...peaks];
newPeaks[selectedIdx] = newSelectedEditPeaks;
return Object.assign({}, state, {
peaks
peaks: newPeaks
});
};
const addToNeg = (state, action) => {
Expand All @@ -108,9 +111,10 @@ const addToNeg = (state, action) => {
const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, {
pos
});
peaks[curveIdx] = newSelectedEditPeaks;
const newPeaks = [...peaks];
newPeaks[curveIdx] = newSelectedEditPeaks;
return Object.assign({}, state, {
peaks
peaks: newPeaks
});
}
const idxN = oriNegState.findIndex(n => n.x === dataToAdd.x);
Expand All @@ -119,9 +123,10 @@ const addToNeg = (state, action) => {
const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, {
neg
});
peaks[curveIdx] = newSelectedEditPeaks;
const newPeaks = [...peaks];
newPeaks[curveIdx] = newSelectedEditPeaks;
return Object.assign({}, state, {
peaks,
peaks: newPeaks,
selectedIdx: curveIdx
});
}
Expand All @@ -139,9 +144,10 @@ const rmFromNeg = (state, action) => {
const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, {
neg
});
peaks[selectedIdx] = newSelectedEditPeaks;
const newPeaks = [...peaks];
newPeaks[selectedIdx] = newSelectedEditPeaks;
return Object.assign({}, state, {
peaks
peaks: newPeaks
});
};
const processShift = (state, action) => {
Expand All @@ -168,9 +174,10 @@ const processShift = (state, action) => {
neg,
prevOffset
});
peaks[curveIdx] = newSelectedEditPeaks;
const newPeaks = [...peaks];
newPeaks[curveIdx] = newSelectedEditPeaks;
return Object.assign({}, state, {
peaks
peaks: newPeaks
});
};
const editPeakReducer = function () {
Expand Down
30 changes: 18 additions & 12 deletions dist/reducers/reducer_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ const addToStack = (state, action) => {
stack: newStack,
refArea: defaultRefArea
});
integrations[curveIdx] = newIntegration;
const newArrIntegration = [...integrations];
newArrIntegration[curveIdx] = newIntegration;
return Object.assign({}, state, {
integrations,
integrations: newArrIntegration,
selectedIdx: curveIdx
});
};
Expand Down Expand Up @@ -106,9 +107,10 @@ const rmFromStack = (state, action) => {
const newIntegration = Object.assign({}, selectedIntegration, {
stack: newStack
});
integrations[curveIdx] = newIntegration;
const newArrIntegration = [...integrations];
newArrIntegration[curveIdx] = newIntegration;
return Object.assign({}, state, {
integrations,
integrations: newArrIntegration,
selectedIdx: curveIdx
});
};
Expand Down Expand Up @@ -136,9 +138,10 @@ const setRef = (state, action) => {
const newIntegration = Object.assign({}, selectedIntegration, {
refArea
});
integrations[curveIdx] = newIntegration;
const newArrIntegration = [...integrations];
newArrIntegration[curveIdx] = newIntegration;
return Object.assign({}, state, {
integrations,
integrations: newArrIntegration,
selectedIdx: curveIdx
});
};
Expand All @@ -159,9 +162,10 @@ const setFkr = (state, action) => {
const newIntegration = Object.assign({}, selectedIntegration, {
refFactor
});
integrations[curveIdx] = newIntegration;
const newArrIntegration = [...integrations];
newArrIntegration[curveIdx] = newIntegration;
return Object.assign({}, state, {
integrations
integrations: newArrIntegration
});
};
const setShift = (state, action) => {
Expand All @@ -174,9 +178,10 @@ const setShift = (state, action) => {
const newIntegration = Object.assign({}, selectedIntegration, {
shift
});
integrations[selectedIdx] = newIntegration;
const newArrIntegration = [...integrations];
newArrIntegration[selectedIdx] = newIntegration;
return Object.assign({}, state, {
integrations
integrations: newArrIntegration
});
};
const resetAll = (state, action) => {
Expand All @@ -196,9 +201,10 @@ const clearAll = (state, action) => {
const newIntegration = Object.assign({}, defaultEmptyIntegration, {
edited: true
});
integrations[curveIdx] = newIntegration;
const newArrIntegration = [...integrations];
newArrIntegration[curveIdx] = newIntegration;
return Object.assign({}, state, {
integrations,
integrations: newArrIntegration,
selectedIdx: curveIdx
});
};
Expand Down
25 changes: 15 additions & 10 deletions dist/reducers/reducer_multiplicity.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ const setShift = (state, action) => {
const newSelectedMulti = Object.assign({}, selectedMulti, {
shift
});
multiplicities[selectedIdx] = newSelectedMulti;
const newMultiplicities = [...multiplicities];
newMultiplicities[selectedIdx] = newSelectedMulti;
return Object.assign({}, state, {
multiplicities
multiplicities: newMultiplicities
});
};
const rmFromStack = (state, action) => {
Expand Down Expand Up @@ -76,9 +77,10 @@ const rmFromStack = (state, action) => {
stack: newStack,
smExtext: newSmExtext
});
multiplicities[curveIdx] = newSelectedMulti;
const newMultiplicities = [...multiplicities];
newMultiplicities[curveIdx] = newSelectedMulti;
return Object.assign({}, state, {
multiplicities,
multiplicities: newMultiplicities,
selectedIdx: curveIdx
});
};
Expand Down Expand Up @@ -115,9 +117,10 @@ const updateMpyJ = (state, action) => {
const newSelectedMulti = Object.assign({}, selectedMulti, {
stack: newStack
});
multiplicities[selectedIdx] = newSelectedMulti;
const newMultiplicities = [...multiplicities];
newMultiplicities[selectedIdx] = newSelectedMulti;
return Object.assign({}, state, {
multiplicities
multiplicities: newMultiplicities
});
};
const clickMpyOne = (state, action) => {
Expand All @@ -135,9 +138,10 @@ const clickMpyOne = (state, action) => {
const newSelectedMulti = Object.assign({}, selectedMulti, {
smExtext: payloadData
});
multiplicities[curveIdx] = newSelectedMulti;
const newMultiplicities = [...multiplicities];
newMultiplicities[curveIdx] = newSelectedMulti;
return Object.assign({}, state, {
multiplicities,
multiplicities: newMultiplicities,
selectedIdx: curveIdx
});
};
Expand All @@ -154,9 +158,10 @@ const clearAll = (state, action) => {
const newSelectedMulti = Object.assign({}, defaultEmptyMultiplicity, {
edited: true
});
multiplicities[curveIdx] = newSelectedMulti;
const newMultiplicities = [...multiplicities];
newMultiplicities[curveIdx] = newSelectedMulti;
return Object.assign({}, state, {
multiplicities
multiplicities: newMultiplicities
});
};
const multiplicityReducer = function () {
Expand Down
10 changes: 6 additions & 4 deletions dist/sagas/saga_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ function* resetInitNmr(action) {
const {
integrations
} = integationSt;
integrations[curveIdx] = integration;
const newArrIntegration = [...integrations];
newArrIntegration[curveIdx] = integration;
const payload = Object.assign({}, integationSt, {
integrations,
integrations: newArrIntegration,
selectedIdx: curveIdx
}); // eslint-disable-line

Expand Down Expand Up @@ -78,9 +79,10 @@ function* resetInitCommonWithIntergation(action) {
const {
integrations
} = integationSt;
integrations[curveIdx] = integration;
const newArrIntegration = [...integrations];
newArrIntegration[curveIdx] = integration;
const payload = Object.assign({}, integationSt, {
integrations,
integrations: newArrIntegration,
selectedIdx: curveIdx
}); // eslint-disable-line

Expand Down
13 changes: 1 addition & 12 deletions dist/sagas/saga_multi_entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ function* setCyclicVoltametry(action) {
}
}
}

// function* setInitData(action) {
// const layoutSt = yield select(getLayoutSt);
// console.log(layoutSt);
// const curveSt = yield select(getCurveSt);
// const { listCurves } = curveSt;
// console.log(listCurves);
// }

const multiEntitiesSagas = [(0, _effects.takeEvery)(_action_type.CURVE.SET_ALL_CURVES, setCyclicVoltametry)
// takeEvery(CURVE.SET_ALL_CURVES, setInitData),
];
const multiEntitiesSagas = [(0, _effects.takeEvery)(_action_type.CURVE.SET_ALL_CURVES, setCyclicVoltametry)];
var _default = multiEntitiesSagas;
exports.default = _default;
Loading

0 comments on commit e996036

Please sign in to comment.