Skip to content

Commit

Permalink
#42 Making changes to the toggle logic of urbanisme tool (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fedorenko authored Feb 28, 2022
1 parent 8487f4a commit a6df220
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 43 deletions.
2 changes: 1 addition & 1 deletion js/extension/actions/urbanisme.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const loading = (value, name) => ({
/**
* Sets the activeTool for urbanisme toolbar
* @memberof actions.toggleUrbanismeTool
* @param {string} tool name to active
* @param {string|null} tool name to active
* @return {object} with type `TOGGLE_TOOL`
*/
export const toggleUrbanismeTool = tool => {
Expand Down
34 changes: 24 additions & 10 deletions js/extension/epics/__tests__/urbanisme-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
toggleLandPlanningEpic,
cleanUpUrbanismeEpic,
clickOnMapEventEpic,
closeOnMeasureEnabledEpic,
deactivateOnMeasureEnabledEpic,
getFeatureInfoEpic,
onClosePanelEpic,
onToogleToolEpic,
Expand Down Expand Up @@ -105,17 +105,18 @@ describe('Urbanisme EPICS', () => {
};
testEpic(
toggleLandPlanningEpic,
4,
5,
toggleControl('urbanisme', null),
actions => {
expect(actions.length).toBe(4);
expect(actions.length).toBe(5);
actions.map(action=> {
switch (action.type) {
case UPDATE_ADDITIONAL_LAYER:
expect(action.options).toBeTruthy();
expect([URBANISME_RASTER_LAYER_ID, URBANISME_VECTOR_LAYER_ID].includes(action.options.id)).toBeTruthy();
break;
case TOGGLE_MAPINFO_STATE:
case PURGE_MAPINFO_RESULTS:
break;
case TOGGLE_CONTROL:
expect(action.control).toBe('measure');
Expand Down Expand Up @@ -250,14 +251,20 @@ describe('Urbanisme EPICS', () => {
it('closeOnMeasureEnabledEpic close when urbanisme plugin when measurement is opened', (done) => {
const state = { controls: { measure: { enabled: true}, urbanisme: { enabled: true}}};
testEpic(
closeOnMeasureEnabledEpic,
1,
deactivateOnMeasureEnabledEpic,
3,
setControlProperty("measure", "enabled", true),
actions => {
expect(actions.length).toBe(1);
expect(actions.length).toBe(3);
actions.map(action=>{
switch (action.type) {
case TOGGLE_CONTROL:
case TOGGLE_TOOL:
expect(action.activeTool).toBe(null);
break;
case TOGGLE_VIEWER_PANEL:
expect(action.enabled).toBe(false);
break;
case PURGE_MAPINFO_RESULTS:
break;
default:
expect(true).toBe(false);
Expand Down Expand Up @@ -428,12 +435,16 @@ describe('Urbanisme EPICS', () => {
});

it('onToogleToolEpic clean up activities of previous tool', (done) => {
const state = {
controls: { measure: { enabled: true}, urbanisme: { enabled: true}},
urbanisme: { activeTool: "ADS"}
};
testEpic(
onToogleToolEpic,
3,
4,
toggleUrbanismeTool('NRU'),
actions => {
expect(actions.length).toBe(3);
expect(actions.length).toBe(4);
actions.map(action=>{
switch (action.type) {
case URBANISME_RESET_FEATURE_HIGHLIGHT:
Expand All @@ -444,12 +455,15 @@ describe('Urbanisme EPICS', () => {
case TOGGLE_VIEWER_PANEL:
expect(action.enabled).toBe(false);
break;
case TOGGLE_CONTROL:
expect(action.control).toBe("measure");
break;
default:
expect(true).toBe(false);
}
});
done();
}, {});
}, state);
});

it('updateAdditionalLayerEpic on feature highlight test', (done) => {
Expand Down
92 changes: 60 additions & 32 deletions js/extension/epics/urbanisme.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const clickOnMapEventEpic = (action$, {getState}) =>
const mapInfoEnabled = !mapInfoDisabledSelector(state);
if (mapInfoEnabled) {
return urbanismeEnabled
? Rx.Observable.of(toggleControl(CONTROL_NAME))
? Rx.Observable.of(toggleUrbanismeTool(null))
: Rx.Observable.empty();
}
return !isEmpty(activeTool) && !isPrinting
Expand Down Expand Up @@ -253,12 +253,12 @@ export const cleanUpUrbanismeEpic = (action$, {getState}) =>
});

/**
* Ensures that when the urbanisme plugin is closed when measurement tool is activated
* Ensures that the urbanisme plugin is deactivated when measurement tool is activated
* @memberof epics.urbanisme
* @param {observable} action$ manages `SET_CONTROL_PROPERTY`
* @return {observable}
*/
export const closeOnMeasureEnabledEpic = (action$, {getState}) =>
export const deactivateOnMeasureEnabledEpic = (action$, {getState}) =>
action$
.ofType(SET_CONTROL_PROPERTY)
.filter(
Expand All @@ -267,42 +267,54 @@ export const closeOnMeasureEnabledEpic = (action$, {getState}) =>
.switchMap(() => {
const urbanismeEnabled = urbanimseControlSelector(getState());
return urbanismeEnabled
? Rx.Observable.of(toggleControl(CONTROL_NAME))
? Rx.Observable.from([
toggleGFIPanel(false),
toggleUrbanismeTool(null),
purgeMapInfoResults()
])
: Rx.Observable.empty();
});

/**
* Ensures that the urbanisme plugin is closed when Identify tool is activated
* Ensures that the urbanisme plugin active tool is getting deactivated when Identify tool is activated
* @memberof epics.urbanisme
* @param {observable} action$ manages `SET_CONTROL_PROPERTY`
* @param {observable} action$ manages `TOGGLE_MAPINFO_STATE`
* @return {observable}
*/
export const closeOnIdentifyEnabledEpic = (action$, {getState}) =>
export const deactivateOnIdentifyEnabledEpic = (action$, {getState}) =>
action$
.ofType(TOGGLE_MAPINFO_STATE)
.filter(() => !mapInfoDisabledSelector(getState()))
.switchMap(() => {
const urbanismeEnabled = urbanimseControlSelector(getState());
return urbanismeEnabled
? Rx.Observable.of(toggleControl(CONTROL_NAME))
? Rx.Observable.from([
toggleGFIPanel(false),
toggleUrbanismeTool(null),
purgeMapInfoResults()
])
: Rx.Observable.empty();
});

/**
* Ensures that the urbanisme plugin is closed when Map info trigger
* is changed to "hover"
* @memberof epics.urbanisme
* @param {observable} action$ manages `SET_CONTROL_PROPERTY`
* @param {observable} action$ manages `SET_MAP_TRIGGER`
* @return {observable}
*/
export const closeOnMapHoverEnabledEpic = (action$, {getState}) =>
export const deactivateOnMapHoverEnabledEpic = (action$, {getState}) =>
action$
.ofType(SET_MAP_TRIGGER)
.filter(() => mapTriggerSelector(getState()) === 'hover')
.switchMap(() => {
const urbanismeEnabled = urbanimseControlSelector(getState());
return urbanismeEnabled
? Rx.Observable.of(toggleControl(CONTROL_NAME))
? Rx.Observable.from([
toggleGFIPanel(false),
toggleUrbanismeTool(null),
purgeMapInfoResults()
])
: Rx.Observable.empty();
});

Expand All @@ -326,15 +338,29 @@ export const onClosePanelEpic = action$ =>
* @param {observable} action$ manages `TOGGLE_TOOL`
* @return {observable}
*/
export const onToogleToolEpic = action$ =>
export const onToogleToolEpic = (action$, {getState}) =>
action$
.ofType(TOGGLE_TOOL)
.switchMap(() =>
Rx.Observable.from([
.filter(() => {
const state = getState();
return activeToolSelector(state);
})
.switchMap(() => {
const state = getState();
const mapInfoEnabled = !mapInfoDisabledSelector(state);
const infoMarkerIsShown = showMarkerSelector(state);
const isMeasureEnabled = measureSelector(state);
const mapHoverTrigger = mapTriggerSelector(state);
return Rx.Observable.from([
resetFeatureHighlight(),
setAttributes(null),
toggleGFIPanel(false)
])
toggleGFIPanel(false),
...(mapInfoEnabled ? [toggleMapInfoState(), purgeMapInfoResults()] : []),
...(isMeasureEnabled ? [toggleControl("measure")] : []),
...(mapHoverTrigger === 'hover' ? [setMapTrigger("click")] : []),
...(infoMarkerIsShown ? [hideMapinfoMarker()] : [])
]);
}
);
/**
* Ensures that when the feature info is loaded it has parcelle data to proceed further to call NRU/ADS data
Expand Down Expand Up @@ -553,20 +579,22 @@ export const updateAdditionalLayerEpic = (action$, {
visibility: true
})
);
} else if (enabled && type === URBANISME_RESET_FEATURE_HIGHLIGHT) {
return Rx.Observable.of(
updateAdditionalLayer(
URBANISME_VECTOR_LAYER_ID,
URBANISME_OWNER,
'overlay',
{
id: URBANISME_VECTOR_LAYER_ID,
features: [],
type: "vector",
name: "selectedPlot",
visibility: true
})
);
}
return Rx.Observable.of(
updateAdditionalLayer(
URBANISME_VECTOR_LAYER_ID,
URBANISME_OWNER,
'overlay',
{
id: URBANISME_VECTOR_LAYER_ID,
features: [],
type: "vector",
name: "selectedPlot",
visibility: true
})
);
return Rx.Observable.empty();
});

export default {
Expand All @@ -580,7 +608,7 @@ export default {
getUrbanismeFeatureInfoOnFeatureInfoClick,
highlightFeatureEpic,
updateAdditionalLayerEpic,
closeOnMeasureEnabledEpic,
closeOnMapHoverEnabledEpic,
closeOnIdentifyEnabledEpic
deactivateOnMeasureEnabledEpic,
deactivateOnMapHoverEnabledEpic,
deactivateOnIdentifyEnabledEpic
};

0 comments on commit a6df220

Please sign in to comment.