Skip to content

Commit 178c439

Browse files
authored
fix: prevent warnings during line drawing (#11642)
1 parent 0bdbec3 commit 178c439

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

web/client/epics/__tests__/longitudinalProfile-test.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
import expect from 'expect';
1010

1111
import {
12-
LPonDockClosedEpic
12+
LPonDockClosedEpic,
13+
LPclickToProfileEpic
1314
} from '../longitudinalProfile';
1415

1516
import { testEpic } from './epicTestUtils';
1617
import { setControlProperty } from '../../actions/controls';
1718
import { CONTROL_DOCK_NAME, CONTROL_NAME, LONGITUDINAL_OWNER, LONGITUDINAL_VECTOR_LAYER_ID, LONGITUDINAL_VECTOR_LAYER_ID_POINT } from '../../plugins/longitudinalProfile/constants';
1819
import { CHANGE_GEOMETRY } from '../../actions/longitudinalProfile';
1920
import { REMOVE_ADDITIONAL_LAYER } from '../../actions/additionallayers';
20-
import { UNREGISTER_EVENT_LISTENER } from '../../actions/map';
21+
import { UNREGISTER_EVENT_LISTENER, CLICK_ON_MAP } from '../../actions/map';
2122
import { CHANGE_DRAWING_STATUS } from '../../actions/draw';
23+
import { SHOW_NOTIFICATION } from '../../actions/notifications';
2224

2325
describe('longitudinalProfile Epics', () => {
2426
it('test default LPonDockClosedEpic epic', (done) => {
@@ -88,4 +90,50 @@ describe('longitudinalProfile Epics', () => {
8890
}
8991
});
9092
});
93+
94+
it('LPclickToProfileEpic should not process clicks when in draw mode', (done) => {
95+
const NUM_ACTIONS = 0;
96+
const point = { latlng: { lat: 44.0, lng: 5.0 } };
97+
const startActions = [{ type: CLICK_ON_MAP, point }];
98+
99+
testEpic(LPclickToProfileEpic, NUM_ACTIONS, startActions, actions => {
100+
expect(actions.length).toBe(0);
101+
done();
102+
}, {
103+
longitudinalProfile: {
104+
mode: 'draw'
105+
},
106+
map: {
107+
present: {
108+
eventListeners: {
109+
click: [CONTROL_NAME]
110+
}
111+
}
112+
}
113+
});
114+
});
115+
116+
it('LPclickToProfileEpic should process clicks when in select mode', (done) => {
117+
const NUM_ACTIONS = 1;
118+
const point = { latlng: { lat: 44.0, lng: 5.0 } };
119+
const startActions = [{ type: CLICK_ON_MAP, point }];
120+
121+
testEpic(LPclickToProfileEpic, NUM_ACTIONS, startActions, actions => {
122+
expect(actions.length).toBe(1);
123+
expect(actions[0].type).toBe(SHOW_NOTIFICATION);
124+
expect(actions[0].level).toBe('warning');
125+
done();
126+
}, {
127+
longitudinalProfile: {
128+
mode: 'select'
129+
},
130+
map: {
131+
present: {
132+
eventListeners: {
133+
click: [CONTROL_NAME]
134+
}
135+
}
136+
}
137+
});
138+
});
91139
});

web/client/epics/longitudinalProfile.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,13 @@ export const LPdeactivateIdentifyEnabledEpic = (action$, store) =>
416416
export const LPclickToProfileEpic = (action$, {getState}) =>
417417
action$
418418
.ofType(CLICK_ON_MAP)
419-
.filter(() => isListeningClickSelector(getState()))
419+
.filter(() => {
420+
const state = getState();
421+
const isListeningClick = isListeningClickSelector(state);
422+
const mode = dataSourceModeSelector(state);
423+
// Only process clicks when in select mode to avoid triggering during drawing
424+
return isListeningClick && mode === 'select';
425+
})
420426
.switchMap(({point}) => {
421427
const state = getState();
422428
const map = mapSelector(state);

0 commit comments

Comments
 (0)