From f0b227b12946fb4fe02f801674e608355d074907 Mon Sep 17 00:00:00 2001 From: Lorenzo Pini Date: Wed, 15 Feb 2017 15:13:38 +0100 Subject: [PATCH] Reset measure state on reset controls action. Fixes#1464 --- web/client/actions/measurement.js | 1 - .../reducers/__tests__/controls-test.js | 20 ++++++++++++++++++- web/client/reducers/measurement.js | 11 +++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/web/client/actions/measurement.js b/web/client/actions/measurement.js index 7fec02f107..a460e30404 100644 --- a/web/client/actions/measurement.js +++ b/web/client/actions/measurement.js @@ -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, diff --git a/web/client/reducers/__tests__/controls-test.js b/web/client/reducers/__tests__/controls-test.js index 0e662a8596..55a049f57a 100644 --- a/web/client/reducers/__tests__/controls-test.js +++ b/web/client/reducers/__tests__/controls-test.js @@ -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', () => { @@ -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(); + }); }); diff --git a/web/client/reducers/measurement.js b/web/client/reducers/measurement.js index 47ab6a36c2..e9db49445a 100644 --- a/web/client/reducers/measurement.js +++ b/web/client/reducers/measurement.js @@ -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 = { @@ -22,7 +23,6 @@ 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')), @@ -30,7 +30,6 @@ function measurement(state = { }); case CHANGE_MEASUREMENT_STATE: return assign({}, state, { - pointMeasureEnabled: action.pointMeasureEnabled, lineMeasureEnabled: action.lineMeasureEnabled, areaMeasureEnabled: action.areaMeasureEnabled, bearingMeasureEnabled: action.bearingMeasureEnabled, @@ -53,6 +52,12 @@ function measurement(state = { }; } } + case RESET_CONTROLS: + return { + lineMeasureEnabled: false, + areaMeasureEnabled: false, + bearingMeasureEnabled: false + }; default: return state; }