From 5ca04c84bb086514465ac777d87a4586be5714ca Mon Sep 17 00:00:00 2001 From: Lan Le Date: Tue, 5 Sep 2023 09:46:47 +0200 Subject: [PATCH] fix: fix cannot undo redo peaks, integrations and multiplicities (#149) --- dist/reducers/reducer_edit_peak.js | 35 +++++++++++++++---------- dist/reducers/reducer_integration.js | 30 +++++++++++++--------- dist/reducers/reducer_multiplicity.js | 25 ++++++++++-------- dist/sagas/saga_manager.js | 10 +++++--- dist/sagas/saga_multi_entities.js | 13 +--------- dist/sagas/saga_multiplicity.js | 30 +++++++++++++--------- dist/setupTests.js | 2 +- package.json | 2 +- src/reducers/reducer_edit_peak.js | 37 ++++++++++++++++----------- src/reducers/reducer_integration.js | 30 +++++++++++++--------- src/reducers/reducer_multiplicity.js | 25 ++++++++++-------- src/sagas/saga_manager.js | 10 +++++--- src/sagas/saga_multi_entities.js | 9 ------- src/sagas/saga_multiplicity.js | 30 +++++++++++++--------- yarn.lock | 8 +++--- 15 files changed, 164 insertions(+), 132 deletions(-) diff --git a/dist/reducers/reducer_edit_peak.js b/dist/reducers/reducer_edit_peak.js index b93c4d08..2fca5bf3 100644 --- a/dist/reducers/reducer_edit_peak.js +++ b/dist/reducers/reducer_edit_peak.js @@ -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)); @@ -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 }); } @@ -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) => { @@ -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); @@ -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 }); } @@ -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) => { @@ -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 () { diff --git a/dist/reducers/reducer_integration.js b/dist/reducers/reducer_integration.js index 9c7cda94..0d009fc7 100644 --- a/dist/reducers/reducer_integration.js +++ b/dist/reducers/reducer_integration.js @@ -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 }); }; @@ -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 }); }; @@ -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 }); }; @@ -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) => { @@ -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) => { @@ -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 }); }; diff --git a/dist/reducers/reducer_multiplicity.js b/dist/reducers/reducer_multiplicity.js index 71e81646..27029c7c 100644 --- a/dist/reducers/reducer_multiplicity.js +++ b/dist/reducers/reducer_multiplicity.js @@ -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) => { @@ -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 }); }; @@ -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) => { @@ -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 }); }; @@ -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 () { diff --git a/dist/sagas/saga_manager.js b/dist/sagas/saga_manager.js index d8439356..108103f0 100644 --- a/dist/sagas/saga_manager.js +++ b/dist/sagas/saga_manager.js @@ -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 @@ -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 diff --git a/dist/sagas/saga_multi_entities.js b/dist/sagas/saga_multi_entities.js index 9f41df42..2d8b0b94 100644 --- a/dist/sagas/saga_multi_entities.js +++ b/dist/sagas/saga_multi_entities.js @@ -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; \ No newline at end of file diff --git a/dist/sagas/saga_multiplicity.js b/dist/sagas/saga_multiplicity.js index 2f3196e6..e771f8e6 100644 --- a/dist/sagas/saga_multiplicity.js +++ b/dist/sagas/saga_multiplicity.js @@ -71,11 +71,12 @@ function* selectMpy(action) { stack: newStack, smExtext: newXExtemt }); - multiplicities[curveIdx] = newSelectedMulti; + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; const payload = Object.assign( // eslint-disable-line {}, mpySt, { - multiplicities, + multiplicities: newMultiplicities, selectedIdx: curveIdx }); yield (0, _effects.put)({ @@ -138,9 +139,10 @@ function* addUiPeakToStack(action) { const newSelectedMulti = Object.assign({}, selectedMulti, { stack: newStack }); // eslint-disable-line - multiplicities[curveIdx] = newSelectedMulti; + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; const payload = Object.assign({}, mpySt, { - multiplicities + multiplicities: newSelectedMulti }); // eslint-disable-line yield (0, _effects.put)({ @@ -193,9 +195,10 @@ const rmPeakFromStack = function (action, metaSt, mpySt) { stack: newStack, smExtext: newSmExtext }); // eslint-disable-line - multiplicities[curveIdx] = newSelectedMulti; + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; return Object.assign({}, mpySt, { - multiplicities + multiplicities: newMultiplicities }); // eslint-disable-line }; @@ -250,9 +253,10 @@ function* resetInitNmr(action) { const { multiplicities } = mpySt; - multiplicities[curveIdx] = multiplicity; + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = multiplicity; const payload = Object.assign({}, mpySt, { - multiplicities, + multiplicities: newMultiplicities, selectedIdx: curveIdx }); // eslint-disable-line @@ -327,9 +331,10 @@ function* resetOne(action) { const newSelectedMulti = Object.assign({}, selectedMulti, { stack: newStack }); // eslint-disable-line - multiplicities[curveIdx] = newSelectedMulti; + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; const payload = Object.assign({}, mpySt, { - multiplicities + multiplicities: newMultiplicities }); // eslint-disable-line yield (0, _effects.put)({ type: _action_type.MULTIPLICITY.RESET_ONE_RDC, @@ -362,9 +367,10 @@ function* selectMpyType(action) { const newSelectedMulti = Object.assign({}, selectedMulti, { stack: newStack }); // eslint-disable-line - multiplicities[curveIdx] = newSelectedMulti; + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; const payload = Object.assign({}, mpySt, { - multiplicities + multiplicities: newMultiplicities }); // eslint-disable-line yield (0, _effects.put)({ diff --git a/dist/setupTests.js b/dist/setupTests.js index 68ee2757..fc453d7d 100644 --- a/dist/setupTests.js +++ b/dist/setupTests.js @@ -2,7 +2,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _enzyme = _interopRequireDefault(require("enzyme")); -var _enzymeAdapterReact = _interopRequireDefault(require("enzyme-adapter-react-16")); +var _enzymeAdapterReact = _interopRequireDefault(require("@wojtekmaj/enzyme-adapter-react-17")); _enzyme.default.configure({ adapter: new _enzymeAdapterReact.default() }); \ No newline at end of file diff --git a/package.json b/package.json index c9124b58..43285f8a 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "react-svg-inline": "^2.1.1", "redux": "^4.1.1", "redux-saga": "^1.1.3", - "redux-undo": "^1.0.1", + "redux-undo": "^1.1.0", "regenerator-transform": "^0.13.3", "reselect": "^4.0.0", "typescript": "^5.0.4" diff --git a/src/reducers/reducer_edit_peak.js b/src/reducers/reducer_edit_peak.js index 8834f565..f5a79d7e 100644 --- a/src/reducers/reducer_edit_peak.js +++ b/src/reducers/reducer_edit_peak.js @@ -41,17 +41,19 @@ const addToPos = (state, action) => { ]; const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, { neg }); - peaks[curveIdx] = newSelectedEditPeaks; - - return Object.assign({}, state, { peaks }); + const newPeaks = [...peaks]; + newPeaks[curveIdx] = newSelectedEditPeaks; + return Object.assign({}, state, { peaks: newPeaks }); } + const idxP = oriPosState.findIndex((p) => almostEqual(p.x, dataToAdd.x)); if (idxP < 0) { // add the peak const pos = [...oriPosState, dataToAdd]; const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, { pos }); - peaks[curveIdx] = newSelectedEditPeaks; - return Object.assign({}, state, { peaks, selectedIdx: curveIdx }); + const newPeaks = [...peaks]; + newPeaks[curveIdx] = newSelectedEditPeaks; + return Object.assign({}, state, { peaks: newPeaks, selectedIdx: curveIdx }); } return state; }; @@ -68,8 +70,9 @@ const rmFromPos = (state, action) => { ]; const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, { pos }); - peaks[selectedIdx] = newSelectedEditPeaks; - return Object.assign({}, state, { peaks }); + const newPeaks = [...peaks]; + newPeaks[selectedIdx] = newSelectedEditPeaks; + return Object.assign({}, state, { peaks: newPeaks }); }; const addToNeg = (state, action) => { @@ -90,15 +93,17 @@ const addToNeg = (state, action) => { ...oriPosState.slice(idxP + 1), ]; const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, { pos }); - peaks[curveIdx] = newSelectedEditPeaks; - return Object.assign({}, state, { peaks }); + const newPeaks = [...peaks]; + newPeaks[curveIdx] = newSelectedEditPeaks; + return Object.assign({}, state, { peaks: newPeaks }); } const idxN = oriNegState.findIndex((n) => n.x === dataToAdd.x); if (idxN < 0) { const neg = [...oriNegState, dataToAdd]; const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, { neg }); - peaks[curveIdx] = newSelectedEditPeaks; - return Object.assign({}, state, { peaks, selectedIdx: curveIdx }); + const newPeaks = [...peaks]; + newPeaks[curveIdx] = newSelectedEditPeaks; + return Object.assign({}, state, { peaks: newPeaks, selectedIdx: curveIdx }); } return state; }; @@ -114,8 +119,9 @@ const rmFromNeg = (state, action) => { ...oriNegState.slice(idx + 1), ]; const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, { neg }); - peaks[selectedIdx] = newSelectedEditPeaks; - return Object.assign({}, state, { peaks }); + const newPeaks = [...peaks]; + newPeaks[selectedIdx] = newSelectedEditPeaks; + return Object.assign({}, state, { peaks: newPeaks }); }; const processShift = (state, action) => { @@ -130,8 +136,9 @@ const processShift = (state, action) => { const { pos, neg, prevOffset } = payload; const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, { pos, neg, prevOffset }); - peaks[curveIdx] = newSelectedEditPeaks; - return Object.assign({}, state, { peaks }); + const newPeaks = [...peaks]; + newPeaks[curveIdx] = newSelectedEditPeaks; + return Object.assign({}, state, { peaks: newPeaks }); }; const editPeakReducer = (state = initialState, action) => { diff --git a/src/reducers/reducer_integration.js b/src/reducers/reducer_integration.js index 34e1a2b2..01352986 100644 --- a/src/reducers/reducer_integration.js +++ b/src/reducers/reducer_integration.js @@ -55,9 +55,10 @@ const addToStack = (state, action) => { selectedIntegration, { stack: newStack, refArea: defaultRefArea }, ); - integrations[curveIdx] = newIntegration; + const newArrIntegration = [...integrations]; + newArrIntegration[curveIdx] = newIntegration; - return Object.assign({}, state, { integrations, selectedIdx: curveIdx }); + return Object.assign({}, state, { integrations: newArrIntegration, selectedIdx: curveIdx }); }; const rmFromStack = (state, action) => { @@ -80,9 +81,10 @@ const rmFromStack = (state, action) => { const newStack = stack.filter((k) => k.xL !== txL && k.xU !== txU); const newIntegration = Object.assign({}, selectedIntegration, { stack: newStack }); - integrations[curveIdx] = newIntegration; + const newArrIntegration = [...integrations]; + newArrIntegration[curveIdx] = newIntegration; - return Object.assign({}, state, { integrations, selectedIdx: curveIdx }); + return Object.assign({}, state, { integrations: newArrIntegration, selectedIdx: curveIdx }); }; const setRef = (state, action) => { @@ -101,9 +103,10 @@ const setRef = (state, action) => { const refArea = ref.area; const newIntegration = Object.assign({}, selectedIntegration, { refArea }); - integrations[curveIdx] = newIntegration; + const newArrIntegration = [...integrations]; + newArrIntegration[curveIdx] = newIntegration; - return Object.assign({}, state, { integrations, selectedIdx: curveIdx }); + return Object.assign({}, state, { integrations: newArrIntegration, selectedIdx: curveIdx }); }; const setFkr = (state, action) => { @@ -116,9 +119,10 @@ const setFkr = (state, action) => { const refFactor = val < 0.01 ? 0.01 : val; const newIntegration = Object.assign({}, selectedIntegration, { refFactor }); - integrations[curveIdx] = newIntegration; + const newArrIntegration = [...integrations]; + newArrIntegration[curveIdx] = newIntegration; - return Object.assign({}, state, { integrations }); + return Object.assign({}, state, { integrations: newArrIntegration }); }; const setShift = (state, action) => { @@ -128,8 +132,9 @@ const setShift = (state, action) => { const shift = action.payload.prevOffset; const newIntegration = Object.assign({}, selectedIntegration, { shift }); - integrations[selectedIdx] = newIntegration; - return Object.assign({}, state, { integrations }); + const newArrIntegration = [...integrations]; + newArrIntegration[selectedIdx] = newIntegration; + return Object.assign({}, state, { integrations: newArrIntegration }); }; const resetAll = (state, action) => { @@ -143,8 +148,9 @@ const clearAll = (state, action) => { const { integrations } = state; const newIntegration = Object.assign({}, defaultEmptyIntegration, { edited: true }); - integrations[curveIdx] = newIntegration; - return Object.assign({}, state, { integrations, selectedIdx: curveIdx }); + const newArrIntegration = [...integrations]; + newArrIntegration[curveIdx] = newIntegration; + return Object.assign({}, state, { integrations: newArrIntegration, selectedIdx: curveIdx }); }; const integrationReducer = (state = initialState, action) => { diff --git a/src/reducers/reducer_multiplicity.js b/src/reducers/reducer_multiplicity.js index 30b45071..855c6400 100644 --- a/src/reducers/reducer_multiplicity.js +++ b/src/reducers/reducer_multiplicity.js @@ -32,8 +32,9 @@ const setShift = (state, action) => { const selectedMulti = multiplicities[selectedIdx]; const newSelectedMulti = Object.assign({}, selectedMulti, { shift }); - multiplicities[selectedIdx] = newSelectedMulti; - return Object.assign({}, state, { multiplicities }); + const newMultiplicities = [...multiplicities]; + newMultiplicities[selectedIdx] = newSelectedMulti; + return Object.assign({}, state, { multiplicities: newMultiplicities }); }; const rmFromStack = (state, action) => { @@ -63,8 +64,9 @@ const rmFromStack = (state, action) => { selectedMulti, { stack: newStack, smExtext: newSmExtext }, ); - multiplicities[curveIdx] = newSelectedMulti; - return Object.assign({}, state, { multiplicities, selectedIdx: curveIdx }); + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; + return Object.assign({}, state, { multiplicities: newMultiplicities, selectedIdx: curveIdx }); }; const updateMpyJ = (state, action) => { @@ -92,8 +94,9 @@ const updateMpyJ = (state, action) => { selectedMulti, { stack: newStack }, ); - multiplicities[selectedIdx] = newSelectedMulti; - return Object.assign({}, state, { multiplicities }); + const newMultiplicities = [...multiplicities]; + newMultiplicities[selectedIdx] = newSelectedMulti; + return Object.assign({}, state, { multiplicities: newMultiplicities }); }; const clickMpyOne = (state, action) => { @@ -104,8 +107,9 @@ const clickMpyOne = (state, action) => { const selectedMulti = multiplicities[curveIdx]; const newSelectedMulti = Object.assign({}, selectedMulti, { smExtext: payloadData }); - multiplicities[curveIdx] = newSelectedMulti; - return Object.assign({}, state, { multiplicities, selectedIdx: curveIdx }); + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; + return Object.assign({}, state, { multiplicities: newMultiplicities, selectedIdx: curveIdx }); }; const clearAll = (state, action) => { @@ -114,8 +118,9 @@ const clearAll = (state, action) => { const { multiplicities } = state; const newSelectedMulti = Object.assign({}, defaultEmptyMultiplicity, { edited: true }); - multiplicities[curveIdx] = newSelectedMulti; - return Object.assign({}, state, { multiplicities }); + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; + return Object.assign({}, state, { multiplicities: newMultiplicities }); }; const multiplicityReducer = (state = initialState, action) => { diff --git a/src/sagas/saga_manager.js b/src/sagas/saga_manager.js index 74df3183..9ac6e748 100644 --- a/src/sagas/saga_manager.js +++ b/src/sagas/saga_manager.js @@ -42,9 +42,10 @@ function* resetInitNmr(action) { const { integration, simulation } = action.payload; const { integrations } = integationSt; - integrations[curveIdx] = integration; + const newArrIntegration = [...integrations]; + newArrIntegration[curveIdx] = integration; - const payload = Object.assign({}, integationSt, { integrations, selectedIdx: curveIdx }); // eslint-disable-line + const payload = Object.assign({}, integationSt, { integrations: newArrIntegration, selectedIdx: curveIdx }); // eslint-disable-line if (integration) { yield put({ @@ -68,9 +69,10 @@ function* resetInitCommonWithIntergation(action) { const { integration } = action.payload; const { integrations } = integationSt; - integrations[curveIdx] = integration; + const newArrIntegration = [...integrations]; + newArrIntegration[curveIdx] = integration; - const payload = Object.assign({}, integationSt, { integrations, selectedIdx: curveIdx }); // eslint-disable-line + const payload = Object.assign({}, integationSt, { integrations: newArrIntegration, selectedIdx: curveIdx }); // eslint-disable-line if (integration) { yield put({ diff --git a/src/sagas/saga_multi_entities.js b/src/sagas/saga_multi_entities.js index 47e80e67..3b7dffea 100644 --- a/src/sagas/saga_multi_entities.js +++ b/src/sagas/saga_multi_entities.js @@ -62,17 +62,8 @@ function* setCyclicVoltametry(action) { // eslint-disable-line } } -// function* setInitData(action) { -// const layoutSt = yield select(getLayoutSt); -// console.log(layoutSt); -// const curveSt = yield select(getCurveSt); -// const { listCurves } = curveSt; -// console.log(listCurves); -// } - const multiEntitiesSagas = [ takeEvery(CURVE.SET_ALL_CURVES, setCyclicVoltametry), - // takeEvery(CURVE.SET_ALL_CURVES, setInitData), ]; export default multiEntitiesSagas; diff --git a/src/sagas/saga_multiplicity.js b/src/sagas/saga_multiplicity.js index 37161552..f863c6b6 100644 --- a/src/sagas/saga_multiplicity.js +++ b/src/sagas/saga_multiplicity.js @@ -48,12 +48,13 @@ function* selectMpy(action) { selectedMulti, { stack: newStack, smExtext: newXExtemt }, ); - multiplicities[curveIdx] = newSelectedMulti; + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; const payload = Object.assign( // eslint-disable-line {}, mpySt, - { multiplicities, selectedIdx: curveIdx }, + { multiplicities: newMultiplicities, selectedIdx: curveIdx }, ); yield put({ @@ -106,9 +107,10 @@ function* addUiPeakToStack(action) { if (isDuplicate) return; const newSelectedMulti = Object.assign({}, selectedMulti,{ stack: newStack }); // eslint-disable-line - multiplicities[curveIdx] = newSelectedMulti; + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; - const payload = Object.assign({}, mpySt, { multiplicities }); // eslint-disable-line + const payload = Object.assign({}, mpySt, { multiplicities: newSelectedMulti }); // eslint-disable-line yield put({ type: MULTIPLICITY.PEAK_ADD_BY_UI_RDC, @@ -151,8 +153,9 @@ const rmPeakFromStack = (action, metaSt, mpySt, curveIdx = 0) => { const newSmExtext = noSmExtext ? newStack[0].xExtent : xExtent; const newSelectedMulti = Object.assign({}, selectedMulti, { stack: newStack, smExtext: newSmExtext }); // eslint-disable-line - multiplicities[curveIdx] = newSelectedMulti; - return Object.assign({}, mpySt, { multiplicities }); // eslint-disable-line + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; + return Object.assign({}, mpySt, { multiplicities: newMultiplicities }); // eslint-disable-line }; function* rmPanelPeakFromStack(action) { @@ -199,8 +202,9 @@ function* resetInitNmr(action) { const { curveIdx } = curveSt; const { multiplicities } = mpySt; - multiplicities[curveIdx] = multiplicity; - const payload = Object.assign({}, mpySt, { multiplicities, selectedIdx: curveIdx }); // eslint-disable-line + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = multiplicity; + const payload = Object.assign({}, mpySt, { multiplicities: newMultiplicities, selectedIdx: curveIdx }); // eslint-disable-line if (multiplicity) { yield put({ @@ -269,9 +273,10 @@ function* resetOne(action) { }); const newSelectedMulti = Object.assign({}, selectedMulti, { stack: newStack }); // eslint-disable-line - multiplicities[curveIdx] = newSelectedMulti; + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; - const payload = Object.assign({}, mpySt, { multiplicities }); // eslint-disable-line + const payload = Object.assign({}, mpySt, { multiplicities: newMultiplicities }); // eslint-disable-line yield put({ type: MULTIPLICITY.RESET_ONE_RDC, payload, @@ -296,9 +301,10 @@ function* selectMpyType(action) { }); const newSelectedMulti = Object.assign({}, selectedMulti, { stack: newStack }); // eslint-disable-line - multiplicities[curveIdx] = newSelectedMulti; + const newMultiplicities = [...multiplicities]; + newMultiplicities[curveIdx] = newSelectedMulti; - const payload = Object.assign({}, mpySt, { multiplicities }); // eslint-disable-line + const payload = Object.assign({}, mpySt, { multiplicities: newMultiplicities }); // eslint-disable-line yield put({ type: MULTIPLICITY.TYPE_SELECT_RDC, diff --git a/yarn.lock b/yarn.lock index b8525172..28bb176f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9757,10 +9757,10 @@ redux-saga@^1.1.3: dependencies: "@redux-saga/core" "^1.2.3" -redux-undo@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/redux-undo/-/redux-undo-1.0.1.tgz#8d989d6c326e6718f4471042e90a5b8b6f3317eb" - integrity sha512-0yFPT+FUgwxCEiS0Mg5T1S4tkgjR8h6sJRY9CW4EMsbJOf1SxO289TbJmlzhRouCHacdDF+powPjrjLHoJYxWQ== +redux-undo@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/redux-undo/-/redux-undo-1.1.0.tgz#ae28e517797b1aa5521d55da561f7214d310f8a5" + integrity sha512-zzLFh2qeF0MTIlzDhDLm9NtkfBqCllQJ3OCuIl5RKlG/ayHw6GUdIFdMhzMS9NnrnWdBX5u//ExMOHpfudGGOg== redux@^4.0.0, redux@^4.0.4, redux@^4.1.1: version "4.2.1"