Skip to content

Commit

Permalink
Reset measure state on reset controls action. Fixes#1464
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnafu committed Feb 16, 2017
1 parent 5399d00 commit b09ac28
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
1 change: 0 additions & 1 deletion web/client/actions/measurement.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function changeMeasurement(measurement) {
function changeMeasurementState(measureState) {
return {
type: CHANGE_MEASUREMENT_STATE,
pointMeasureEnabled: measureState.pointMeasureEnabled,
lineMeasureEnabled: measureState.lineMeasureEnabled,
areaMeasureEnabled: measureState.areaMeasureEnabled,
bearingMeasureEnabled: measureState.bearingMeasureEnabled,
Expand Down
20 changes: 19 additions & 1 deletion web/client/reducers/__tests__/controls-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const expect = require('expect');

const controls = require('../controls');
const {TOGGLE_CONTROL, SET_CONTROL_PROPERTY} = require('../../actions/controls');
const {TOGGLE_CONTROL, SET_CONTROL_PROPERTY, RESET_CONTROLS} = require('../../actions/controls');

describe('Test the constrols reducer', () => {
it('toggles a control the first time', () => {
Expand Down Expand Up @@ -57,4 +57,22 @@ describe('Test the constrols reducer', () => {
expect(state.mycontrol).toExist();
expect(state.mycontrol.prop).toBe('val');
});


it('reset the controls', () => {
const state = controls(
{
c1: { enabled: true},
c2: { enabled: false},
c3: { idonthaveenabledfield: "whatever"}
}, {
type: RESET_CONTROLS
});
expect(state.c1).toExist();
expect(state.c2).toExist();
expect(state.c3).toExist();
expect(state.c1.enabled).toBe(false);
expect(state.c2.enabled).toBe(false);
expect(state.c3.enabled).toNotExist();
});
});
11 changes: 8 additions & 3 deletions web/client/reducers/measurement.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const {
CHANGE_MEASUREMENT_STATE
} = require('../actions/measurement');

const {TOGGLE_CONTROL} = require('../actions/controls');
const {TOGGLE_CONTROL, RESET_CONTROLS} = require('../actions/controls');

const assign = require('object-assign');

function measurement(state = {
Expand All @@ -22,15 +23,13 @@ function measurement(state = {
switch (action.type) {
case CHANGE_MEASUREMENT_TOOL:
return assign({}, state, {
pointMeasureEnabled: ((action.geomType !== state.geomType) && (action.geomType === 'Point')),
lineMeasureEnabled: ((action.geomType !== state.geomType) && (action.geomType === 'LineString')),
areaMeasureEnabled: ((action.geomType !== state.geomType) && (action.geomType === 'Polygon')),
bearingMeasureEnabled: ((action.geomType !== state.geomType) && (action.geomType === 'Bearing')),
geomType: (action.geomType === state.geomType) ? null : action.geomType
});
case CHANGE_MEASUREMENT_STATE:
return assign({}, state, {
pointMeasureEnabled: action.pointMeasureEnabled,
lineMeasureEnabled: action.lineMeasureEnabled,
areaMeasureEnabled: action.areaMeasureEnabled,
bearingMeasureEnabled: action.bearingMeasureEnabled,
Expand All @@ -53,6 +52,12 @@ function measurement(state = {
};
}
}
case RESET_CONTROLS:
return {
lineMeasureEnabled: false,
areaMeasureEnabled: false,
bearingMeasureEnabled: false
};
default:
return state;
}
Expand Down

0 comments on commit b09ac28

Please sign in to comment.