Skip to content

Commit

Permalink
fix: fix cannot undo redo peaks, integrations and multiplicities (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
baolanlequang authored Sep 5, 2023
1 parent 551d2f8 commit 5ca04c8
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 132 deletions.
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;
30 changes: 18 additions & 12 deletions dist/sagas/saga_multiplicity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)({
Expand Down Expand Up @@ -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)({
Expand Down Expand Up @@ -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
};

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)({
Expand Down
2 changes: 1 addition & 1 deletion dist/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 5ca04c8

Please sign in to comment.