Skip to content

Commit

Permalink
fix: fix undo multiplicities
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan Le committed Sep 5, 2023
1 parent a8fcc46 commit 708a513
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
25 changes: 15 additions & 10 deletions src/reducers/reducer_multiplicity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand All @@ -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) => {
Expand Down
10 changes: 6 additions & 4 deletions src/sagas/saga_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down
9 changes: 0 additions & 9 deletions src/sagas/saga_multi_entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
30 changes: 18 additions & 12 deletions src/sagas/saga_multiplicity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 708a513

Please sign in to comment.