Skip to content

Commit d40c78b

Browse files
author
Lan Le
committed
feat: WIP clear all default peaks
1 parent 0c1d652 commit d40c78b

File tree

5 files changed

+64
-11
lines changed

5 files changed

+64
-11
lines changed

src/__tests__/units/components/cmd_bar/03_peak.test.js

+42-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,51 @@ const store = mockStore({
1111
ui:{ sweepType: LIST_UI_SWEEP_TYPE.ZOOMIN },
1212
layout: LIST_LAYOUT.MS,
1313
curve: { curveIdx: 0 },
14+
editPeak: {
15+
present: {
16+
selectedIdx: 0,
17+
peaks: [
18+
{
19+
prevOffset: 0,
20+
pos: [],
21+
neg: [],
22+
},
23+
],
24+
}
25+
},
26+
threshold: {
27+
isEdit: true,
28+
value: false,
29+
upper: false,
30+
lower: false,
31+
},
32+
shift: { shifts: [] },
33+
cyclicvolta: {}
1434
});
1535
const nmrStore = mockStore({
1636
ui:{ sweepType: LIST_UI_SWEEP_TYPE.ZOOMIN },
1737
layout: LIST_LAYOUT.H1,
1838
curve: { curveIdx: 0 },
39+
editPeak: {
40+
present: {
41+
selectedIdx: 0,
42+
peaks: [
43+
{
44+
prevOffset: 0,
45+
pos: [],
46+
neg: [],
47+
},
48+
],
49+
}
50+
},
51+
threshold: {
52+
isEdit: true,
53+
value: false,
54+
upper: false,
55+
lower: false,
56+
},
57+
shift: { shifts: [] },
58+
cyclicvolta: {}
1959
});
2060

2161
const dispatchMock = () => Promise.resolve({});
@@ -33,7 +73,7 @@ describe('<Peak />', () => {
3373
it('render when has Set reference button', async () => {
3474
const renderer =
3575
<AppWrapper store={nmrStore}>
36-
<Peak />
76+
<Peak feature={{}} />
3777
</AppWrapper>
3878
;
3979
const { queryByTestId } = render(renderer);
@@ -45,7 +85,7 @@ describe('<Peak />', () => {
4585
it('render when does not hav Set reference button', async () => {
4686
const renderer =
4787
<AppWrapper store={store}>
48-
<Peak />
88+
<Peak feature={{}} />
4989
</AppWrapper>
5090
;
5191
const { queryByTestId } = render(renderer);

src/__tests__/units/reducers/reducer_edit_peak.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ describe('Test redux reducer for edit peak', () => {
7575

7676
it('Clear all peaks', () => {
7777
action.type = EDITPEAK.CLEAR_ALL
78-
action.payload = { curveIdx: 0 }
78+
action.payload = { curveIdx: 0, dataPeaks: [{x: 5, y: 6}] }
7979
peaksState = { peaks: [{pos: [{x: 1, y: 2}, {x: 3, y: 4}]}], selectedIdx: 0 }
80-
const expectedValue = {peaks: [{neg: [], pos: [], prevOffset: 0}], selectedIdx: 0}
80+
const expectedValue = {peaks: [{neg: [{x: 1, y: 2}, {x: 3, y: 4}, {x: 5, y: 6}], pos: []}], selectedIdx: 0}
8181
const newState = editPeakReducer(peaksState, action)
8282
expect(newState).toEqual(expectedValue)
8383
})

src/components/cmd_bar/03_peak.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { MuButton, commonStyle, focusStyle } from './common';
1717
import { LIST_UI_SWEEP_TYPE } from '../../constants/list_ui';
1818
import TriBtn from './tri_btn';
1919
import { clearAllPeaks } from '../../actions/edit_peak';
20+
import { extractPeaksEdit } from '../../helpers/extractPeaksEdit';
2021

2122
const styles = () => (
2223
Object.assign(
@@ -32,13 +33,15 @@ const Peak = ({
3233
isFocusSetRefSt, disableSetRefSt,
3334
isHandleMaxAndMinPeaksSt,
3435
cyclicVotaSt, curveSt,
35-
clearAllPeaksAct,
36+
clearAllPeaksAct, feature,
37+
editPeakSt, thresSt, shiftSt, layoutSt,
3638
}) => {
3739
let onSweepPeakAdd = () => setUiSweepTypeAct(LIST_UI_SWEEP_TYPE.PEAK_ADD);
3840
let onSweepPeakDELETE = () => setUiSweepTypeAct(LIST_UI_SWEEP_TYPE.PEAK_DELETE);
3941
let onSweepAnchorShift = () => setUiSweepTypeAct(LIST_UI_SWEEP_TYPE.ANCHOR_SHIFT);
4042
const { curveIdx } = curveSt;
41-
const onClearAll = () => clearAllPeaksAct({ curveIdx });
43+
const dataPeaks = extractPeaksEdit(feature, editPeakSt, thresSt, shiftSt, layoutSt);
44+
const onClearAll = () => clearAllPeaksAct({ curveIdx, dataPeaks });
4245
if (isHandleMaxAndMinPeaksSt) {
4346
const { spectraList } = cyclicVotaSt;
4447
const spectra = spectraList[curveIdx];
@@ -120,7 +123,7 @@ const Peak = ({
120123
);
121124
};
122125

123-
const mapStateToProps = (state, _) => ( // eslint-disable-line
126+
const mapStateToProps = (state, props) => ( // eslint-disable-line
124127
{
125128
isFocusAddPeakSt: state.ui.sweepType === LIST_UI_SWEEP_TYPE.PEAK_ADD || state.ui.sweepType === LIST_UI_SWEEP_TYPE.CYCLIC_VOLTA_ADD_MAX_PEAK || state.ui.sweepType === LIST_UI_SWEEP_TYPE.CYCLIC_VOLTA_ADD_MIN_PEAK,
126129
disableAddPeakSt: Cfg.btnCmdAddPeak(state.layout),
@@ -131,6 +134,10 @@ const mapStateToProps = (state, _) => ( // eslint-disable-line
131134
isHandleMaxAndMinPeaksSt: !Cfg.hidePanelCyclicVolta(state.layout),
132135
cyclicVotaSt: state.cyclicvolta,
133136
curveSt: state.curve,
137+
editPeakSt: state.editPeak.present,
138+
thresSt: state.threshold,
139+
layoutSt: state.layout,
140+
shiftSt: state.shift,
134141
}
135142
);
136143

@@ -154,6 +161,11 @@ Peak.propTypes = {
154161
cyclicVotaSt: PropTypes.object.isRequired,
155162
curveSt: PropTypes.object.isRequired,
156163
clearAllPeaksAct: PropTypes.func.isRequired,
164+
feature: PropTypes.object.isRequired,
165+
editPeakSt: PropTypes.object.isRequired,
166+
thresSt: PropTypes.object.isRequired,
167+
layoutSt: PropTypes.string.isRequired,
168+
shiftSt: PropTypes.object.isRequired,
157169
};
158170

159171
export default compose(

src/components/cmd_bar/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const CmdBar = ({
3838
<div className={classes.card}>
3939
<Viewer editorOnly={editorOnly} />
4040
<Zoom />
41-
<Peak jcampIdx={jcampIdx} />
41+
<Peak jcampIdx={jcampIdx} feature={feature} />
4242
<Pecker jcampIdx={jcampIdx} />
4343
<Integration />
4444
<Multiplicity />

src/reducers/reducer_edit_peak.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,21 @@ const processShift = (state, action) => {
142142
};
143143

144144
const clearAllPeaks = (state, action) => {
145-
const { curveIdx } = action.payload;
145+
const { curveIdx, dataPeaks } = action.payload;
146146
const { peaks } = state;
147147
const selectedEditPeaks = peaks[curveIdx];
148148

149149
const { pos } = selectedEditPeaks;
150150

151-
const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, { pos: [], neg: [...pos] });
151+
const newSelectedEditPeaks = Object.assign({}, selectedEditPeaks, {
152+
pos: [], neg: [...pos, ...dataPeaks],
153+
});
152154
const newPeaks = [...peaks];
153155
newPeaks[curveIdx] = newSelectedEditPeaks;
154156
return Object.assign({}, state, { peaks: newPeaks });
155157
};
156158

157159
const editPeakReducer = (state = initialState, action) => {
158-
console.log(action);
159160
switch (action.type) {
160161
case EDITPEAK.ADD_POSITIVE:
161162
return addToPos(state, action);

0 commit comments

Comments
 (0)